X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fmemcached.c;h=b5a4b208365b8fba6d99453387f8c10d492ae916;hb=4027126a75439c7d2b1d5572092fd291ef19ead6;hp=8d6f72811969760bf6573b5fed7f4956bf0c4d8c;hpb=d9ba7e3ed5d93e9abd34f961fff51676a096ac02;p=collectd.git diff --git a/src/memcached.c b/src/memcached.c index 8d6f7281..b5a4b208 100644 --- a/src/memcached.c +++ b/src/memcached.c @@ -134,7 +134,7 @@ static int memcached_query_daemon (char *buffer, int buffer_size) /* {{{ */ p.events = POLLIN | POLLERR | POLLHUP; p.revents = 0; - status = poll (&p, /* nfds = */ 1, /* timeout = */ interval_g); + status = poll (&p, /* nfds = */ 1, /* timeout = */ 1000 * interval_g); if (status <= 0) { if (status == 0) @@ -212,11 +212,10 @@ static int memcached_config (const char *key, const char *value) /* {{{ */ } else if (strcasecmp (key, "Port") == 0) { int port = (int) (atof (value)); if ((port > 0) && (port <= 65535)) { - snprintf (memcached_port, sizeof (memcached_port), "%i", port); + ssnprintf (memcached_port, sizeof (memcached_port), "%i", port); } else { - strncpy (memcached_port, value, sizeof (memcached_port)); + sstrncpy (memcached_port, value, sizeof (memcached_port)); } - memcached_port[sizeof (memcached_port) - 1] = '\0'; } else { return -1; } @@ -235,16 +234,13 @@ static void submit_counter (const char *type, const char *type_inst, vl.values = values; vl.values_len = 1; - vl.time = time (NULL); sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "memcached", sizeof (vl.plugin)); + sstrncpy (vl.type, type, sizeof (vl.type)); if (type_inst != NULL) - { - strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; - } + sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); } /* void memcached_submit_cmd */ /* }}} */ @@ -262,13 +258,11 @@ static void submit_counter2 (const char *type, const char *type_inst, vl.time = time (NULL); sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "memcached", sizeof (vl.plugin)); + sstrncpy (vl.type, type, sizeof (vl.type)); if (type_inst != NULL) - { - strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; - } + sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); } /* void memcached_submit_cmd */ /* }}} */ @@ -285,13 +279,11 @@ static void submit_gauge (const char *type, const char *type_inst, vl.time = time (NULL); sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "memcached", sizeof (vl.plugin)); + sstrncpy (vl.type, type, sizeof (vl.type)); if (type_inst != NULL) - { - strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; - } + sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); } /* }}} */ @@ -309,13 +301,11 @@ static void submit_gauge2 (const char *type, const char *type_inst, vl.time = time (NULL); sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "memcached", sizeof (vl.plugin)); + sstrncpy (vl.type, type, sizeof (vl.type)); if (type_inst != NULL) - { - strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; - } + sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); } /* }}} */ @@ -330,6 +320,8 @@ static int memcached_read (void) /* {{{ */ gauge_t bytes_used = NAN; gauge_t bytes_total = NAN; + gauge_t hits = NAN; + gauge_t gets = NAN; counter_t rusage_user = 0; counter_t rusage_syst = 0; counter_t octets_rx = 0; @@ -439,6 +431,8 @@ static int memcached_read (void) /* {{{ */ { const char *name = fields[1] + 4; submit_counter ("memcached_command", name, atoll (fields[2])); + if (strcmp (name, "get") == 0) + gets = atof (fields[2]); } /* @@ -447,6 +441,7 @@ static int memcached_read (void) /* {{{ */ else if (FIELD_IS ("get_hits")) { submit_counter ("memcached_ops", "hits", atoll (fields[2])); + hits = atof (fields[2]); } else if (FIELD_IS ("get_misses")) { @@ -479,6 +474,16 @@ static int memcached_read (void) /* {{{ */ if ((octets_rx != 0) || (octets_tx != 0)) submit_counter2 ("memcached_octets", NULL, octets_rx, octets_tx); + if (!isnan (gets) && !isnan (hits)) + { + gauge_t rate = NAN; + + if (gets != 0.0) + rate = 100.0 * hits / gets; + + submit_gauge ("percent", "hitratio", rate); + } + return 0; } /* }}} */