There are several ways to measure energy consumption to any appliance. Some commercial pumps have a clock (counter) connected to the contactor so any time the contactor is closed the clock runs. This shows you how many total hours the equipment has operated.
Since one leg of a WH is always energized, you would need a 240 volts counter clock and two of them at that since the power switches between the top and bottom thermostats. Then you could add the two counters together to get total hours of operation. Then multiply hours by kW output to get kWh.
Yesterday I saw a BTU counter on an abandoned solar WH system. I suppose it measured inlet and outlet temperatures and flow rates.
Power = volts times amps. Energy is power over time. A 4500 watt WH uses 4.5 kWh if it operates for one hour. It uses 2.25 kWh if operated for 30 minutes. Also, the nameplate output is based on an input voltage of 240 (for a home). Also, power = voltage x voltage / resistance. So if voltage is above 240, you get more than 4500 watts. If voltage is less than 240, power is a little below 4500 watts.