how do energy consumption (Ah, kWh) meters work?
Ah would be measured with a coulomb counter - basically what you said, measuring current and numerically integrating this over time.
As for kWh, you could measure current and voltage, multiply them together to get power, then again, numerically integrate this over time to get kWh
An MCU is not required to perform this sort of measurement. The STC3100 is a simple I2C interfaced coulomb counter that measures the charge state of a battery. It works by integrating the measured current into/out of the battery over time and providing the result in a form that can be read by the processor.
I have used this device on a couple of products and find the results better than I would have thought bearing in mind the large variations in the load current that can be seen, in my case the load current varies over at least 4 orders of magnitude. The errors due to the sampling of the varying current seem to cancel out over time.
Mechanical wattmeter is essentially a motor with voltage and current sense windings. The velocity of motor is proportional to multiplication of voltage by current. In case if the multiplication gives negative result, the motor will rotate backwards.