From 5ecffc35586331c1ded4cda3d95fc5511604126a Mon Sep 17 00:00:00 2001 From: Steve Schnepp Date: Thu, 3 Sep 2015 17:13:06 +0200 Subject: [PATCH 1/2] battery_: first version --- plugins/sensors/battery-uevent_ | 58 +++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 plugins/sensors/battery-uevent_ diff --git a/plugins/sensors/battery-uevent_ b/plugins/sensors/battery-uevent_ new file mode 100755 index 00000000..f4cbd541 --- /dev/null +++ b/plugins/sensors/battery-uevent_ @@ -0,0 +1,58 @@ +#! /bin/sh +# Plugin to monitor the battery status via the uevent API + +battery_name=CMB1 +percent=yes + +if [ "$1" = "config" ] +then + echo "graph_title Battery $battery_name" + if [ "$percent" = "yes" ] + then + echo "graph_vlabel %" + else + echo "graph_vlabel mAh" + fi + + echo "charge_design.label Design charge" + echo "charge_design.draw AREA" + [ "$percent" = "yes" ] && echo "charge_design.cdef charge_design,charge_design,/,100,*" + + echo "charge_full.label Full charge" + echo "charge_full.draw AREA" + [ "$percent" = "yes" ] && echo "charge_full.cdef charge_full,charge_design,/,100,*" + echo "charge_now.label Current charge" + echo "charge_now.draw AREA" + [ "$percent" = "yes" ] && echo "charge_now.cdef charge_now,charge_design,/,100,*" + + exit 0 +fi + +# Crudely read all the vars into the current namespace +. /sys/class/power_supply/$battery_name/uevent + +echo "charge_design.value $(( $POWER_SUPPLY_CHARGE_FULL_DESIGN / 1000 )) " +echo "charge_full.value $(( $POWER_SUPPLY_CHARGE_FULL / 1000 ))" +echo "charge_now.value $(( $POWER_SUPPLY_CHARGE_NOW / 1000 ))" + +exit 0 + + +:<< DATA +cat /sys/class/power_supply/$1/uevent +POWER_SUPPLY_NAME=CMB1 +POWER_SUPPLY_STATUS=Charging +POWER_SUPPLY_PRESENT=1 +POWER_SUPPLY_TECHNOLOGY=Li-ion +POWER_SUPPLY_CYCLE_COUNT=0 +POWER_SUPPLY_VOLTAGE_MIN_DESIGN=10800000 +POWER_SUPPLY_VOLTAGE_NOW=11418000 +POWER_SUPPLY_CURRENT_NOW=2668000 +POWER_SUPPLY_CHARGE_FULL_DESIGN=5200000 +POWER_SUPPLY_CHARGE_FULL=5000000 +POWER_SUPPLY_CHARGE_NOW=100000 +POWER_SUPPLY_CAPACITY=2 +POWER_SUPPLY_CAPACITY_LEVEL=Normal +POWER_SUPPLY_MODEL_NAME=CP293570 +POWER_SUPPLY_MANUFACTURER=Fujitsu +DATA From 0ab4b3a083248e7ed205a1db9939b7622d086ddc Mon Sep 17 00:00:00 2001 From: Steve Schnepp Date: Thu, 3 Sep 2015 17:14:15 +0200 Subject: [PATCH 2/2] battery_: make a wildcard plugin --- plugins/sensors/{battery-uevent_ => battery_} | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) rename plugins/sensors/{battery-uevent_ => battery_} (82%) diff --git a/plugins/sensors/battery-uevent_ b/plugins/sensors/battery_ similarity index 82% rename from plugins/sensors/battery-uevent_ rename to plugins/sensors/battery_ index f4cbd541..01f6f9d0 100755 --- a/plugins/sensors/battery-uevent_ +++ b/plugins/sensors/battery_ @@ -1,8 +1,18 @@ #! /bin/sh # Plugin to monitor the battery status via the uevent API +# +# (c) 2015 - GPLv2 - steve.schnepp@pwkf.org +# +# It is a wildcard plugin, symlink it with the battery directory +# default is to display charge as mAh, but you can also use percentage if you +# prefer, by setting the env var "percent" to "yes". +# +# [battery_*] +# env.percent no +# -battery_name=CMB1 -percent=yes +battery_name=${0##*_} +percent=${percent:-"no"} if [ "$1" = "config" ] then