projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
memcached plugin: Pass `ai_hints' to `getaddrinfo'.
[collectd.git]
/
src
/
memcached.c
diff --git
a/src/memcached.c
b/src/memcached.c
index
c3fa06b
..
2d999ce
100644
(file)
--- a/
src/memcached.c
+++ b/
src/memcached.c
@@
-1,7
+1,8
@@
/**
* collectd - src/memcached.c, based on src/hddtemp.c
/**
* collectd - src/memcached.c, based on src/hddtemp.c
- * Copyright (C) 2007 Antony Dovgal
- * Copyright (C) 2005,2006 Vincent Stehlé
+ * Copyright (C) 2007 Antony Dovgal
+ * Copyright (C) 2007-2009 Florian Forster
+ * Copyright (C) 2009 Doug MacEachern
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@@
-19,8
+20,8
@@
*
* Authors:
* Antony Dovgal <tony at daylessday dot org>
*
* Authors:
* Antony Dovgal <tony at daylessday dot org>
- * Vincent Stehlé <vincent.stehle at free.fr>
* Florian octo Forster <octo at verplant.org>
* Florian octo Forster <octo at verplant.org>
+ * Doug MacEachern <dougm at hyperic.com>
**/
#include "collectd.h"
**/
#include "collectd.h"
@@
-81,7
+82,7
@@
static int memcached_query_daemon (char *buffer, int buffer_size) /* {{{ */
port = MEMCACHED_DEF_PORT;
}
port = MEMCACHED_DEF_PORT;
}
- if ((ai_return = getaddrinfo (host, port,
NULL
, &ai_list)) != 0) {
+ if ((ai_return = getaddrinfo (host, port,
&ai_hints
, &ai_list)) != 0) {
char errbuf[1024];
ERROR ("memcached: getaddrinfo (%s, %s): %s",
host, port,
char errbuf[1024];
ERROR ("memcached: getaddrinfo (%s, %s): %s",
host, port,
@@
-212,11
+213,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)) {
} else if (strcasecmp (key, "Port") == 0) {
int port = (int) (atof (value));
if ((port > 0) && (port <= 65535)) {
- snprintf (memcached_port, sizeof (memcached_port), "%i", port);
+ s
s
nprintf (memcached_port, sizeof (memcached_port), "%i", port);
} else {
} else {
- strncpy (memcached_port, value, sizeof (memcached_port));
+ s
s
trncpy (memcached_port, value, sizeof (memcached_port));
}
}
- memcached_port[sizeof (memcached_port) - 1] = '\0';
} else {
return -1;
}
} else {
return -1;
}
@@
-235,16
+235,13
@@
static void submit_counter (const char *type, const char *type_inst,
vl.values = values;
vl.values_len = 1;
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.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "memcached", sizeof (vl.plugin));
+ sstrncpy (vl.type, type, sizeof (vl.type));
if (type_inst != NULL)
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 */
/* }}} */
} /* void memcached_submit_cmd */
/* }}} */
@@
-262,13
+259,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));
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)
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 */
/* }}} */
} /* void memcached_submit_cmd */
/* }}} */
@@
-285,13
+280,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));
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)
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
+302,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));
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)
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
+321,8
@@
static int memcached_read (void) /* {{{ */
gauge_t bytes_used = NAN;
gauge_t bytes_total = NAN;
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;
counter_t rusage_user = 0;
counter_t rusage_syst = 0;
counter_t octets_rx = 0;
@@
-439,6
+432,8
@@
static int memcached_read (void) /* {{{ */
{
const char *name = fields[1] + 4;
submit_counter ("memcached_command", name, atoll (fields[2]));
{
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
+442,7
@@
static int memcached_read (void) /* {{{ */
else if (FIELD_IS ("get_hits"))
{
submit_counter ("memcached_ops", "hits", atoll (fields[2]));
else if (FIELD_IS ("get_hits"))
{
submit_counter ("memcached_ops", "hits", atoll (fields[2]));
+ hits = atof (fields[2]);
}
else if (FIELD_IS ("get_misses"))
{
}
else if (FIELD_IS ("get_misses"))
{
@@
-479,6
+475,16
@@
static int memcached_read (void) /* {{{ */
if ((octets_rx != 0) || (octets_tx != 0))
submit_counter2 ("memcached_octets", NULL, octets_rx, octets_tx);
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;
}
/* }}} */
return 0;
}
/* }}} */