From fb558eeea9d5a96a268bd7065accd8d7a9991645 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Fri, 14 Dec 2012 11:40:12 +0100 Subject: [PATCH] apcups plugin: Implement the "ReportSeconds" option. --- src/apcups.c | 19 +++++++++++++++++-- src/collectd.conf.in | 1 + src/collectd.conf.pod | 6 ++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/apcups.c b/src/apcups.c index 4fbbde63..dd535b15 100644 --- a/src/apcups.c +++ b/src/apcups.c @@ -70,6 +70,8 @@ struct apc_detail_s /* Default values for contacting daemon */ static char *conf_host = NULL; static int conf_port = NISPORT; +/* Defaults to false for backwards compatibility. */ +static _Bool conf_report_seconds = 0; static int global_sockfd = -1; @@ -81,9 +83,9 @@ static const char *config_keys[] = { "Host", "Port", - NULL + "ReportSeconds" }; -static int config_keys_num = 2; +static int config_keys_num = STATIC_ARRAY_SIZE (config_keys); static int net_shutdown (int *fd) { @@ -360,7 +362,13 @@ static int apc_query_server (char *host, int port, else if (strcmp ("LINEFREQ", key) == 0) apcups_detail->linefreq = value; else if (strcmp ("TIMELEFT", key) == 0) + { + /* Convert minutes to seconds if requested by + * the user. */ + if (conf_report_seconds) + value *= 60.0; apcups_detail->timeleft = value; + } tokptr = strtok_r (NULL, ":", &toksaveptr); } /* while (tokptr != NULL) */ @@ -403,6 +411,13 @@ static int apcups_config (const char *key, const char *value) } conf_port = port_tmp; } + else if (strcasecmp (key, "ReportSeconds") == 0) + { + if (IS_TRUE (value)) + conf_report_seconds = 1; + else + conf_report_seconds = 0; + } else { return (-1); diff --git a/src/collectd.conf.in b/src/collectd.conf.in index 87af1c96..a565a579 100644 --- a/src/collectd.conf.in +++ b/src/collectd.conf.in @@ -208,6 +208,7 @@ # # Host "localhost" # Port "3551" +# ReportSeconds true # # diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index f011dbcd..b9f9549d 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -641,6 +641,12 @@ B can handle it. TCP-Port to connect to. Defaults to B<3551>. +=item B B + +If set to B, the time reported in the C metric will be +converted to seconds. This is the recommended setting. If set to B, the +default for backwards compatibility, the time will be reported in minutes. + =back =head2 Plugin C -- 2.11.0