0

I need to write a power, temperature monitor system for linux system. It needs display some power statistics for for some or all builtin-devices as what powerTop does.I have searched quite a bit and I'm still clueless. Could some one give me a guidance.

Kevin Q
  • 679
  • 1
  • 13
  • 19
  • Please give more specifics about the platform. Also see the [power documentation](https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/power/00-INDEX). If you have *hardware*, you can measure supply currents and voltages. If you do not have this hardware, you must guess. The same for temperature; so only if you give a clue as to hardware, can someone answer. – artless noise Apr 29 '13 at 00:09
  • It should be generic to any Linux machine. – Kevin Q Apr 29 '13 at 04:29
  • Then it is impossible. You need hardware support. Some chips present the same interface to the CPU but have different power profiles. There is no way to generically estimate either. *lmsensor* and */sys/power* will be present if there is hardware support. – artless noise Apr 29 '13 at 13:36

2 Answers2

1

For measuring the temperature you might use the lm_sensors tool. For power consumption take a look at the acpi client. Both should be available for most distributions.

You can use these tools to determine the required values and display them in your software.

Example output of lm_sensors:

pc87366-isa-6620
Adapter: ISA adapter
VCORE:       +2.01 V  (min =  +1.90 V, max =  +2.10 V)
VCC:         +4.99 V  (min =  +0.00 V, max =  +6.03 V)
VPWR:       +11.88 V  (min =  +5.93 V, max = +28.02 V)
+12V:       +11.93 V  (min = +11.02 V, max = +13.01 V)
-12V:       -12.19 V  (min = -13.10 V, max = -11.06 V)
GND:         +0.00 V  (min =  +0.00 V, max =  +0.00 V)
Vsb:         +3.28 V  (min =  +3.00 V, max =  +3.59 V)
Vdd:         +3.28 V  (min =  +3.00 V, max =  +3.59 V)
Vbat:        +3.01 V  (min =  +2.40 V, max =  +3.01 V)
AVdd:        +3.26 V  (min =  +3.00 V, max =  +3.59 V)
Temp:        +55.0°C  (low  =  +0.0°C, high = +70.0°C)  
                      (crit = +85.0°C)

If you do not get certain values you might have to tweak your configuration. Look at the following locations (text has been taken from the man page):

/etc/sensors3.conf
/etc/sensors.conf
      The system-wide libsensors(3) configuration file. /etc/sensors3.conf  is  tried  first,
      and if it doesn't exist, /etc/sensors.conf is used instead.

/etc/sensors.d
      A  directory  where you can put additional libsensors configuration files.  Files found
      in this directory will be processed in alphabetical order after the default  configura‐
      tion file. Files with names that start with a dot are ignored.
Matthias Herlitzius
  • 3,365
  • 2
  • 20
  • 20
1

If you want to write something completely on your own you may have a look at ACPI, which features are provided via sysfs.

ls /sys/power

should give you a first look at the information exported.

akluth
  • 8,393
  • 5
  • 38
  • 42