From: Florian Forster Date: Tue, 17 Aug 2010 16:53:29 +0000 (+0200) Subject: Merge branch 'collectd-4.9' into collectd-4.10 X-Git-Tag: collectd-4.10.2~8 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=c15dbfc3739f7c3bbd8171797eaef55749008bfa;hp=0fe0b565ea84fb2363411366905c7cfb492cd709;p=collectd.git Merge branch 'collectd-4.9' into collectd-4.10 --- diff --git a/src/collectd-perl.pod b/src/collectd-perl.pod index 56370533..5c11b652 100644 --- a/src/collectd-perl.pod +++ b/src/collectd-perl.pod @@ -4,7 +4,9 @@ collectd-perl - Documentation of collectd's C =head1 SYNOPSIS - LoadPlugin perl + + Globals true + # ... IncludeDir "/path/to/perl/plugins" @@ -25,6 +27,12 @@ for collectd in Perl. This is a lot more efficient than executing a Perl-script every time you want to read a value with the C (see L) and provides a lot more functionality, too. +When loading the C, the B option should be enabled. +Else, the perl plugin will fail to load any Perl modules implemented in C, +which includes, amongst many others, the B module used by the plugin +itself. See the documentation of the B option in L +for details. + =head1 CONFIGURATION =over 4 diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index cc448a0e..4faba997 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -57,6 +57,33 @@ directory for the daemon. Loads the plugin I. There must be at least one such line or B will be mostly useless. +Starting with collectd 4.9, this may also be a block in which further options +affecting the behavior of B may be specified. The following +options are allowed inside a B block: + + + Globals true + + +=over 4 + +=item B B + +If enabled, collectd will export all global symbols of the plugin (and of all +libraries loaded as dependencies of the plugin) and, thus, makes those symbols +available for resolving unresolved symbols in subsequently loaded plugins if +that is supported by your system. By default, this is disabled. + +This is useful (or possibly even required), e.Eg., when loading a plugin +that embeds some scripting language into the daemon (e.Eg. the C +or C plugins). Scripting languages usually provide means to load +extensions written in C. Those extensions require symbols provided by the +interpreter, which is loaded as a dependency of the respective collectd +plugin. See the documentation of those plugins (e.Eg., +L or L) for details. + +=back + =item B I If I points to a file, includes that file. If I points to a @@ -4175,25 +4202,37 @@ Use the last number found. =item B -The matched number is a counter. Simply sets the internal counter to this -value. +=item B + +=item B + +The matched number is a counter. Simply I the internal counter to this +value. Variants exist for C, C, and C data sources. =item B -Add the matched value to the internal counter. +=item B + +Add the matched value to the internal counter. In case of B, the +matched number may be negative, which will effectively subtract from the +internal counter. =item B -Increase the internal counter by one. This B is the only one that does -not use the matched subexpression, but simply counts the number of matched +=item B + +Increase the internal counter by one. These B are the only ones that do +not use the matched subexpression, but simply count the number of matched lines. Thus, you may use a regular expression without submatch in this case. =back As you'd expect the B types interpret the submatch as a floating point -number, using L. The B and B interpret the -submatch as an integer using L. B does not use the -submatch at all and it may be omitted in this case. +number, using L. The B and B types interpret +the submatch as an unsigned integer using L. The B types +interpret the submatch as a signed integer using L. B +and B do not use the submatch at all and it may be omitted in this +case. =item B I diff --git a/src/configfile.c b/src/configfile.c index 787ad0ea..0b7786f9 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -701,11 +701,10 @@ static oconfig_item_t *cf_read_generic (const char *path, int depth) if (status != 0) { char errbuf[1024]; - ERROR ("configfile: stat (%s) failed: %s", + WARNING ("configfile: stat (%s) failed: %s", path_ptr, sstrerror (errno, errbuf, sizeof (errbuf))); - oconfig_free (root); - return (NULL); + continue; } if (S_ISREG (statbuf.st_mode)) @@ -714,7 +713,7 @@ static oconfig_item_t *cf_read_generic (const char *path, int depth) temp = cf_read_dir (path_ptr, depth); else { - ERROR ("configfile: %s is neither a file nor a " + WARNING ("configfile: %s is neither a file nor a " "directory.", path); continue; } @@ -731,6 +730,12 @@ static oconfig_item_t *cf_read_generic (const char *path, int depth) wordfree (&we); + if (root->children == NULL) + { + oconfig_free (root); + return (NULL); + } + return (root); } /* oconfig_item_t *cf_read_generic */ /* #endif HAVE_WORDEXP_H */ diff --git a/src/curl_json.c b/src/curl_json.c index 03ef6a34..21deed61 100644 --- a/src/curl_json.c +++ b/src/curl_json.c @@ -1,7 +1,7 @@ /** * collectd - src/curl_json.c * Copyright (C) 2009 Doug MacEachern - * Copyright (C) 2006-2009 Florian octo Forster + * Copyright (C) 2006-2010 Florian octo Forster * * 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 @@ -130,59 +130,57 @@ static int cj_get_type (cj_key_t *key) } /* yajl callbacks */ -static int cj_cb_integer (void *ctx, long val) +#define CJ_CB_ABORT 0 +#define CJ_CB_CONTINUE 1 + +/* "number" may not be null terminated, so copy it into a buffer before + * parsing. */ +static int cj_cb_number (void *ctx, + const char *number, unsigned int number_len) { + char buffer[number_len + 1]; + cj_t *db = (cj_t *)ctx; cj_key_t *key = db->state[db->depth].key; + char *endptr; + value_t vt; + int type; - if (key != NULL) - { - value_t vt; - int type; + if (key == NULL) + return (CJ_CB_CONTINUE); - type = cj_get_type (key); - if (type == DS_TYPE_COUNTER) - vt.counter = (counter_t) val; - else if (type == DS_TYPE_GAUGE) - vt.gauge = (gauge_t) val; - else if (type == DS_TYPE_DERIVE) - vt.derive = (derive_t) val; - else if (type == DS_TYPE_ABSOLUTE) - vt.absolute = (absolute_t) val; - else - return 0; + memcpy (buffer, number, number_len); + buffer[sizeof (buffer) - 1] = 0; - cj_submit (db, key, &vt); - } - return 1; -} + type = cj_get_type (key); -static int cj_cb_double (void *ctx, double val) -{ - cj_t *db = (cj_t *)ctx; - cj_key_t *key = db->state[db->depth].key; + endptr = NULL; + errno = 0; - if (key != NULL) + if (type == DS_TYPE_COUNTER) + vt.counter = (counter_t) strtoull (buffer, &endptr, /* base = */ 0); + else if (type == DS_TYPE_GAUGE) + vt.gauge = (gauge_t) strtod (buffer, &endptr); + else if (type == DS_TYPE_DERIVE) + vt.derive = (derive_t) strtoll (buffer, &endptr, /* base = */ 0); + else if (type == DS_TYPE_ABSOLUTE) + vt.absolute = (absolute_t) strtoull (buffer, &endptr, /* base = */ 0); + else { - value_t vt; - int type; - - type = cj_get_type (key); - if (type == DS_TYPE_COUNTER) - vt.counter = (counter_t) val; - else if (type == DS_TYPE_GAUGE) - vt.gauge = (gauge_t) val; - else if (type == DS_TYPE_DERIVE) - vt.derive = (derive_t) val; - else if (type == DS_TYPE_ABSOLUTE) - vt.absolute = (absolute_t) val; - else - return 0; + ERROR ("curl_json plugin: Unknown data source type: \"%s\"", key->type); + return (CJ_CB_ABORT); + } - cj_submit (db, key, &vt); + if ((endptr == &buffer[0]) || (errno != 0)) + { + NOTICE ("curl_json plugin: Overflow while parsing number. " + "Ignoring this value."); + return (CJ_CB_CONTINUE); } - return 1; -} + + cj_submit (db, key, &vt); + return (CJ_CB_CONTINUE); +} /* int cj_cb_number */ static int cj_cb_map_key (void *ctx, const unsigned char *val, unsigned int len) @@ -209,7 +207,7 @@ static int cj_cb_map_key (void *ctx, const unsigned char *val, db->state[db->depth].key = NULL; } - return 1; + return (CJ_CB_CONTINUE); } static int cj_cb_string (void *ctx, const unsigned char *val, @@ -220,7 +218,7 @@ static int cj_cb_string (void *ctx, const unsigned char *val, char *ptr; if (db->depth != 1) /* e.g. _all_dbs */ - return 1; + return (CJ_CB_CONTINUE); cj_cb_map_key (ctx, val, len); /* same logic */ @@ -242,7 +240,7 @@ static int cj_cb_string (void *ctx, const unsigned char *val, cj_curl_perform (db, curl); curl_easy_cleanup (curl); } - return 1; + return (CJ_CB_CONTINUE); } static int cj_cb_start (void *ctx) @@ -251,9 +249,9 @@ static int cj_cb_start (void *ctx) if (++db->depth >= YAJL_MAX_DEPTH) { ERROR ("curl_json plugin: %s depth exceeds max, aborting.", db->url); - return 0; + return (CJ_CB_ABORT); } - return 1; + return (CJ_CB_CONTINUE); } static int cj_cb_end (void *ctx) @@ -261,7 +259,7 @@ static int cj_cb_end (void *ctx) cj_t *db = (cj_t *)ctx; db->state[db->depth].tree = NULL; --db->depth; - return 1; + return (CJ_CB_CONTINUE); } static int cj_cb_start_map (void *ctx) @@ -287,9 +285,9 @@ static int cj_cb_end_array (void * ctx) static yajl_callbacks ycallbacks = { NULL, /* null */ NULL, /* boolean */ - cj_cb_integer, - cj_cb_double, - NULL, /* number */ + NULL, /* integer */ + NULL, /* double */ + cj_cb_number, cj_cb_string, cj_cb_start_map, cj_cb_map_key, @@ -777,7 +775,8 @@ static int cj_curl_perform (cj_t *db, CURL *curl) /* {{{ */ curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &rc); - if (rc != 200) + /* The response code is zero if a non-HTTP transport was used. */ + if ((rc != 0) && (rc != 200)) { ERROR ("curl_json plugin: curl_easy_perform failed with response code %ld (%s)", rc, url); diff --git a/src/plugin.c b/src/plugin.c index 4a3c9171..af894d54 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -1374,7 +1374,12 @@ int plugin_dispatch_values (value_list_t *vl) if (c_avl_get (data_sets, vl->type, (void *) &ds) != 0) { - INFO ("plugin_dispatch_values: Dataset not found: %s", vl->type); + char ident[6 * DATA_MAX_NAME_LEN]; + + FORMAT_VL (ident, sizeof (ident), vl); + INFO ("plugin_dispatch_values: Dataset not found: %s " + "(from \"%s\"), check your types.db!", + vl->type, ident); return (-1); } diff --git a/src/utils_match.c b/src/utils_match.c index 0f87bc0c..4d4b57d0 100644 --- a/src/utils_match.c +++ b/src/utils_match.c @@ -83,7 +83,7 @@ static int default_callback (const char __attribute__((unused)) *str, if (matches_num < 2) return (-1); - value = strtod (matches[1], &endptr); + value = (gauge_t) strtod (matches[1], &endptr); if (matches[1] == endptr) return (-1); @@ -131,7 +131,7 @@ static int default_callback (const char __attribute__((unused)) *str, if (matches_num < 2) return (-1); - value = strtoll (matches[1], &endptr, 0); + value = (counter_t) strtoull (matches[1], &endptr, 0); if (matches[1] == endptr) return (-1); @@ -162,7 +162,7 @@ static int default_callback (const char __attribute__((unused)) *str, if (matches_num < 2) return (-1); - value = strtoll (matches[1], &endptr, 0); + value = (derive_t) strtoll (matches[1], &endptr, 0); if (matches[1] == endptr) return (-1); @@ -186,7 +186,7 @@ static int default_callback (const char __attribute__((unused)) *str, if (matches_num < 2) return (-1); - value = strtoll (matches[1], &endptr, 0); + value = (absolute_t) strtoull (matches[1], &endptr, 0); if (matches[1] == endptr) return (-1); diff --git a/src/utils_match.h b/src/utils_match.h index 9e47d5c5..36abe30c 100644 --- a/src/utils_match.h +++ b/src/utils_match.h @@ -28,10 +28,10 @@ /* * Defines */ -#define UTILS_MATCH_DS_TYPE_GAUGE 0x10 -#define UTILS_MATCH_DS_TYPE_COUNTER 0x20 -#define UTILS_MATCH_DS_TYPE_DERIVE 0x30 -#define UTILS_MATCH_DS_TYPE_ABSOLUTE 0x40 +#define UTILS_MATCH_DS_TYPE_GAUGE 0x10 +#define UTILS_MATCH_DS_TYPE_COUNTER 0x20 +#define UTILS_MATCH_DS_TYPE_DERIVE 0x40 +#define UTILS_MATCH_DS_TYPE_ABSOLUTE 0x80 #define UTILS_MATCH_CF_GAUGE_AVERAGE 0x01 #define UTILS_MATCH_CF_GAUGE_MIN 0x02