Measuring power consumption in code

I would like to be able to measure the power consumption (from the 5V adapter) of the BeagleBone Black in my (Java) code.

I have tried this already, but I get an error (Error: Write failed) when executing the i2c command.

Can somebody help me with some pointers on how to achieve this?