From Electron Cloud
Revision as of 15:54, 22 June 2009 by Ecloud (Talk | contribs)

Jump to: navigation, search

This is a convention I wish somebody else had thought of and publicized widely a long time ago... there should be one memorable command to see the most relevant power and sensor info on every Linux box. My convention is to call this pow. It has to be implemented differently on different systems, although that could be automated in some kind of complicated "pow" package which noone has written, AFAIK.

For GUI purposes, gkrellm does a great job - it finds and understands the Apple SMC sensors just as well as the ACPI ones, looks slick, updates very smoothly and doesn't take much CPU. It's just that "pow" is nice to have for remote SSH sessions.

ACPI-compatible PCs

A shell alias might be good enough:

alias pow='cat /proc/acpi/battery/BAT1/info | grep last | cat - /proc/acpi/battery/BAT1/state /proc/acpi/thermal_zone/THRM/temperature'

or you could use a script:

#!/bin/sh
CHARGE_NOW=`cat /sys/class/power_supply/BAT0/charge_now`
CHARGE_FULL=`cat /sys/class/power_supply/BAT0/charge_full`
CHARGE_PERCENT=$(( $CHARGE_NOW * 100 / $CHARGE_FULL ))
CHARGE_NOW=`cat /proc/acpi/battery/BAT0/state | grep remaining | cut -c26-`
CHARGE_FULL=`cat /proc/acpi/battery/BAT0/info | grep last | cut -c26-`
cat /proc/acpi/battery/BAT0/state | grep -v remaining
echo "Charge:                    $CHARGE_NOW / $CHARGE_FULL = $CHARGE_PERCENT%"
cat /proc/acpi/thermal_zone/TZS0/temperature /proc/acpi/thermal_zone/TZS1/temperature

which produces output like this:

[acer][02:10:26 PM] pow
present:                 yes
capacity state:          ok
charging state:          charging
present rate:            2200 mA
present voltage:         11663 mV
Charge:	           1606 mAh / 3799 mAh = 42%
temperature:             45 C
temperature:             48 C

Apple Intel systems

Apple uses SMC (system management whatchamacallit) rather than ACPI. If your Linux kernel has support for that, there will be some nodes under /sys/devices/platform/applesmc.768 on a mac mini; not sure if the 768 is different on other systems, or what. Here's another crude script (which would be better at least re-written in python or something):

#!/bin/sh
for s in `ls /sys/devices/platform/applesmc.*/temp*`
do
        integer=`cat $s | cut -c1-2`
        fraction=`cat $s | cut -c3-5`
        echo "temperature:               $integer.$fraction °C"
done
for s in `ls /sys/devices/platform/applesmc.*/fan*output`
do
        partial_path=`echo $s | cut -d'_' -f1`
        name=`echo $partial_path | cut -d'/' -f6`
        current=`cat $s`
        min=`cat ${partial_path}_min`
        max=`cat ${partial_path}_max`
        echo "$name:                      $current RPM (range $min - $max)"
done
for s in `ls /dev/sd?`
do
        hddtemp $s 2>/dev/null
done

and its output looks like this:

[mini][03:46:57 PM] pow
temperature:               59.250 °C
temperature:               56.000 °C
fan1:                      1610 RPM (range 1000 - 5500)
/dev/sda: ST9500420AS:  52°C or °F