author | Florian Forster <octo@collectd.org> | |
Sat, 5 Dec 2015 07:57:07 +0000 (08:57 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Sat, 5 Dec 2015 07:57:07 +0000 (08:57 +0100) |
26 files changed:
diff --git a/src/ceph.c b/src/ceph.c
index d762754d51733326aa58d466c60f29404675d762..2a85823299f9cdad62608005265d7254f72f0095 100644 (file)
--- a/src/ceph.c
+++ b/src/ceph.c
{
node_handler_t handler;
void * handler_arg;
- struct {
- char key[DATA_MAX_NAME_LEN];
- int key_len;
- } state[YAJL_MAX_DEPTH];
- int depth;
+
+ char *key;
+ char *stack[YAJL_MAX_DEPTH];
+ size_t depth;
};
typedef struct yajl_struct yajl_struct;
return CEPH_CB_CONTINUE;
}
+#define BUFFER_ADD(dest, src) do { \
+ size_t dest_size = sizeof (dest); \
+ strncat ((dest), (src), dest_size - strlen (dest)); \
+ (dest)[dest_size - 1] = 0; \
+} while (0)
+
static int
ceph_cb_number(void *ctx, const char *number_val, yajl_len_t number_len)
{
- yajl_struct *yajl = (yajl_struct*)ctx;
+ yajl_struct *state = (yajl_struct*) ctx;
char buffer[number_len+1];
- int i, latency_type = 0, result;
- char key[128];
+ char key[2 * DATA_MAX_NAME_LEN];
+ _Bool latency_type = 0;
+ size_t i;
+ int status;
memcpy(buffer, number_val, number_len);
buffer[sizeof(buffer) - 1] = 0;
- ssnprintf(key, yajl->state[0].key_len, "%s", yajl->state[0].key);
- for(i = 1; i < yajl->depth; i++)
+ memset (key, 0, sizeof (key));
+ for (i = 0; i < state->depth; i++)
{
- if((i == yajl->depth-1) && ((strcmp(yajl->state[i].key,"avgcount") == 0)
- || (strcmp(yajl->state[i].key,"sum") == 0)))
+ if (state->stack[i] == NULL)
+ continue;
+
+ if (strlen (key) != 0)
+ BUFFER_ADD (key, ".");
+ BUFFER_ADD (key, state->stack[i]);
+ }
+
+ /* Special case for latency metrics. */
+ if ((strcmp ("avgcount", state->key) == 0)
+ || (strcmp ("sum", state->key) == 0))
+ {
+ latency_type = 1;
+
+ /* Super-special case for filestore.journal_wr_bytes.avgcount: For
+ * some reason, Ceph schema encodes this as a count/sum pair while all
+ * other "Bytes" data (excluding used/capacity bytes for OSD space) uses
+ * a single "Derive" type. To spare further confusion, keep this KPI as
+ * the same type of other "Bytes". Instead of keeping an "average" or
+ * "rate", use the "sum" in the pair and assign that to the derive
+ * value. */
+ if (convert_special_metrics && (state->depth >= 2)
+ && (strcmp("filestore", state->stack[state->depth - 2]) == 0)
+ && (strcmp("journal_wr_bytes", state->stack[state->depth - 1]) == 0)
+ && (strcmp("avgcount", state->key) == 0))
{
- if(convert_special_metrics)
- {
- /**
- * Special case for filestore:JournalWrBytes. For some reason,
- * Ceph schema encodes this as a count/sum pair while all
- * other "Bytes" data (excluding used/capacity bytes for OSD
- * space) uses a single "Derive" type. To spare further
- * confusion, keep this KPI as the same type of other "Bytes".
- * Instead of keeping an "average" or "rate", use the "sum" in
- * the pair and assign that to the derive value.
- */
- if((strcmp(yajl->state[i-1].key, "journal_wr_bytes") == 0) &&
- (strcmp(yajl->state[i-2].key,"filestore") == 0) &&
- (strcmp(yajl->state[i].key,"avgcount") == 0))
- {
- DEBUG("ceph plugin: Skipping avgcount for filestore.JournalWrBytes");
- yajl->depth = (yajl->depth - 1);
- return CEPH_CB_CONTINUE;
- }
- }
- //probably a avgcount/sum pair. if not - we'll try full key later
- latency_type = 1;
- break;
+ DEBUG("ceph plugin: Skipping avgcount for filestore.JournalWrBytes");
+ return CEPH_CB_CONTINUE;
}
- strncat(key, ".", 1);
- strncat(key, yajl->state[i].key, yajl->state[i].key_len+1);
+ }
+ else /* not a latency type */
+ {
+ BUFFER_ADD (key, ".");
+ BUFFER_ADD (key, state->key);
}
- result = yajl->handler(yajl->handler_arg, buffer, key);
-
- if((result == RETRY_AVGCOUNT) && latency_type)
+ status = state->handler(state->handler_arg, buffer, key);
+ if((status == RETRY_AVGCOUNT) && latency_type)
{
- strncat(key, ".", 1);
- strncat(key, yajl->state[yajl->depth-1].key,
- yajl->state[yajl->depth-1].key_len+1);
- result = yajl->handler(yajl->handler_arg, buffer, key);
+ /* Add previously skipped part of the key, either "avgcount" or "sum",
+ * and try again. */
+ BUFFER_ADD (key, ".");
+ BUFFER_ADD (key, state->key);
+
+ status = state->handler(state->handler_arg, buffer, key);
}
- if(result == -ENOMEM)
+ if (status != 0)
{
- ERROR("ceph plugin: memory allocation failed");
+ ERROR("ceph plugin: JSON handler failed with status %d.", status);
return CEPH_CB_ABORT;
}
- yajl->depth = (yajl->depth - 1);
return CEPH_CB_CONTINUE;
}
static int ceph_cb_start_map(void *ctx)
{
+ yajl_struct *state = (yajl_struct*) ctx;
+
+ /* Push key to the stack */
+ if (state->depth == YAJL_MAX_DEPTH)
+ return CEPH_CB_ABORT;
+
+ state->stack[state->depth] = state->key;
+ state->depth++;
+ state->key = NULL;
+
return CEPH_CB_CONTINUE;
}
-static int
-ceph_cb_map_key(void *ctx, const unsigned char *key, yajl_len_t string_len)
+static int ceph_cb_end_map(void *ctx)
{
- yajl_struct *yajl = (yajl_struct*)ctx;
+ yajl_struct *state = (yajl_struct*) ctx;
- if((yajl->depth+1) >= YAJL_MAX_DEPTH)
- {
- ERROR("ceph plugin: depth exceeds max, aborting.");
+ /* Pop key from the stack */
+ if (state->depth == 0)
return CEPH_CB_ABORT;
- }
-
- char buffer[string_len+1];
-
- memcpy(buffer, key, string_len);
- buffer[sizeof(buffer) - 1] = 0;
- snprintf(yajl->state[yajl->depth].key, sizeof(buffer), "%s", buffer);
- yajl->state[yajl->depth].key_len = sizeof(buffer);
- yajl->depth = (yajl->depth + 1);
+ sfree (state->key);
+ state->depth--;
+ state->key = state->stack[state->depth];
+ state->stack[state->depth] = NULL;
return CEPH_CB_CONTINUE;
}
-static int ceph_cb_end_map(void *ctx)
+static int
+ceph_cb_map_key(void *ctx, const unsigned char *key, yajl_len_t string_len)
{
- yajl_struct *yajl = (yajl_struct*)ctx;
+ yajl_struct *state = (yajl_struct*) ctx;
+ size_t sz = ((size_t) string_len) + 1;
+
+ sfree (state->key);
+ state->key = malloc (sz);
+ if (state->key == NULL)
+ {
+ ERROR ("ceph plugin: malloc failed.");
+ return CEPH_CB_ABORT;
+ }
+
+ memmove (state->key, key, sz - 1);
+ state->key[sz - 1] = 0;
- yajl->depth = (yajl->depth - 1);
return CEPH_CB_CONTINUE;
}
plugin_register_read("ceph", ceph_read);
plugin_register_shutdown("ceph", ceph_shutdown);
}
+/* vim: set sw=4 sts=4 et : */
diff --git a/src/ceph_test.c b/src/ceph_test.c
index d6c72316485c3aa0f3c8b1b629c14686115bfe70..acab179ed66c231b75f91ca6883c3e360756929a 100644 (file)
--- a/src/ceph_test.c
+++ b/src/ceph_test.c
#include "ceph.c" /* sic */
#include "testing.h"
+struct case_s
+{
+ char *key;
+ char *value;
+};
+typedef struct case_s case_t;
+
+struct test_s
+{
+ case_t *cases;
+ size_t cases_num;
+};
+typedef struct test_s test_t;
+
+static int test_handler(void *user, char const *val, char const *key)
+{
+ test_t *t = user;
+ size_t i;
+
+ char status[1024];
+ _Bool ok;
+
+ /* special case for latency metrics. */
+ if (strcmp ("filestore.example_latency", key) == 0)
+ return RETRY_AVGCOUNT;
+
+ snprintf (status, sizeof (status), "unexpected call: test_handler(\"%s\") = \"%s\"", key, val);
+ ok = 0;
+
+ for (i = 0; i < t->cases_num; i++)
+ {
+ if (strcmp (key, t->cases[i].key) != 0)
+ continue;
+
+ if (strcmp (val, t->cases[i].value) != 0)
+ {
+ snprintf (status, sizeof (status), "test_handler(\"%s\") = \"%s\", want \"%s\"", key, val, t->cases[i].value);
+ ok = 0;
+ break;
+ }
+
+ snprintf (status, sizeof (status), "test_handler(\"%s\") = \"%s\"", key, val);
+ ok = 1;
+ break;
+ }
+
+ OK1(ok, status);
+ return ok ? 0 : -1;
+}
+
+DEF_TEST(traverse_json)
+{
+ char const *json = "{\n"
+ " \"WBThrottle\": {\n"
+ " \"bytes_dirtied\": {\n"
+ " \"type\": 2,\n"
+ " \"description\": \"Dirty data\",\n"
+ " \"nick\": \"\"\n"
+ " },\n"
+ " \"bytes_wb\": {\n"
+ " \"type\": 2,\n"
+ " \"description\": \"Written data\",\n"
+ " \"nick\": \"\"\n"
+ " },\n"
+ " \"ios_dirtied\": {\n"
+ " \"type\": 2,\n"
+ " \"description\": \"Dirty operations\",\n"
+ " \"nick\": \"\"\n"
+ " },\n"
+ " \"ios_wb\": {\n"
+ " \"type\": 2,\n"
+ " \"description\": \"Written operations\",\n"
+ " \"nick\": \"\"\n"
+ " },\n"
+ " \"inodes_dirtied\": {\n"
+ " \"type\": 2,\n"
+ " \"description\": \"Entries waiting for write\",\n"
+ " \"nick\": \"\"\n"
+ " },\n"
+ " \"inodes_wb\": {\n"
+ " \"type\": 10,\n"
+ " \"description\": \"Written entries\",\n"
+ " \"nick\": \"\"\n"
+ " }\n"
+ " },\n"
+ " \"filestore\": {\n"
+ " \"journal_wr_bytes\": {\n"
+ " \"avgcount\": 23,\n"
+ " \"sum\": 3117\n"
+ " },\n"
+ " \"example_latency\": {\n"
+ " \"avgcount\": 42,\n"
+ " \"sum\": 4711\n"
+ " }\n"
+ " }\n"
+ "}\n";
+ case_t cases[] = {
+ {"WBThrottle.bytes_dirtied.type", "2"},
+ {"WBThrottle.bytes_wb.type", "2"},
+ {"WBThrottle.ios_dirtied.type", "2"},
+ {"WBThrottle.ios_wb.type", "2"},
+ {"WBThrottle.inodes_dirtied.type", "2"},
+ {"WBThrottle.inodes_wb.type", "10"},
+ {"filestore.journal_wr_bytes", "3117"},
+ {"filestore.example_latency.avgcount", "42"},
+ {"filestore.example_latency.sum", "4711"},
+ };
+ test_t t = {cases, STATIC_ARRAY_SIZE (cases)};
+
+ yajl_struct ctx = {test_handler, &t};
+
+ yajl_handle hndl;
+#if HAVE_YAJL_V2
+ hndl = yajl_alloc (&callbacks, NULL, &ctx);
+ CHECK_ZERO (traverse_json ((unsigned char *) json, (uint32_t) strlen (json), hndl));
+ CHECK_ZERO (yajl_complete_parse (hndl));
+#else
+ hndl = yajl_alloc (&callbacks, NULL, NULL, &ctx);
+ CHECK_ZERO (traverse_json ((unsigned char *) json, (uint32_t) strlen (json), hndl));
+ CHECK_ZERO (yajl_parse_complete (hndl));
+#endif
+
+ return 0;
+}
+
DEF_TEST(parse_keys)
{
struct {
{"aa.bb.cc.dd.ee.ff", "Aa.bb.cc.dd.ee.ff"},
{"aa.bb.cc.dd.ee.ff.type", "Aa.bb.cc.dd.ee.ff"},
{"aa.type", "Aa.type"},
+ {"WBThrottle.bytes_dirtied.type", "WBThrottle.bytesDirtied"},
};
size_t i;
int main (void)
{
+ RUN_TEST(traverse_json);
RUN_TEST(parse_keys);
END_TEST;
diff --git a/src/cpu.c b/src/cpu.c
index bcaea38c546305968487a8c509e117b09dfa1e0a..7f8c9858995c7d11f3d853905e4d3e574d660822 100644 (file)
--- a/src/cpu.c
+++ b/src/cpu.c
port_host = mach_host_self ();
- /* FIXME: Free `cpu_list' if it's not NULL */
- if ((status = host_processors (port_host, &cpu_list, &cpu_list_len)) != KERN_SUCCESS)
+ status = host_processors (port_host, &cpu_list, &cpu_list_len);
+ if (status == KERN_INVALID_ARGUMENT)
{
- ERROR ("cpu plugin: host_processors returned %i", (int) status);
+ ERROR ("cpu plugin: Don't have a privileged host control port. "
+ "The most common cause for this problem is "
+ "that collectd is running without root "
+ "privileges, which are required to read CPU "
+ "load information. "
+ "<https://collectd.org/bugs/22>");
+ cpu_list_len = 0;
+ return (-1);
+ }
+ if (status != KERN_SUCCESS)
+ {
+ ERROR ("cpu plugin: host_processors() failed with status %d.", (int) status);
cpu_list_len = 0;
return (-1);
}
- DEBUG ("host_processors returned %i %s", (int) cpu_list_len, cpu_list_len == 1 ? "processor" : "processors");
INFO ("cpu plugin: Found %i processor%s.", (int) cpu_list_len, cpu_list_len == 1 ? "" : "s");
/* #endif PROCESSOR_CPU_LOAD_INFO */
diff --git a/src/daemon/collectd.c b/src/daemon/collectd.c
index fc52933111e79fec0c291d115618d4b57f6032e5..06125dce5fa97097e5be76178e89cf4bea3a193d 100644 (file)
--- a/src/daemon/collectd.c
+++ b/src/daemon/collectd.c
#if HAVE_SETLOCALE
if (setlocale (LC_NUMERIC, COLLECTD_LOCALE) == NULL)
WARNING ("setlocale (\"%s\") failed.", COLLECTD_LOCALE);
+
+ /* Update the environment, so that libraries that are calling
+ * setlocale(LC_NUMERIC, "") don't accidentally revert these changes. */
+ unsetenv ("LC_ALL");
+ setenv ("LC_NUMERIC", COLLECTD_LOCALE, /* overwrite = */ 1);
#endif
#if HAVE_LIBKSTAT
index ae9ab3a6cfe6bd6679fbc3dadc5ffa5a124fc25f..89b0be0b1cc780dc7e185bb232f7123b33344e31 100644 (file)
--- a/src/daemon/configfile.c
+++ b/src/daemon/configfile.c
if (root == NULL)
{
ERROR ("configfile: malloc failed.");
+ closedir (dh);
return (NULL);
}
memset (root, 0, sizeof (oconfig_item_t));
ERROR ("configfile: Not including `%s/%s' because its"
" name is too long.",
dir, de->d_name);
+ closedir (dh);
for (i = 0; i < filenames_num; ++i)
free (filenames[i]);
free (filenames);
filenames_num * sizeof (*filenames));
if (tmp == NULL) {
ERROR ("configfile: realloc failed.");
+ closedir (dh);
for (i = 0; i < filenames_num - 1; ++i)
free (filenames[i]);
free (filenames);
}
if (filenames == NULL)
+ {
+ closedir (dh);
return (root);
+ }
qsort ((void *) filenames, filenames_num, sizeof (*filenames),
cf_compare_string);
free (name);
}
+ closedir (dh);
free(filenames);
return (root);
} /* oconfig_item_t *cf_read_dir */
-/*
+/*
* cf_read_generic
*
* Path is stat'ed and either cf_read_file or cf_read_dir is called
diff --git a/src/df.c b/src/df.c
index cb0ff2ffe2ba5bfcefb046c0502021b27f4411c6..ef9e41307d8d2e9a1cba8eeba5b82bf8e54dd731 100644 (file)
--- a/src/df.c
+++ b/src/df.c
{
unsigned long long blocksize;
char disk_name[256];
+ cu_mount_t *dup_ptr;
uint64_t blk_free;
uint64_t blk_reserved;
uint64_t blk_used;
if (ignorelist_match (il_fstype, mnt_ptr->type))
continue;
+ /* search for duplicates *in front of* the current mnt_ptr. */
+ for (dup_ptr = mnt_list; dup_ptr != NULL; dup_ptr = dup_ptr->next)
+ {
+ /* No duplicate found: mnt_ptr is the first of its kind. */
+ if (dup_ptr == mnt_ptr)
+ {
+ dup_ptr = NULL;
+ break;
+ }
+
+ /* Duplicate found: leave non-NULL dup_ptr. */
+ if (by_device && (strcmp (mnt_ptr->spec_device, dup_ptr->spec_device) == 0))
+ break;
+ else if (!by_device && (strcmp (mnt_ptr->dir, dup_ptr->dir) == 0))
+ break;
+ }
+
+ /* ignore duplicates */
+ if (dup_ptr != NULL)
+ continue;
+
if (STATANYFS (mnt_ptr->dir, &statbuf) < 0)
{
char errbuf[1024];
diff --git a/src/exec.c b/src/exec.c
old mode 100755 (executable)
new mode 100644 (file)
new mode 100644 (file)
diff --git a/src/memcached.c b/src/memcached.c
index f684abffe9314515771d75cef1d1cd81143838ee..d7578b625c8a1d7db08aa4f69a19af48f708a598 100644 (file)
--- a/src/memcached.c
+++ b/src/memcached.c
}
else if (FIELD_IS ("listen_disabled_num"))
{
- submit_derive ("memcached_connections", "listen_disabled", atof (fields[2]), st);
+ submit_derive ("connections", "listen_disabled", atof (fields[2]), st);
}
/*
diff --git a/src/multimeter.c b/src/multimeter.c
index 775eb57e27bff64201f81e83cf6528c36fa0608e..03608e6cfe5e61110e13552f43f7fd8e5963c46c 100644 (file)
--- a/src/multimeter.c
+++ b/src/multimeter.c
for (i = 0; i < 10; i++)
{
- device[strlen(device)-1] = i + '0';
+ device[strlen(device)-1] = i + '0';
- if ((fd = open(device, O_RDWR | O_NOCTTY)) > 0)
+ if ((fd = open(device, O_RDWR | O_NOCTTY)) != -1)
{
struct termios tios;
int rts = TIOCM_RTS;
tcflush(fd, TCIFLUSH);
tcsetattr(fd, TCSANOW, &tios);
ioctl(fd, TIOCMBIC, &rts);
-
+
if (multimeter_read_value (&value) < -1)
{
close (fd);
diff --git a/src/ntpd.c b/src/ntpd.c
index dbde6609f64527ff8d58c91a4e9fda5f53e226e6..ee2c048ee6ec2eea1d2325daed3dca0bd9445aef 100644 (file)
--- a/src/ntpd.c
+++ b/src/ntpd.c
return (0);
}
-static void ntpd_submit (char *type, char *type_inst, double value)
+static void ntpd_submit (char *type, char *type_inst, gauge_t value)
{
value_t values[1];
value_list_t vl = VALUE_LIST_INIT;
* sets the LSB based on whether the peer was reachable. If the LSB is zero,
* the values are out of date. */
static void ntpd_submit_reach (char *type, char *type_inst, uint8_t reach,
- double value)
+ gauge_t value)
{
if (!(reach & 1))
value = NAN;
int ps_num;
int ps_size;
+ gauge_t offset_loop;
+ gauge_t freq_loop;
+ gauge_t offset_error;
+
int status;
int i;
+ /* On Linux, if the STA_NANO bit is set in ik->status, then ik->offset
+ * is is nanoseconds, otherwise it's microseconds.
+ * TODO(octo): STA_NANO is defined in the Linux specific <sys/timex.h> header. */
+ double scale_loop = 1e-6;
+ double scale_error = 1e-6;
+
ik = NULL;
ik_num = 0;
ik_size = 0;
}
/* kerninfo -> estimated error */
+ offset_loop = scale_loop * ((gauge_t) ntohl (ik->offset));
+ freq_loop = ntpd_read_fp (ik->freq);
+ offset_error = scale_error * ((gauge_t) ntohl (ik->esterror));
DEBUG ("info_kernel:\n"
- " pll offset = %.8f\n"
- " pll frequency = %.8f\n" /* drift compensation */
- " est error = %.8f\n",
- ntpd_read_fp (ik->offset),
- ntpd_read_fp (ik->freq),
- ntpd_read_fp (ik->esterror));
-
- ntpd_submit ("frequency_offset", "loop", ntpd_read_fp (ik->freq));
- ntpd_submit ("time_offset", "loop", ntpd_read_fp (ik->offset));
- ntpd_submit ("time_offset", "error", ntpd_read_fp (ik->esterror));
+ " pll offset = %.8g\n"
+ " pll frequency = %.8g\n" /* drift compensation */
+ " est error = %.8g\n",
+ offset_loop, freq_loop, offset_error);
+
+ ntpd_submit ("frequency_offset", "loop", freq_loop);
+ ntpd_submit ("time_offset", "loop", offset_loop);
+ ntpd_submit ("time_offset", "error", offset_error);
free (ik);
ik = NULL;
diff --git a/src/perl.c b/src/perl.c
index cf09586f71abceeb644cc1fd8d9083867fd6da82..14a7a8dfd9d5c350fb9fe1f27b09961fdb1668ba 100644 (file)
--- a/src/perl.c
+++ b/src/perl.c
values = ST (/* stack index = */ 0);
+ if (NULL == values)
+ XSRETURN_EMPTY;
+
/* Make sure the argument is a hash reference. */
if (! (SvROK (values) && (SVt_PVHV == SvTYPE (SvRV (values))))) {
log_err ("Collectd::plugin_dispatch_values: Invalid values.");
XSRETURN_EMPTY;
}
- if (NULL == values)
- XSRETURN_EMPTY;
-
ret = pplugin_dispatch_values (aTHX_ (HV *)SvRV (values));
if (0 == ret)
diff --git a/src/pinba.c b/src/pinba.c
index b6e7b152554a13b00af34ab0fe6bbf3d9be67381..d13d047b208aaab564889c4c3c24b570f2c92a68 100644 (file)
--- a/src/pinba.c
+++ b/src/pinba.c
char errbuf[1024];
ERROR ("pinba plugin: bind(2) failed: %s",
sstrerror (errno, errbuf, sizeof (errbuf)));
+ close (fd);
return (0);
}
diff --git a/src/postgresql.c b/src/postgresql.c
index e68fd3219aad4f439222114d5f8166e27fa06a51..8093eb1243a4a78f8dbd75027d8ae7b755cbc617 100644 (file)
--- a/src/postgresql.c
+++ b/src/postgresql.c
data = udb_query_get_user_data (q);
if (NULL == data) {
- data = (c_psql_user_data_t *) smalloc (sizeof (*data));
+ data = (c_psql_user_data_t *) malloc (sizeof (*data));
if (NULL == data) {
log_err ("Out of memory.");
return -1;
diff --git a/src/processes.c b/src/processes.c
index 63d22fc4f3fbd2860a71577a53974a1c50c332f8..fac4778487f3fb0820925433c04267fbb5ee4e5b 100644 (file)
--- a/src/processes.c
+++ b/src/processes.c
if (status != 0)
{
DEBUG ("ProcessMatch: compiling the regular expression \"%s\" failed.", regexp);
- sfree(new->re);
+ sfree (new->re);
sfree (new);
return;
}
diff --git a/src/rrdtool.c b/src/rrdtool.c
index e093f2b27f5395c7ec304044d84fc305af6e0fef..26d16389c8d2522bd8b6299454aacd780b870434 100644 (file)
--- a/src/rrdtool.c
+++ b/src/rrdtool.c
cache = c_avl_create ((int (*) (const void *, const void *)) strcmp);
if (cache == NULL)
{
+ pthread_mutex_unlock (&cache_lock);
ERROR ("rrdtool plugin: c_avl_create failed.");
return (-1);
}
diff --git a/src/snmp.c b/src/snmp.c
index 8df7edd40a2e173abd3bceb065ecaf0cda4e7d77..3ccf60c3fd8ff638ab90aaa21f8eafcbb5223261 100644 (file)
--- a/src/snmp.c
+++ b/src/snmp.c
@@ -1755,6 +1755,7 @@ static int csnmp_read_value (host_definition_t *host, data_definition_t *data)
res = NULL;
sfree (errstr);
+ sfree (vl.values);
csnmp_host_close_session (host);
return (-1);
diff --git a/src/table.c b/src/table.c
index 4e34a9ec718ed9e90683981c93eb8a5bbc2c1588..aebf0bbfad39123fba3f34b58d02c06bd743f1be 100644 (file)
--- a/src/table.c
+++ b/src/table.c
res = (tbl_result_t *)realloc (tbl->results,
(tbl->results_num + 1) * sizeof (*tbl->results));
- if (NULL == tbl) {
+ if (res == NULL) {
char errbuf[1024];
log_err ("realloc failed: %s.",
sstrerror (errno, errbuf, sizeof (errbuf)));
diff --git a/src/teamspeak2.c b/src/teamspeak2.c
index 56e8d14e968642d4f632542ac8f9047a3562bf0d..058eb7c38362a7cc972ca609556698e1537933f6 100644 (file)
--- a/src/teamspeak2.c
+++ b/src/teamspeak2.c
WARNING ("teamspeak2 plugin: connect failed: %s",
sstrerror (errno, errbuf, sizeof (errbuf)));
close (sd);
+ sd = -1;
continue;
}
diff --git a/src/threshold.c b/src/threshold.c
index 38c7efb016d73a1d62bd10bb3efb0e5670caf1e1..b753d37445166c4facfdd9facf2cabbf8e4fa1be 100644 (file)
--- a/src/threshold.c
+++ b/src/threshold.c
{ /* {{{ */
int i;
int status = 0;
+ int old_size = c_avl_size (threshold_tree);
threshold_t th;
break;
}
- if (c_avl_size (threshold_tree) > 0) {
+ /* register callbacks if this is the first time we see a valid config */
+ if ((old_size == 0) && (c_avl_size (threshold_tree) > 0))
+ {
plugin_register_missing ("threshold", ut_missing,
/* user data = */ NULL);
plugin_register_write ("threshold", ut_check_threshold,
diff --git a/src/turbostat.c b/src/turbostat.c
index 42fed52a3e496b8e87036f20150023ce50a56ff2..5ab073d547d073fb3d4544143fb3d7f01dd82530 100644 (file)
--- a/src/turbostat.c
+++ b/src/turbostat.c
}
if (fscanf(filep, "%d", &value) != 1) {
ERROR("turbostat plugin: Failed to parse number from '%s'", path);
+ fclose(filep);
return -1;
}
fclose(filep);
diff --git a/src/utils_fbhash.c b/src/utils_fbhash.c
index 70b89089dce13e73e2deb9f25b8db5942ccdaa70..cbd150610205255a8a20478a324175a7feebd35a 100644 (file)
--- a/src/utils_fbhash.c
+++ b/src/utils_fbhash.c
c_avl_tree_t *tree;
};
-/*
+/*
* Private functions
*/
static void fbh_free_tree (c_avl_tree_t *tree) /* {{{ */
return (status);
} /* }}} int fbh_check_file */
-/*
+/*
* Public functions
*/
fbhash_t *fbh_create (const char *file) /* {{{ */
if (status != 0)
{
fbh_destroy (h);
+ free (h);
return (NULL);
}
diff --git a/src/utils_mount.c b/src/utils_mount.c
index afeb39e1162af515ddac44dfda578b3a76c2cdb4..f2b79439adc77e70b495cf7079a38ef18997dfbc 100644 (file)
--- a/src/utils_mount.c
+++ b/src/utils_mount.c
char *
cu_mount_checkoption(char *line, char *keyword, int full)
{
- char *line2, *l2;
- int l = strlen(keyword);
- char *p1, *p2;
+ char *line2, *l2, *p1, *p2;
+ int l;
if(line == NULL || keyword == NULL) {
return NULL;
}
+
if(full != 0) {
full = 1;
}
l2++;
}
+ l = strlen(keyword);
p1 = line - 1;
p2 = strchr(line, ',');
do {
diff --git a/src/varnish.c b/src/varnish.c
index 65562d323a91bc01da44feeee3c2056a461c17e5..95303bec9bb328c1e8b8c84e3437dd286472d047 100644 (file)
--- a/src/varnish.c
+++ b/src/varnish.c
return (varnish_submit (plugin_instance, category, type, type_instance, value));
} /* }}} int varnish_submit_derive */
+#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
+static int varnish_monitor (void *priv, const struct VSC_point * const pt) /* {{{ */
+{
+ uint64_t val;
+ const user_config_t *conf;
+ const char *class;
+ const char *name;
+
+ if (pt == NULL)
+ return (0);
+
+ conf = priv;
+
+#if HAVE_VARNISH_V4
+ class = pt->section->fantom->type;
+ name = pt->desc->name;
+
+ if (strcmp(class, "MAIN") != 0)
+ return (0);
+
+#elif HAVE_VARNISH_V3
+ class = pt->class;
+ name = pt->name;
+
+ if (strcmp(class, "") != 0)
+ return (0);
+#endif
+
+ val = *(const volatile uint64_t*) pt->ptr;
+
+ if (conf->collect_cache)
+ {
+ if (strcmp(name, "cache_hit") == 0)
+ return varnish_submit_derive (conf->instance, "cache", "cache_result", "hit", val);
+ else if (strcmp(name, "cache_miss") == 0)
+ return varnish_submit_derive (conf->instance, "cache", "cache_result", "miss", val);
+ else if (strcmp(name, "cache_hitpass") == 0)
+ return varnish_submit_derive (conf->instance, "cache", "cache_result", "hitpass", val);
+ }
+
+ if (conf->collect_connections)
+ {
+ if (strcmp(name, "client_conn") == 0)
+ return varnish_submit_derive (conf->instance, "connections", "connections", "accepted", val);
+ else if (strcmp(name, "client_drop") == 0)
+ return varnish_submit_derive (conf->instance, "connections", "connections", "dropped" , val);
+ else if (strcmp(name, "client_req") == 0)
+ return varnish_submit_derive (conf->instance, "connections", "connections", "received", val);
+ }
+
+#ifdef HAVE_VARNISH_V3
+ if (conf->collect_dirdns)
+ {
+ if (strcmp(name, "dir_dns_lookups") == 0)
+ return varnish_submit_derive (conf->instance, "dirdns", "cache_operation", "lookups", val);
+ else if (strcmp(name, "dir_dns_failed") == 0)
+ return varnish_submit_derive (conf->instance, "dirdns", "cache_result", "failed", val);
+ else if (strcmp(name, "dir_dns_hit") == 0)
+ return varnish_submit_derive (conf->instance, "dirdns", "cache_result", "hits", val);
+ else if (strcmp(name, "dir_dns_cache_full") == 0)
+ return varnish_submit_derive (conf->instance, "dirdns", "cache_result", "cache_full", val);
+ }
+#endif
+
+ if (conf->collect_esi)
+ {
+ if (strcmp(name, "esi_errors") == 0)
+ return varnish_submit_derive (conf->instance, "esi", "total_operations", "error", val);
+ else if (strcmp(name, "esi_parse") == 0)
+ return varnish_submit_derive (conf->instance, "esi", "total_operations", "parsed", val);
+ else if (strcmp(name, "esi_warnings") == 0)
+ return varnish_submit_derive (conf->instance, "esi", "total_operations", "warning", val);
+ }
+
+ if (conf->collect_backend)
+ {
+ if (strcmp(name, "backend_conn") == 0)
+ return varnish_submit_derive (conf->instance, "backend", "connections", "success", val);
+ else if (strcmp(name, "backend_unhealthy") == 0)
+ return varnish_submit_derive (conf->instance, "backend", "connections", "not-attempted", val);
+ else if (strcmp(name, "backend_busy") == 0)
+ return varnish_submit_derive (conf->instance, "backend", "connections", "too-many", val);
+ else if (strcmp(name, "backend_fail") == 0)
+ return varnish_submit_derive (conf->instance, "backend", "connections", "failures", val);
+ else if (strcmp(name, "backend_reuse") == 0)
+ return varnish_submit_derive (conf->instance, "backend", "connections", "reuses", val);
+ else if (strcmp(name, "backend_toolate") == 0)
+ return varnish_submit_derive (conf->instance, "backend", "connections", "was-closed", val);
+ else if (strcmp(name, "backend_recycle") == 0)
+ return varnish_submit_derive (conf->instance, "backend", "connections", "recycled", val);
+ else if (strcmp(name, "backend_unused") == 0)
+ return varnish_submit_derive (conf->instance, "backend", "connections", "unused", val);
+ else if (strcmp(name, "backend_retry") == 0)
+ return varnish_submit_derive (conf->instance, "backend", "connections", "retries", val);
+ else if (strcmp(name, "backend_req") == 0)
+ return varnish_submit_derive (conf->instance, "backend", "http_requests", "requests", val);
+ else if (strcmp(name, "n_backend") == 0)
+ return varnish_submit_gauge (conf->instance, "backend", "backends", "n_backends", val);
+ }
+
+ if (conf->collect_fetch)
+ {
+ if (strcmp(name, "fetch_head") == 0)
+ return varnish_submit_derive (conf->instance, "fetch", "http_requests", "head", val);
+ else if (strcmp(name, "fetch_length") == 0)
+ return varnish_submit_derive (conf->instance, "fetch", "http_requests", "length", val);
+ else if (strcmp(name, "fetch_chunked") == 0)
+ return varnish_submit_derive (conf->instance, "fetch", "http_requests", "chunked", val);
+ else if (strcmp(name, "fetch_eof") == 0)
+ return varnish_submit_derive (conf->instance, "fetch", "http_requests", "eof", val);
+ else if (strcmp(name, "fetch_bad") == 0)
+ return varnish_submit_derive (conf->instance, "fetch", "http_requests", "bad_headers", val);
+ else if (strcmp(name, "fetch_close") == 0)
+ return varnish_submit_derive (conf->instance, "fetch", "http_requests", "close", val);
+ else if (strcmp(name, "fetch_oldhttp") == 0)
+ return varnish_submit_derive (conf->instance, "fetch", "http_requests", "oldhttp", val);
+ else if (strcmp(name, "fetch_zero") == 0)
+ return varnish_submit_derive (conf->instance, "fetch", "http_requests", "zero", val);
+ else if (strcmp(name, "fetch_failed") == 0)
+ return varnish_submit_derive (conf->instance, "fetch", "http_requests", "failed", val);
+ else if (strcmp(name, "fetch_1xx") == 0)
+ return varnish_submit_derive (conf->instance, "fetch", "http_requests", "no_body_1xx", val);
+ else if (strcmp(name, "fetch_204") == 0)
+ return varnish_submit_derive (conf->instance, "fetch", "http_requests", "no_body_204", val);
+ else if (strcmp(name, "fetch_304") == 0)
+ return varnish_submit_derive (conf->instance, "fetch", "http_requests", "no_body_304", val);
+ }
+
+ if (conf->collect_hcb)
+ {
+ if (strcmp(name, "hcb_nolock") == 0)
+ return varnish_submit_derive (conf->instance, "hcb", "cache_operation", "lookup_nolock", val);
+ else if (strcmp(name, "hcb_lock") == 0)
+ return varnish_submit_derive (conf->instance, "hcb", "cache_operation", "lookup_lock", val);
+ else if (strcmp(name, "hcb_insert") == 0)
+ return varnish_submit_derive (conf->instance, "hcb", "cache_operation", "insert", val);
+ }
+
+ if (conf->collect_objects)
+ {
+ if (strcmp(name, "n_expired") == 0)
+ return varnish_submit_derive (conf->instance, "objects", "total_objects", "expired", val);
+ else if (strcmp(name, "n_lru_nuked") == 0)
+ return varnish_submit_derive (conf->instance, "objects", "total_objects", "lru_nuked", val);
+ else if (strcmp(name, "n_lru_saved") == 0)
+ return varnish_submit_derive (conf->instance, "objects", "total_objects", "lru_saved", val);
+ else if (strcmp(name, "n_lru_moved") == 0)
+ return varnish_submit_derive (conf->instance, "objects", "total_objects", "lru_moved", val);
+ else if (strcmp(name, "n_deathrow") == 0)
+ return varnish_submit_derive (conf->instance, "objects", "total_objects", "deathrow", val);
+ else if (strcmp(name, "losthdr") == 0)
+ return varnish_submit_derive (conf->instance, "objects", "total_objects", "header_overflow", val);
+ else if (strcmp(name, "n_obj_purged") == 0)
+ return varnish_submit_derive (conf->instance, "objects", "total_objects", "purged", val);
+ else if (strcmp(name, "n_objsendfile") == 0)
+ return varnish_submit_derive (conf->instance, "objects", "total_objects", "sent_sendfile", val);
+ else if (strcmp(name, "n_objwrite") == 0)
+ return varnish_submit_derive (conf->instance, "objects", "total_objects", "sent_write", val);
+ else if (strcmp(name, "n_objoverflow") == 0)
+ return varnish_submit_derive (conf->instance, "objects", "total_objects", "workspace_overflow", val);
+ }
+
+#if HAVE_VARNISH_V3
+ if (conf->collect_ban)
+ {
+ if (strcmp(name, "n_ban") == 0)
+ return varnish_submit_derive (conf->instance, "ban", "total_operations", "total", val);
+ else if (strcmp(name, "n_ban_add") == 0)
+ return varnish_submit_derive (conf->instance, "ban", "total_operations", "added", val);
+ else if (strcmp(name, "n_ban_retire") == 0)
+ return varnish_submit_derive (conf->instance, "ban", "total_operations", "deleted", val);
+ else if (strcmp(name, "n_ban_obj_test") == 0)
+ return varnish_submit_derive (conf->instance, "ban", "total_operations", "objects_tested", val);
+ else if (strcmp(name, "n_ban_re_test") == 0)
+ return varnish_submit_derive (conf->instance, "ban", "total_operations", "regexps_tested", val);
+ else if (strcmp(name, "n_ban_dups") == 0)
+ return varnish_submit_derive (conf->instance, "ban", "total_operations", "duplicate", val);
+ }
+#endif
+#if HAVE_VARNISH_V4
+ if (conf->collect_ban)
+ {
+ if (strcmp(name, "bans") == 0)
+ return varnish_submit_derive (conf->instance, "ban", "total_operations", "total", val);
+ else if (strcmp(name, "bans_added") == 0)
+ return varnish_submit_derive (conf->instance, "ban", "total_operations", "added", val);
+ else if (strcmp(name, "bans_obj") == 0)
+ return varnish_submit_derive (conf->instance, "ban", "total_operations", "obj", val);
+ else if (strcmp(name, "bans_req") == 0)
+ return varnish_submit_derive (conf->instance, "ban", "total_operations", "req", val);
+ else if (strcmp(name, "bans_completed") == 0)
+ return varnish_submit_derive (conf->instance, "ban", "total_operations", "completed", val);
+ else if (strcmp(name, "bans_deleted") == 0)
+ return varnish_submit_derive (conf->instance, "ban", "total_operations", "deleted", val);
+ else if (strcmp(name, "bans_tested") == 0)
+ return varnish_submit_derive (conf->instance, "ban", "total_operations", "tested", val);
+ else if (strcmp(name, "bans_dups") == 0)
+ return varnish_submit_derive (conf->instance, "ban", "total_operations", "duplicate", val);
+ }
+#endif
+
+ if (conf->collect_session)
+ {
+ if (strcmp(name, "sess_closed") == 0)
+ return varnish_submit_derive (conf->instance, "session", "total_operations", "closed", val);
+ else if (strcmp(name, "sess_pipeline") == 0)
+ return varnish_submit_derive (conf->instance, "session", "total_operations", "pipeline", val);
+ else if (strcmp(name, "sess_readahead") == 0)
+ return varnish_submit_derive (conf->instance, "session", "total_operations", "readahead", val);
+ else if (strcmp(name, "sess_conn") == 0)
+ return varnish_submit_derive (conf->instance, "session", "total_operations", "accepted", val);
+ else if (strcmp(name, "sess_drop") == 0)
+ return varnish_submit_derive (conf->instance, "session", "total_operations", "dropped", val);
+ else if (strcmp(name, "sess_fail") == 0)
+ return varnish_submit_derive (conf->instance, "session", "total_operations", "failed", val);
+ else if (strcmp(name, "sess_pipe_overflow") == 0)
+ return varnish_submit_derive (conf->instance, "session", "total_operations", "overflow", val);
+ else if (strcmp(name, "sess_queued") == 0)
+ return varnish_submit_derive (conf->instance, "session", "total_operations", "queued", val);
+ else if (strcmp(name, "sess_linger") == 0)
+ return varnish_submit_derive (conf->instance, "session", "total_operations", "linger", val);
+ else if (strcmp(name, "sess_herd") == 0)
+ return varnish_submit_derive (conf->instance, "session", "total_operations", "herd", val);
+ }
+
+ if (conf->collect_shm)
+ {
+ if (strcmp(name, "shm_records") == 0)
+ return varnish_submit_derive (conf->instance, "shm", "total_operations", "records", val);
+ else if (strcmp(name, "shm_writes") == 0)
+ return varnish_submit_derive (conf->instance, "shm", "total_operations", "writes", val);
+ else if (strcmp(name, "shm_flushes") == 0)
+ return varnish_submit_derive (conf->instance, "shm", "total_operations", "flushes", val);
+ else if (strcmp(name, "shm_cont") == 0)
+ return varnish_submit_derive (conf->instance, "shm", "total_operations", "contention", val);
+ else if (strcmp(name, "shm_cycles") == 0)
+ return varnish_submit_derive (conf->instance, "shm", "total_operations", "cycles", val);
+ }
+
+ if (conf->collect_sms)
+ {
+ if (strcmp(name, "sms_nreq") == 0)
+ return varnish_submit_derive (conf->instance, "sms", "total_requests", "allocator", val);
+ else if (strcmp(name, "sms_nobj") == 0)
+ return varnish_submit_gauge (conf->instance, "sms", "requests", "outstanding", val);
+ else if (strcmp(name, "sms_nbytes") == 0)
+ return varnish_submit_gauge (conf->instance, "sms", "bytes", "outstanding", val);
+ else if (strcmp(name, "sms_balloc") == 0)
+ return varnish_submit_derive (conf->instance, "sms", "total_bytes", "allocated", val);
+ else if (strcmp(name, "sms_bfree") == 0)
+ return varnish_submit_derive (conf->instance, "sms", "total_bytes", "free", val);
+ }
+
+ if (conf->collect_struct)
+ {
+ if (strcmp(name, "n_sess_mem") == 0)
+ return varnish_submit_gauge (conf->instance, "struct", "current_sessions", "sess_mem", val);
+ else if (strcmp(name, "n_sess") == 0)
+ return varnish_submit_gauge (conf->instance, "struct", "current_sessions", "sess", val);
+ else if (strcmp(name, "n_object") == 0)
+ return varnish_submit_gauge (conf->instance, "struct", "objects", "object", val);
+ else if (strcmp(name, "n_vampireobject") == 0)
+ return varnish_submit_gauge (conf->instance, "struct", "objects", "vampireobject", val);
+ else if (strcmp(name, "n_objectcore") == 0)
+ return varnish_submit_gauge (conf->instance, "struct", "objects", "objectcore", val);
+ else if (strcmp(name, "n_waitinglist") == 0)
+ return varnish_submit_gauge (conf->instance, "struct", "objects", "waitinglist", val);
+ else if (strcmp(name, "n_objecthead") == 0)
+ return varnish_submit_gauge (conf->instance, "struct", "objects", "objecthead", val);
+ else if (strcmp(name, "n_smf") == 0)
+ return varnish_submit_gauge (conf->instance, "struct", "objects", "smf", val);
+ else if (strcmp(name, "n_smf_frag") == 0)
+ return varnish_submit_gauge (conf->instance, "struct", "objects", "smf_frag", val);
+ else if (strcmp(name, "n_smf_large") == 0)
+ return varnish_submit_gauge (conf->instance, "struct", "objects", "smf_large", val);
+ else if (strcmp(name, "n_vbe_conn") == 0)
+ return varnish_submit_gauge (conf->instance, "struct", "objects", "vbe_conn", val);
+ }
+
+ if (conf->collect_totals)
+ {
+ if (strcmp(name, "s_sess") == 0)
+ return varnish_submit_derive (conf->instance, "totals", "total_sessions", "sessions", val);
+ else if (strcmp(name, "s_req") == 0)
+ return varnish_submit_derive (conf->instance, "totals", "total_requests", "requests", val);
+ else if (strcmp(name, "s_pipe") == 0)
+ return varnish_submit_derive (conf->instance, "totals", "total_operations", "pipe", val);
+ else if (strcmp(name, "s_pass") == 0)
+ return varnish_submit_derive (conf->instance, "totals", "total_operations", "pass", val);
+ else if (strcmp(name, "s_fetch") == 0)
+ return varnish_submit_derive (conf->instance, "totals", "total_operations", "fetches", val);
+ else if (strcmp(name, "s_synth") == 0)
+ return varnish_submit_derive (conf->instance, "totals", "total_bytes", "synth", val);
+ else if (strcmp(name, "s_req_hdrbytes") == 0)
+ return varnish_submit_derive (conf->instance, "totals", "total_bytes", "req_header", val);
+ else if (strcmp(name, "s_req_bodybytes") == 0)
+ return varnish_submit_derive (conf->instance, "totals", "total_bytes", "req_body", val);
+ else if (strcmp(name, "s_resp_hdrbytes") == 0)
+ return varnish_submit_derive (conf->instance, "totals", "total_bytes", "resp_header", val);
+ else if (strcmp(name, "s_resp_bodybytes") == 0)
+ return varnish_submit_derive (conf->instance, "totals", "total_bytes", "resp_body", val);
+ else if (strcmp(name, "s_pipe_hdrbytes") == 0)
+ return varnish_submit_derive (conf->instance, "totals", "total_bytes", "pipe_header", val);
+ else if (strcmp(name, "s_pipe_in") == 0)
+ return varnish_submit_derive (conf->instance, "totals", "total_bytes", "pipe_in", val);
+ else if (strcmp(name, "s_pipe_out") == 0)
+ return varnish_submit_derive (conf->instance, "totals", "total_bytes", "pipe_out", val);
+ else if (strcmp(name, "n_purges") == 0)
+ return varnish_submit_derive (conf->instance, "totals", "total_operations", "purges", val);
+ else if (strcmp(name, "s_hdrbytes") == 0)
+ return varnish_submit_derive (conf->instance, "totals", "total_bytes", "header-bytes", val);
+ else if (strcmp(name, "s_bodybytes") == 0)
+ return varnish_submit_derive (conf->instance, "totals", "total_bytes", "body-bytes", val);
+ else if (strcmp(name, "n_gzip") == 0)
+ return varnish_submit_derive (conf->instance, "totals", "total_operations", "gzip", val);
+ else if (strcmp(name, "n_gunzip") == 0)
+ return varnish_submit_derive (conf->instance, "totals", "total_operations", "gunzip", val);
+ }
+
+ if (conf->collect_uptime)
+ {
+ if (strcmp(name, "uptime") == 0)
+ return varnish_submit_gauge (conf->instance, "uptime", "uptime", "client_uptime", val);
+ }
+
+ if (conf->collect_vcl)
+ {
+ if (strcmp(name, "n_vcl") == 0)
+ return varnish_submit_gauge (conf->instance, "vcl", "vcl", "total_vcl", val);
+ else if (strcmp(name, "n_vcl_avail") == 0)
+ return varnish_submit_gauge (conf->instance, "vcl", "vcl", "avail_vcl", val);
+ else if (strcmp(name, "n_vcl_discard") == 0)
+ return varnish_submit_gauge (conf->instance, "vcl", "vcl", "discarded_vcl", val);
+ else if (strcmp(name, "vmods") == 0)
+ return varnish_submit_gauge (conf->instance, "vcl", "objects", "vmod", val);
+ }
+
+ if (conf->collect_workers)
+ {
+ if (strcmp(name, "threads") == 0)
+ return varnish_submit_gauge (conf->instance, "workers", "threads", "worker", val);
+ else if (strcmp(name, "threads_created") == 0)
+ return varnish_submit_derive (conf->instance, "workers", "total_threads", "created", val);
+ else if (strcmp(name, "threads_failed") == 0)
+ return varnish_submit_derive (conf->instance, "workers", "total_threads", "failed", val);
+ else if (strcmp(name, "threads_limited") == 0)
+ return varnish_submit_derive (conf->instance, "workers", "total_threads", "limited", val);
+ else if (strcmp(name, "threads_destroyed") == 0)
+ return varnish_submit_derive (conf->instance, "workers", "total_threads", "dropped", val);
+ else if (strcmp(name, "thread_queue_len") == 0)
+ return varnish_submit_derive (conf->instance, "workers", "queue_length", "threads", val);
+ else if (strcmp(name, "n_wrk") == 0)
+ return varnish_submit_gauge (conf->instance, "workers", "threads", "worker", val);
+ else if (strcmp(name, "n_wrk_create") == 0)
+ return varnish_submit_derive (conf->instance, "workers", "total_threads", "created", val);
+ else if (strcmp(name, "n_wrk_failed") == 0)
+ return varnish_submit_derive (conf->instance, "workers", "total_threads", "failed", val);
+ else if (strcmp(name, "n_wrk_max") == 0)
+ return varnish_submit_derive (conf->instance, "workers", "total_threads", "limited", val);
+ else if (strcmp(name, "n_wrk_drop") == 0)
+ return varnish_submit_derive (conf->instance, "workers", "total_threads", "dropped", val);
+ else if (strcmp(name, "n_wrk_queue") == 0)
+ return varnish_submit_derive (conf->instance, "workers", "total_requests", "queued", val);
+ else if (strcmp(name, "n_wrk_overflow") == 0)
+ return varnish_submit_derive (conf->instance, "workers", "total_requests", "overflowed", val);
+ else if (strcmp(name, "n_wrk_queued") == 0)
+ return varnish_submit_derive (conf->instance, "workers", "total_requests", "queued", val);
+ else if (strcmp(name, "n_wrk_lqueue") == 0)
+ return varnish_submit_derive (conf->instance, "workers", "total_requests", "queue_length", val);
+ }
+
+#if HAVE_VARNISH_V4
+ if (conf->collect_vsm)
+ {
+ if (strcmp(name, "vsm_free") == 0)
+ return varnish_submit_gauge (conf->instance, "vsm", "bytes", "free", val);
+ else if (strcmp(name, "vsm_used") == 0)
+ return varnish_submit_gauge (conf->instance, "vsm", "bytes", "used", val);
+ else if (strcmp(name, "vsm_cooling") == 0)
+ return varnish_submit_gauge (conf->instance, "vsm", "bytes", "cooling", val);
+ else if (strcmp(name, "vsm_overflow") == 0)
+ return varnish_submit_gauge (conf->instance, "vsm", "bytes", "overflow", val);
+ else if (strcmp(name, "vsm_overflowed") == 0)
+ return varnish_submit_derive (conf->instance, "vsm", "total_bytes", "overflowed", val);
+ }
+#endif
+
+ return (0);
+
+} /* }}} static int varnish_monitor */
+#else /* if HAVE_VARNISH_V2 */
static void varnish_monitor (const user_config_t *conf, /* {{{ */
const c_varnish_stats_t *stats)
{
if (conf->collect_connections)
{
-#ifndef HAVE_VARNISH_V4
/* Client connections accepted */
varnish_submit_derive (conf->instance, "connections", "connections", "accepted", stats->client_conn);
/* Connection dropped, no sess */
varnish_submit_derive (conf->instance, "connections", "connections", "dropped" , stats->client_drop);
-#endif
/* Client requests received */
varnish_submit_derive (conf->instance, "connections", "connections", "received", stats->client_req);
}
-#ifdef HAVE_VARNISH_V3
- if (conf->collect_dirdns)
- {
- /* DNS director lookups */
- varnish_submit_derive (conf->instance, "dirdns", "cache_operation", "lookups", stats->dir_dns_lookups);
- /* DNS director failed lookups */
- varnish_submit_derive (conf->instance, "dirdns", "cache_result", "failed", stats->dir_dns_failed);
- /* DNS director cached lookups hit */
- varnish_submit_derive (conf->instance, "dirdns", "cache_result", "hits", stats->dir_dns_hit);
- /* DNS director full dnscache */
- varnish_submit_derive (conf->instance, "dirdns", "cache_result", "cache_full", stats->dir_dns_cache_full);
- }
-#endif
-
if (conf->collect_esi)
{
/* ESI parse errors (unlock) */
varnish_submit_derive (conf->instance, "esi", "total_operations", "error", stats->esi_errors);
-#if HAVE_VARNISH_V2
/* Objects ESI parsed (unlock) */
varnish_submit_derive (conf->instance, "esi", "total_operations", "parsed", stats->esi_parse);
-#else
- /* ESI parse warnings (unlock) */
- varnish_submit_derive (conf->instance, "esi", "total_operations", "warning", stats->esi_warnings);
-#endif
}
if (conf->collect_backend)
varnish_submit_derive (conf->instance, "backend", "connections", "was-closed" , stats->backend_toolate);
/* Backend conn. recycles */
varnish_submit_derive (conf->instance, "backend", "connections", "recycled" , stats->backend_recycle);
-#if HAVE_VARNISH_V2
/* Backend conn. unused */
varnish_submit_derive (conf->instance, "backend", "connections", "unused" , stats->backend_unused);
-#else
- /* Backend conn. retry */
- varnish_submit_derive (conf->instance, "backend", "connections", "retries" , stats->backend_retry);
-#endif
/* Backend requests mades */
varnish_submit_derive (conf->instance, "backend", "http_requests", "requests" , stats->backend_req);
/* N backends */
varnish_submit_derive (conf->instance, "fetch", "http_requests", "zero" , stats->fetch_zero);
/* Fetch failed */
varnish_submit_derive (conf->instance, "fetch", "http_requests", "failed" , stats->fetch_failed);
-#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
- /* Fetch no body (1xx) */
- varnish_submit_derive (conf->instance, "fetch", "http_requests", "no_body_1xx", stats->fetch_1xx);
- /* Fetch no body (204) */
- varnish_submit_derive (conf->instance, "fetch", "http_requests", "no_body_204", stats->fetch_204);
- /* Fetch no body (304) */
- varnish_submit_derive (conf->instance, "fetch", "http_requests", "no_body_304", stats->fetch_304);
-#endif
}
if (conf->collect_hcb)
varnish_submit_derive (conf->instance, "objects", "total_objects", "expired", stats->n_expired);
/* N LRU nuked objects */
varnish_submit_derive (conf->instance, "objects", "total_objects", "lru_nuked", stats->n_lru_nuked);
-#if HAVE_VARNISH_V2
/* N LRU saved objects */
varnish_submit_derive (conf->instance, "objects", "total_objects", "lru_saved", stats->n_lru_saved);
-#endif
/* N LRU moved objects */
varnish_submit_derive (conf->instance, "objects", "total_objects", "lru_moved", stats->n_lru_moved);
-#if HAVE_VARNISH_V2
/* N objects on deathrow */
varnish_submit_derive (conf->instance, "objects", "total_objects", "deathrow", stats->n_deathrow);
-#endif
/* HTTP header overflows */
varnish_submit_derive (conf->instance, "objects", "total_objects", "header_overflow", stats->losthdr);
-#if HAVE_VARNISH_V4
- /* N purged objects */
- varnish_submit_derive (conf->instance, "objects", "total_objects", "purged", stats->n_obj_purged);
-#else
/* Objects sent with sendfile */
varnish_submit_derive (conf->instance, "objects", "total_objects", "sent_sendfile", stats->n_objsendfile);
/* Objects sent with write */
varnish_submit_derive (conf->instance, "objects", "total_objects", "sent_write", stats->n_objwrite);
/* Objects overflowing workspace */
varnish_submit_derive (conf->instance, "objects", "total_objects", "workspace_overflow", stats->n_objoverflow);
-#endif
}
-#if HAVE_VARNISH_V2
if (conf->collect_purge)
{
/* N total active purges */
/* N duplicate purges removed */
varnish_submit_derive (conf->instance, "purge", "total_operations", "duplicate", stats->n_purge_dups);
}
-#endif
-#if HAVE_VARNISH_V3
- if (conf->collect_ban)
- {
- /* N total active bans */
- varnish_submit_derive (conf->instance, "ban", "total_operations", "total", stats->n_ban);
- /* N new bans added */
- varnish_submit_derive (conf->instance, "ban", "total_operations", "added", stats->n_ban_add);
- /* N old bans deleted */
- varnish_submit_derive (conf->instance, "ban", "total_operations", "deleted", stats->n_ban_retire);
- /* N objects tested */
- varnish_submit_derive (conf->instance, "ban", "total_operations", "objects_tested", stats->n_ban_obj_test);
- /* N regexps tested against */
- varnish_submit_derive (conf->instance, "ban", "total_operations", "regexps_tested", stats->n_ban_re_test);
- /* N duplicate bans removed */
- varnish_submit_derive (conf->instance, "ban", "total_operations", "duplicate", stats->n_ban_dups);
- }
-#endif
-#if HAVE_VARNISH_V4
- if (conf->collect_ban)
- {
- /* N total active bans */
- varnish_submit_derive (conf->instance, "ban", "total_operations", "total", stats->bans);
- /* N new bans added */
- varnish_submit_derive (conf->instance, "ban", "total_operations", "added", stats->bans_added);
- /* N bans using obj */
- varnish_submit_derive (conf->instance, "ban", "total_operations", "obj", stats->bans_obj);
- /* N bans using req */
- varnish_submit_derive (conf->instance, "ban", "total_operations", "req", stats->bans_req);
- /* N new bans completed */
- varnish_submit_derive (conf->instance, "ban", "total_operations", "completed", stats->bans_completed);
- /* N old bans deleted */
- varnish_submit_derive (conf->instance, "ban", "total_operations", "deleted", stats->bans_deleted);
- /* N objects tested */
- varnish_submit_derive (conf->instance, "ban", "total_operations", "tested", stats->bans_tested);
- /* N duplicate bans removed */
- varnish_submit_derive (conf->instance, "ban", "total_operations", "duplicate", stats->bans_dups);
- }
-#endif
if (conf->collect_session)
{
varnish_submit_derive (conf->instance, "session", "total_operations", "pipeline", stats->sess_pipeline);
/* Session Read Ahead */
varnish_submit_derive (conf->instance, "session", "total_operations", "readahead", stats->sess_readahead);
-#if HAVE_VARNISH_V4
- /* Sessions accepted */
- varnish_submit_derive (conf->instance, "session", "total_operations", "accepted", stats->sess_conn);
- /* Sessions dropped for thread */
- varnish_submit_derive (conf->instance, "session", "total_operations", "dropped", stats->sess_drop);
- /* Sessions accept failure */
- varnish_submit_derive (conf->instance, "session", "total_operations", "failed", stats->sess_fail);
- /* Sessions pipe overflow */
- varnish_submit_derive (conf->instance, "session", "total_operations", "overflow", stats->sess_pipe_overflow);
- /* Sessions queued for thread */
- varnish_submit_derive (conf->instance, "session", "total_operations", "queued", stats->sess_queued);
-#else
/* Session Linger */
varnish_submit_derive (conf->instance, "session", "total_operations", "linger", stats->sess_linger);
-#endif
/* Session herd */
varnish_submit_derive (conf->instance, "session", "total_operations", "herd", stats->sess_herd);
}
varnish_submit_derive (conf->instance, "shm", "total_operations", "cycles" , stats->shm_cycles);
}
-#if HAVE_VARNISH_V2
if (conf->collect_sm)
{
/* allocator requests */
/* SMA bytes free */
varnish_submit_derive (conf->instance, "sma", "total_bytes", "free" , stats->sma_bfree);
}
-#endif
if (conf->collect_sms)
{
if (conf->collect_struct)
{
-#if !HAVE_VARNISH_V4
/* N struct sess_mem */
varnish_submit_gauge (conf->instance, "struct", "current_sessions", "sess_mem", stats->n_sess_mem);
/* N struct sess */
varnish_submit_gauge (conf->instance, "struct", "current_sessions", "sess", stats->n_sess);
-#endif
/* N struct object */
varnish_submit_gauge (conf->instance, "struct", "objects", "object", stats->n_object);
-#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
- /* N unresurrected objects */
- varnish_submit_gauge (conf->instance, "struct", "objects", "vampireobject", stats->n_vampireobject);
- /* N struct objectcore */
- varnish_submit_gauge (conf->instance, "struct", "objects", "objectcore", stats->n_objectcore);
- /* N struct waitinglist */
- varnish_submit_gauge (conf->instance, "struct", "objects", "waitinglist", stats->n_waitinglist);
-#endif
/* N struct objecthead */
varnish_submit_gauge (conf->instance, "struct", "objects", "objecthead", stats->n_objecthead);
-#ifdef HAVE_VARNISH_V2
/* N struct smf */
varnish_submit_gauge (conf->instance, "struct", "objects", "smf", stats->n_smf);
/* N small free smf */
varnish_submit_gauge (conf->instance, "struct", "objects", "smf_large", stats->n_smf_large);
/* N struct vbe_conn */
varnish_submit_gauge (conf->instance, "struct", "objects", "vbe_conn", stats->n_vbe_conn);
-#endif
}
if (conf->collect_totals)
varnish_submit_derive (conf->instance, "totals", "total_operations", "pass", stats->s_pass);
/* Total fetch */
varnish_submit_derive (conf->instance, "totals", "total_operations", "fetches", stats->s_fetch);
-#if HAVE_VARNISH_V4
- /* Total synth */
- varnish_submit_derive (conf->instance, "totals", "total_bytes", "synth", stats->s_synth);
- /* Request header bytes */
- varnish_submit_derive (conf->instance, "totals", "total_bytes", "req_header", stats->s_req_hdrbytes);
- /* Request body byte */
- varnish_submit_derive (conf->instance, "totals", "total_bytes", "req_body", stats->s_req_bodybytes);
- /* Response header bytes */
- varnish_submit_derive (conf->instance, "totals", "total_bytes", "resp_header", stats->s_resp_hdrbytes);
- /* Response body byte */
- varnish_submit_derive (conf->instance, "totals", "total_bytes", "resp_body", stats->s_resp_bodybytes);
- /* Pipe request header bytes */
- varnish_submit_derive (conf->instance, "totals", "total_bytes", "pipe_header", stats->s_pipe_hdrbytes);
- /* Piped bytes from client */
- varnish_submit_derive (conf->instance, "totals", "total_bytes", "pipe_in", stats->s_pipe_in);
- /* Piped bytes to client */
- varnish_submit_derive (conf->instance, "totals", "total_bytes", "pipe_out", stats->s_pipe_out);
- /* Number of purge operations */
- varnish_submit_derive (conf->instance, "totals", "total_operations", "purges", stats->n_purges);
-#else
/* Total header bytes */
varnish_submit_derive (conf->instance, "totals", "total_bytes", "header-bytes", stats->s_hdrbytes);
/* Total body byte */
varnish_submit_derive (conf->instance, "totals", "total_bytes", "body-bytes", stats->s_bodybytes);
-#endif
-#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
- /* Gzip operations */
- varnish_submit_derive (conf->instance, "totals", "total_operations", "gzip", stats->n_gzip);
- /* Gunzip operations */
- varnish_submit_derive (conf->instance, "totals", "total_operations", "gunzip", stats->n_gunzip);
-#endif
}
-#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
- if (conf->collect_uptime)
- {
- /* Client uptime */
- varnish_submit_gauge (conf->instance, "uptime", "uptime", "client_uptime", stats->uptime);
- }
-#endif
-
if (conf->collect_vcl)
{
/* N vcl total */
varnish_submit_gauge (conf->instance, "vcl", "vcl", "avail_vcl", stats->n_vcl_avail);
/* N vcl discarded */
varnish_submit_gauge (conf->instance, "vcl", "vcl", "discarded_vcl", stats->n_vcl_discard);
-#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
- /* Loaded VMODs */
- varnish_submit_gauge (conf->instance, "vcl", "objects", "vmod", stats->vmods);
-#endif
}
if (conf->collect_workers)
{
-#ifdef HAVE_VARNISH_V4
- /* total number of threads */
- varnish_submit_gauge (conf->instance, "workers", "threads", "worker", stats->threads);
- /* threads created */
- varnish_submit_derive (conf->instance, "workers", "total_threads", "created", stats->threads_created);
- /* thread creation failed */
- varnish_submit_derive (conf->instance, "workers", "total_threads", "failed", stats->threads_failed);
- /* threads hit max */
- varnish_submit_derive (conf->instance, "workers", "total_threads", "limited", stats->threads_limited);
- /* threads destroyed */
- varnish_submit_derive (conf->instance, "workers", "total_threads", "dropped", stats->threads_destroyed);
- /* length of session queue */
- varnish_submit_derive (conf->instance, "workers", "queue_length", "threads", stats->thread_queue_len);
-#else
/* worker threads */
varnish_submit_gauge (conf->instance, "workers", "threads", "worker", stats->n_wrk);
/* worker threads created */
varnish_submit_derive (conf->instance, "workers", "total_threads", "limited", stats->n_wrk_max);
/* dropped work requests */
varnish_submit_derive (conf->instance, "workers", "total_threads", "dropped", stats->n_wrk_drop);
-#ifdef HAVE_VARNISH_V2
/* queued work requests */
varnish_submit_derive (conf->instance, "workers", "total_requests", "queued", stats->n_wrk_queue);
/* overflowed work requests */
varnish_submit_derive (conf->instance, "workers", "total_requests", "overflowed", stats->n_wrk_overflow);
-#else /* HAVE_VARNISH_V3 */
- /* queued work requests */
- varnish_submit_derive (conf->instance, "workers", "total_requests", "queued", stats->n_wrk_queued);
- /* work request queue length */
- varnish_submit_derive (conf->instance, "workers", "total_requests", "queue_length", stats->n_wrk_lqueue);
-#endif
-#endif
}
-#if HAVE_VARNISH_V4
- if (conf->collect_vsm)
- {
- /* Free VSM space */
- varnish_submit_gauge (conf->instance, "vsm", "bytes", "free", stats->vsm_free);
- /* Used VSM space */
- varnish_submit_gauge (conf->instance, "vsm", "bytes", "used", stats->vsm_used);
- /* Cooling VSM space */
- varnish_submit_gauge (conf->instance, "vsm", "bytes", "cooling", stats->vsm_cooling);
- /* Overflow VSM space */
- varnish_submit_gauge (conf->instance, "vsm", "bytes", "overflow", stats->vsm_overflow);
- /* Total overflowed VSM space */
- varnish_submit_derive (conf->instance, "vsm", "total_bytes", "overflowed", stats->vsm_overflowed);
- }
-#endif
-
} /* }}} void varnish_monitor */
+#endif
#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
static int varnish_read (user_data_t *ud) /* {{{ */
return (-1);
}
-
- varnish_monitor (conf, stats);
+#if HAVE_VARNISH_V3
+ VSC_Iter (vd, varnish_monitor, conf);
+#else /* if HAVE_VARNISH_V4 */
+ VSC_Iter (vd, NULL, varnish_monitor, conf);
+#endif
VSM_Delete (vd);
return (0);
diff --git a/src/vmem.c b/src/vmem.c
index 5e609e67e26fc3b108b32c7151cae023bc175289..7bb0433cb233f1865bb747d3e5d700437c9df7ca 100644 (file)
--- a/src/vmem.c
+++ b/src/vmem.c
value_t value = { .derive = counter };
submit_one (inst, "vmpage_action", "refill", value);
}
+ else if (strncmp ("pgsteal_kswapd_", key, strlen ("pgsteal_kswapd_")) == 0)
+ {
+ char *inst = key + strlen ("pgsteal_kswapd_");
+ value_t value = { .derive = counter };
+ submit_one (inst, "vmpage_action", "steal_kswapd", value);
+ }
+ else if (strncmp ("pgsteal_direct_", key, strlen ("pgsteal_direct_")) == 0)
+ {
+ char *inst = key + strlen ("pgsteal_direct_");
+ value_t value = { .derive = counter };
+ submit_one (inst, "vmpage_action", "steal_direct", value);
+ }
+ /* For backwards compatibility (somewhen before 4.2.3) */
else if (strncmp ("pgsteal_", key, strlen ("pgsteal_")) == 0)
{
char *inst = key + strlen ("pgsteal_");
diff --git a/src/write_graphite.c b/src/write_graphite.c
index 0702a6ea9e2888b68104dd6315a399d2275f50e8..6baace14410e48f72761d21d6d2db1c9fdb854ad 100644 (file)
--- a/src/write_graphite.c
+++ b/src/write_graphite.c
ssize_t status = 0;
status = swrite (cb->sock_fd, cb->send_buf, strlen (cb->send_buf));
- if (status < 0)
+ if (status != 0)
{
if (cb->log_send_errors)
{
diff --git a/src/zfs_arc.c b/src/zfs_arc.c
index dd633d5f2287352969f1619f553c105eccd7eade..2577bb017db900904894e6f5a6f1da53a6b4c1c8 100644 (file)
--- a/src/zfs_arc.c
+++ b/src/zfs_arc.c
return (-1);
}
- len = read_file_contents (ZOL_ARCSTATS_FILE, file_contents, sizeof(file_contents));
+ len = read_file_contents (ZOL_ARCSTATS_FILE, file_contents, sizeof(file_contents) - 1);
if (len > 1)
{