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