From: Florian Forster Date: Mon, 8 Jun 2015 10:36:04 +0000 (+0200) Subject: apcups plugin: Implement the "PersistentConnection" option. X-Git-Tag: collectd-5.6.0~697 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=9b4f1327773717688653e080da89e0e19fc9a26f;p=collectd.git apcups plugin: Implement the "PersistentConnection" option. If set to false, close the connection after each interval. This lets users chose this method if persistent connections pose a problem. Fixes: #617 --- diff --git a/src/apcups.c b/src/apcups.c index 66fe45e1..dc533f1e 100644 --- a/src/apcups.c +++ b/src/apcups.c @@ -74,12 +74,12 @@ static char *conf_node = NULL; static char *conf_service = NULL; /* Defaults to false for backwards compatibility. */ static _Bool conf_report_seconds = 0; +static _Bool conf_persistent_conn = 1; static int global_sockfd = -1; static int count_retries = 0; static int count_iterations = 0; -static _Bool close_socket = 0; static int net_shutdown (int *fd) { @@ -314,7 +314,7 @@ static int apc_query_server (char const *node, char const *service, "first %i iterations. Will close the socket " "in future iterations.", count_retries, count_iterations); - close_socket = 1; + conf_persistent_conn = 0; } while ((n = net_recv (&global_sockfd, recvline, sizeof (recvline) - 1)) > 0) @@ -367,7 +367,7 @@ static int apc_query_server (char const *node, char const *service, } status = errno; /* save errno, net_shutdown() may re-set it. */ - if (close_socket) + if (!conf_persistent_conn) net_shutdown (&global_sockfd); if (n < 0) @@ -395,6 +395,8 @@ static int apcups_config (oconfig_item_t *ci) cf_util_get_service (child, &conf_service); else if (strcasecmp (child->key, "ReportSeconds") == 0) cf_util_get_boolean (child, &conf_report_seconds); + else if (strcasecmp (child->key, "PersistentConnection") == 0) + cf_util_get_boolean (child, &conf_persistent_conn); else ERROR ("apcups plugin: Unknown config option \"%s\".", child->key); } diff --git a/src/collectd.conf.in b/src/collectd.conf.in index 99f879cc..5a4c4674 100644 --- a/src/collectd.conf.in +++ b/src/collectd.conf.in @@ -264,6 +264,7 @@ # Host "localhost" # Port "3551" # ReportSeconds true +# PersistentConnection true # # diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 1884914f..16315ade 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -802,12 +802,22 @@ B can handle it. TCP-Port to connect to. Defaults to B<3551>. -=item B B +=item B 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. +=item B B|B + +By default, the plugin will try to keep the connection to UPS open between +reads. Since this appears to be somewhat brittle (I appears to close +the connection due to inactivity quite quickly), the plugin will try to detect +this problem and switch to an open-read-close mode in such cases. + +You can instruct the plugin to close the connection after each read by setting +this option to B. + =back =head2 Plugin C