From: Peter Wu Date: Mon, 30 Mar 2015 16:48:06 +0000 (+0200) Subject: battery: report current if known X-Git-Tag: collectd-5.5.0~43^2~1 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=af5eb0ca07aac94bf4ebf5429e9d5c2c1fb7d4e9;p=collectd.git battery: report current if known The power field is not always available (take my Clevo B7130 laptop for example). The current is reported though via "current_now". According to the ACPI spec v5.0, sect. 10.2.2.6 _BST (Battery Status), the reported field is "battery present rate" which is always positive (its direction depends on the charging state). Contents of /sys/class/power_supply/BAT0/uevent for my laptop: POWER_SUPPLY_NAME=BAT0 POWER_SUPPLY_STATUS=Discharging POWER_SUPPLY_PRESENT=1 POWER_SUPPLY_TECHNOLOGY=Li-ion POWER_SUPPLY_CYCLE_COUNT=0 POWER_SUPPLY_VOLTAGE_MIN_DESIGN=11100000 POWER_SUPPLY_VOLTAGE_NOW=11824000 POWER_SUPPLY_CURRENT_NOW=1498000 POWER_SUPPLY_CHARGE_FULL_DESIGN=5200000 POWER_SUPPLY_CHARGE_FULL=5280000 POWER_SUPPLY_CHARGE_NOW=4797000 POWER_SUPPLY_CAPACITY=90 POWER_SUPPLY_CAPACITY_LEVEL=Normal POWER_SUPPLY_MODEL_NAME=BAT POWER_SUPPLY_MANUFACTURER=NOTEBOOK POWER_SUPPLY_SERIAL_NUMBER=0001 Note for Clevo B7130 owners, the charging rate is not reported when discharging but this can be [patched][1]. [1]: https://github.com/Lekensteyn/acpi-stuff/blob/master/Clevo-B7130/BatteryFix.dsl --- diff --git a/src/battery.c b/src/battery.c index 185442c1..f106da09 100644 --- a/src/battery.c +++ b/src/battery.c @@ -513,13 +513,15 @@ static int read_sysfs_callback (char const *dir, /* {{{ */ v *= -1.0; battery_submit (plugin_instance, "power", v * SYSFS_FACTOR); } + if (sysfs_file_to_gauge (dir, power_supply, "current_now", &v) == 0) + { + if (discharging) + v *= -1.0; + battery_submit (plugin_instance, "current", v * SYSFS_FACTOR); + } if (sysfs_file_to_gauge (dir, power_supply, "voltage_now", &v) == 0) battery_submit (plugin_instance, "voltage", v * SYSFS_FACTOR); -#if 0 - if (sysfs_file_to_gauge (dir, power_supply, "voltage_min_design", &v) == 0) - battery_submit (plugin_instance, "voltage", v * SYSFS_FACTOR); -#endif return (0); } /* }}} int read_sysfs_callback */