X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fbattery_statefs.c;h=149512b9f48fdf85056dd047da03a85d292ee6b6;hp=a0ff18725276341c0dc88f8e6f4b8f5b9bef5bfb;hb=da11ce02eb202b3e01d3e2d1b40f248a84430973;hpb=92860d61218a3da1e9b74a2fad37e9df88df8ce8 diff --git a/src/battery_statefs.c b/src/battery_statefs.c index a0ff1872..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,7 +56,7 @@ 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.plugin, "battery", sizeof(vl.plugin)); /* statefs supports 1 battery at present */ @@ -72,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++) { @@ -105,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; }