X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fmemcached.c;h=ee3dbe12d67c4998b3ac65ede2f808016370023f;hb=fadd1df67243af6d0d4f58b10b21755ee1f433d6;hp=759ef512b7cbc8ccc2da7ed268f96b8a2857e1a5;hpb=a3da854628383819439f0680acd2786fd00744fe;p=collectd.git diff --git a/src/memcached.c b/src/memcached.c index 759ef512..ee3dbe12 100644 --- a/src/memcached.c +++ b/src/memcached.c @@ -1,8 +1,9 @@ /** * collectd - src/memcached.c, based on src/hddtemp.c - * Copyright (C) 2007 Antony Dovgal - * Copyright (C) 2005,2006 Vincent Stehlé - * Copyright (C) 2009 Franck Lombardi + * Copyright (C) 2007 Antony Dovgal + * Copyright (C) 2007-2010 Florian Forster + * Copyright (C) 2009 Doug MacEachern + * Copyright (C) 2009 Franck Lombardi * * 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 @@ -20,8 +21,8 @@ * * Authors: * Antony Dovgal - * Vincent Stehlé - * Florian octo Forster + * Florian octo Forster + * Doug MacEachern * Franck Lombardi **/ @@ -37,6 +38,11 @@ # include # include +/* Hack to work around the missing define in AIX */ +#ifndef MSG_DONTWAIT +# define MSG_DONTWAIT MSG_NONBLOCK +#endif + #define MEMCACHED_DEF_HOST "127.0.0.1" #define MEMCACHED_DEF_PORT "11211" @@ -66,7 +72,8 @@ static int memcached_query_daemon (char *buffer, int buffer_size) /* {{{ */ memset (&serv_addr, 0, sizeof (serv_addr)); serv_addr.sun_family = AF_UNIX; - sstrncpy (serv_addr.sun_path, memcached_socket, sizeof (serv_addr.sun_path)); + sstrncpy (serv_addr.sun_path, memcached_socket, + sizeof (serv_addr.sun_path)); /* create our socket descriptor */ fd = socket (AF_UNIX, SOCK_STREAM, 0); @@ -79,7 +86,7 @@ static int memcached_query_daemon (char *buffer, int buffer_size) /* {{{ */ /* connect to the memcached daemon */ status = (ssize_t) connect (fd, (struct sockaddr *) &serv_addr, - SUN_LEN (&serv_addr)); + sizeof (serv_addr)); if (status != 0) { shutdown (fd, SHUT_RDWR); close (fd); @@ -113,7 +120,7 @@ static int memcached_query_daemon (char *buffer, int buffer_size) /* {{{ */ 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, @@ -169,12 +176,14 @@ static int memcached_query_daemon (char *buffer, int buffer_size) /* {{{ */ p.events = POLLIN | POLLERR | POLLHUP; p.revents = 0; - status = poll (&p, /* nfds = */ 1, /* timeout = */ 1000 * interval_g); + status = poll (&p, /* nfds = */ 1, + /* timeout = */ CDTIME_T_TO_MS (interval_g)); if (status <= 0) { if (status == 0) { - ERROR ("memcached: poll(2) timed out after %i seconds.", interval_g); + ERROR ("memcached: poll(2) timed out after %.3f seconds.", + CDTIME_T_TO_DOUBLE (interval_g)); } else { @@ -264,13 +273,13 @@ static int memcached_config (const char *key, const char *value) /* {{{ */ } /* }}} */ -static void submit_counter (const char *type, const char *type_inst, - counter_t value) /* {{{ */ +static void submit_derive (const char *type, const char *type_inst, + derive_t value) /* {{{ */ { value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].counter = value; + values[0].derive = value; vl.values = values; vl.values_len = 1; @@ -284,18 +293,17 @@ static void submit_counter (const char *type, const char *type_inst, } /* void memcached_submit_cmd */ /* }}} */ -static void submit_counter2 (const char *type, const char *type_inst, - counter_t value0, counter_t value1) /* {{{ */ +static void submit_derive2 (const char *type, const char *type_inst, + derive_t value0, derive_t value1) /* {{{ */ { value_t values[2]; value_list_t vl = VALUE_LIST_INIT; - values[0].counter = value0; - values[1].counter = value1; + values[0].derive = value0; + values[1].derive = value1; vl.values = values; vl.values_len = 2; - 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)); @@ -316,7 +324,6 @@ static void submit_gauge (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)); @@ -338,7 +345,6 @@ static void submit_gauge2 (const char *type, const char *type_inst, vl.values = values; vl.values_len = 2; - 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)); @@ -362,10 +368,10 @@ static int memcached_read (void) /* {{{ */ 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 octets_tx = 0; + derive_t rusage_user = 0; + derive_t rusage_syst = 0; + derive_t octets_rx = 0; + derive_t octets_tx = 0; /* get data from daemon */ if (memcached_query_daemon (buf, sizeof (buf)) < 0) { @@ -450,7 +456,7 @@ static int memcached_read (void) /* {{{ */ else if ((name_len > 4) && (strncmp (fields[1], "cmd_", 4) == 0)) { const char *name = fields[1] + 4; - submit_counter ("memcached_command", name, atoll (fields[2])); + submit_derive ("memcached_command", name, atoll (fields[2])); if (strcmp (name, "get") == 0) gets = atof (fields[2]); } @@ -460,16 +466,16 @@ static int memcached_read (void) /* {{{ */ */ else if (FIELD_IS ("get_hits")) { - submit_counter ("memcached_ops", "hits", atoll (fields[2])); + submit_derive ("memcached_ops", "hits", atoll (fields[2])); hits = atof (fields[2]); } else if (FIELD_IS ("get_misses")) { - submit_counter ("memcached_ops", "misses", atoll (fields[2])); + submit_derive ("memcached_ops", "misses", atoll (fields[2])); } else if (FIELD_IS ("evictions")) { - submit_counter ("memcached_ops", "evictions", atoll (fields[2])); + submit_derive ("memcached_ops", "evictions", atoll (fields[2])); } /* @@ -489,10 +495,10 @@ static int memcached_read (void) /* {{{ */ submit_gauge2 ("df", "cache", bytes_used, bytes_total - bytes_used); if ((rusage_user != 0) || (rusage_syst != 0)) - submit_counter2 ("ps_cputime", NULL, rusage_user, rusage_syst); + submit_derive2 ("ps_cputime", NULL, rusage_user, rusage_syst); if ((octets_rx != 0) || (octets_tx != 0)) - submit_counter2 ("memcached_octets", NULL, octets_rx, octets_tx); + submit_derive2 ("memcached_octets", NULL, octets_rx, octets_tx); if (!isnan (gets) && !isnan (hits)) {