X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fbattery_statefs.c;h=149512b9f48fdf85056dd047da03a85d292ee6b6;hb=936d749328d399463f2bbb5ec3d07cd3a271a7c7;hp=03729fdb0c9d4900fe5d55bc72c1c9f375e2ee9d;hpb=e14e8b7f5c5bf9d0fe5cc632c6383f304d4ac2ad;p=collectd.git diff --git a/src/battery_statefs.c b/src/battery_statefs.c index 03729fdb..149512b9 100644 --- a/src/battery_statefs.c +++ b/src/battery_statefs.c @@ -44,9 +44,9 @@ SOFTWARE. **/ -#include "collectd.h" #include "common.h" #include "plugin.h" +#include "collectd.h" #include @@ -56,9 +56,8 @@ static void battery_submit(const char *type, gauge_t value, const char *type_instance) { value_list_t vl = VALUE_LIST_INIT; - vl.values = &(value_t) { .gauge = value }; + vl.values = &(value_t){.gauge = value}; vl.values_len = 1; - sstrncpy(vl.host, hostname_g, sizeof(vl.host)); sstrncpy(vl.plugin, "battery", sizeof(vl.plugin)); /* statefs supports 1 battery at present */ sstrncpy(vl.plugin_instance, "0", sizeof(vl.plugin_instance)); @@ -73,31 +72,33 @@ int battery_read_statefs(void) { value_t v; int success = 0; - if (parse_value_file(STATEFS_ROOT "ChargePercentage", &v, DS_TYPE_GAUGE) == 0) { + if (parse_value_file(STATEFS_ROOT "ChargePercentage", &v, DS_TYPE_GAUGE) == + 0) { battery_submit("charge", v.gauge, NULL); success++; - } else if (parse_value_file(STATEFS_ROOT "Capacity", &v, DS_TYPE_GAUGE) == 0) { + } else if (parse_value_file(STATEFS_ROOT "Capacity", &v, DS_TYPE_GAUGE) == + 0) { // Use capacity as a charge estimate if ChargePercentage is not available battery_submit("charge", v.gauge, NULL); success++; } else { - WARNING("battery plugin: Neither \""STATEFS_ROOT"ChargePercentage\" " - "nor \""STATEFS_ROOT"Capacity\" could be read."); + WARNING("battery plugin: Neither \"" STATEFS_ROOT "ChargePercentage\" " + "nor \"" STATEFS_ROOT "Capacity\" could be read."); } struct { - char *path; - char *type; - char *type_instance; + const char *path; + const char *type; + const char *type_instance; gauge_t factor; } metrics[] = { - {STATEFS_ROOT "Current", "current", NULL, 1e-6}, // from uA to A - {STATEFS_ROOT "Energy", "energy_wh", NULL, 1e-6}, // from uWh to Wh - {STATEFS_ROOT "Power", "power", NULL, 1e-6}, // from uW to W - {STATEFS_ROOT "Temperature", "temperature", NULL, 0.1}, // from 10xC to C - {STATEFS_ROOT "TimeUntilFull", "duration", "full", 1.0}, - {STATEFS_ROOT "TimeUntilLow", "duration", "low", 1.0}, - {STATEFS_ROOT "Voltage", "voltage", NULL, 1e-6}, // from uV to V + {STATEFS_ROOT "Current", "current", NULL, 1e-6}, // from uA to A + {STATEFS_ROOT "Energy", "energy_wh", NULL, 1e-6}, // from uWh to Wh + {STATEFS_ROOT "Power", "power", NULL, 1e-6}, // from uW to W + {STATEFS_ROOT "Temperature", "temperature", NULL, 0.1}, // from 10xC to C + {STATEFS_ROOT "TimeUntilFull", "duration", "full", 1.0}, + {STATEFS_ROOT "TimeUntilLow", "duration", "low", 1.0}, + {STATEFS_ROOT "Voltage", "voltage", NULL, 1e-6}, // from uV to V }; for (size_t i = 0; i < STATIC_ARRAY_SIZE(metrics); i++) { @@ -106,14 +107,16 @@ int battery_read_statefs(void) { continue; } - battery_submit(metrics[i].type, v.gauge * metrics[i].factor, metrics[i].type_instance); + battery_submit(metrics[i].type, v.gauge * metrics[i].factor, + metrics[i].type_instance); success++; } if (success == 0) { - ERROR("battery plugin: statefs backend: none of the statistics are available"); - return (-1); + ERROR("battery plugin: statefs backend: none of the statistics are " + "available"); + return -1; } - return (0); + return 0; }