How to measure power consumed by mains device
There are special data acquisition ICs for this, like this range by Analog Devices. They consist of 2 high resolution ADCs (Analog-to-Digital Converters), one measuring the voltage and the other the current. Two ADCs are needed because the measurements must occur simultaneously to get an accurate power reading. An internal computational block may calculate (reactive) power. Programmable gain amplifiers can set sensitivity. 

They usually interface via a serial bus like I2C or SPI with a microcontroller. Some ICs used in kWh-meters give a pulse for a programmable energy unit instead, like 10 pulses per kWh.