How do I measure server power consumption?
Solution 1:
I don't think it's possible to calculate the power consumption by software in a reliable manner.
Some (most?) notebook can tell you how much power you're drawing from the battery. But I don't think that this is possible for desktop computers or servers without special hardware.
If you have physical access to the server, you could just plug it in an electricity usage monitor, e.g. this one for 22 USD.
Solution 2:
AFAIK most server & desktop hardware doesn't have the necessary hardware parts to measure this (unlike laptops where this is part of the battery electronics).
If you have an UPS, then this might be part of its features, so if you have one, you might want to look at its documentation.
Otherwise, there also devices that you can put between the server and the wall plug to measure this.
Solution 3:
Thanks to the RAPL capabilities available in many intel/amd cpus (that is pretty reliable compared to a physical wattmeter) there are some projects emerging for that in the last years.
One of them is scaphandre. This is pretty recent but you can already get the machine power consumption and the consumption of each processes running on it.