.libs/
src/collectd
src/collectd-nagios
+src/collectd-tg
src/collectdctl
src/collectdmon
src/*.1
src/*.5
-src/libcollectdclient/lcc_features.h
+src/libcollectdclient/collectd/lcc_features.h
# patch stuff
*.rej
&& rm -f Makefile \
&& rm -f Makefile.in \
&& rm -f missing \
+&& rm -f INSTALL \
&& rm -f -r src/.deps \
&& rm -f -r src/.libs \
&& rm -f src/*.o \
&& rm -f src/*.lo \
&& rm -f src/collectd \
&& rm -f src/collectd.1 \
+&& rm -f src/collectd.conf \
+&& rm -f src/collectdctl \
+&& rm -f src/collectd-tg \
+&& rm -f src/collectd-nagios \
+&& rm -f src/collectdmon \
&& rm -f src/config.h \
&& rm -f src/config.h.in \
&& rm -f src/config.h.in~ \
&& rm -f src/Makefile.in \
&& rm -f src/stamp-h1 \
&& rm -f src/stamp-h1.in \
+&& rm -f src/*.pb-c.c \
+&& rm -f src/*.pb-c.h \
+&& rm -f src/Makefile.in \
+&& rm -f src/liboconfig/*.o \
+&& rm -f src/liboconfig/*.la \
+&& rm -f src/liboconfig/*.lo \
+&& rm -f -r src/liboconfig/.libs \
+&& rm -f -r src/liboconfig/Makefile \
+&& rm -f -r src/liboconfig/Makefile.in \
+&& rm -f -r src/liboconfig/parser.c \
+&& rm -f -r src/liboconfig/parser.h \
+&& rm -f -r src/liboconfig/scanner.c \
&& rm -f -r src/libping/.libs \
&& rm -f src/libping/*.o \
&& rm -f src/libping/*.la \
&& rm -f src/libcollectdclient/*.o \
&& rm -f src/libcollectdclient/*.la \
&& rm -f src/libcollectdclient/*.lo \
+&& rm -f src/libcollectdclient/Makefile \
+&& rm -f src/libcollectdclient/Makefile.in \
+&& rm -f src/libcollectdclient/collectd/lcc_features.h \
+&& rm -f src/libcollectdclient/libcollectdclient.pc \
+&& rm -f bindings/Makefile \
+&& rm -f bindings/Makefile.in \
+&& rm -f -r bindings/java/.libs \
+&& rm -f bindings/java/Makefile \
+&& rm -f bindings/java/Makefile.in \
+&& rm -f bindings/java/java-build-stamp \
+&& rm -f bindings/java/org/collectd/api/*.class \
+&& rm -f bindings/java/org/collectd/java/*.class \
&& rm -f bindings/.perl-directory-stamp \
&& rm -f -r bindings/buildperl
=head2 Plugin C<curl_json>
-The B<curl_json plugin> uses B<libcurl> (L<http://curl.haxx.se/>) and
-B<libyajl> (L<http://www.lloydforge.org/projects/yajl/>) to retrieve JSON data
-via cURL. This can be used to collect values from CouchDB documents (which are
-stored JSON notation), for example.
-
-The following example will collect several values from the built-in `_stats'
-runtime statistics module of CouchDB
+The B<curl_json plugin> collects values from JSON data to be parsed by
+B<libyajl> (L<http://www.lloydforge.org/projects/yajl/>) retrieved via
+either B<libcurl> (L<http://curl.haxx.se/>) or read directly from a
+unix socket. The former can be used, for example, to collect values
+from CouchDB documents (which are stored JSON notation), and the
+latter to collect values from a uWSGI stats socket.
+
+The following example will collect several values from the built-in
+`_stats' runtime statistics module of CouchDB
(L<http://wiki.apache.org/couchdb/Runtime_Statistics>).
<Plugin curl_json>
</URL>
</Plugin>
-In the B<Plugin> block, there may be one or more B<URL> blocks, each defining
-a URL to be fetched via HTTP (using libcurl) and one or more B<Key> blocks.
+This example will collect data directly from a uWSGI Stats Server
+socket.
+
+ <Plugin curl_json>
+ <Sock "/var/run/uwsgi.stats.sock">
+ Instance "uwsgi"
+ <Key "workers/*/requests">
+ Type "http_requests"
+ </Key>
+
+ <Key "workers/*/apps/*/requests">
+ Type "http_requests"
+ </Key>
+ </Sock>
+ </Plugin>
+
+In the B<Plugin> block, there may be one or more B<URL> blocks, each
+defining a URL to be fetched via HTTP (using libcurl) or B<Sock>
+blocks defining a unix socket to read JSON from directly. Each of
+these blocks may have one or more B<Key> blocks.
+
The B<Key> string argument must be in a path format, which is used to collect a
value from a JSON map object. If a path element of B<Key> is the
I<*>E<nbsp>wildcard, the values for all keys will be collectd.
#include "utils_avltree.h"
#include "utils_complain.h"
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <sys/un.h>
+
#include <curl/curl.h>
+
#include <yajl/yajl_parse.h>
#if HAVE_YAJL_YAJL_VERSION_H
# include <yajl/yajl_version.h>
char *instance;
char *host;
+ char *sock;
+
char *url;
char *user;
char *pass;
#endif
static int cj_read (user_data_t *ud);
-static int cj_curl_perform (cj_t *db, CURL *curl);
static void cj_submit (cj_t *db, cj_key_t *key, value_t *value);
static size_t cj_curl_callback (void *buf, /* {{{ */
cj_t *db = (cj_t *)ctx;
if (++db->depth >= YAJL_MAX_DEPTH)
{
- ERROR ("curl_json plugin: %s depth exceeds max, aborting.", db->url);
+ ERROR ("curl_json plugin: %s depth exceeds max, aborting.",
+ db->url ? db->url : db->sock);
return (CJ_CB_ABORT);
}
return (CJ_CB_CONTINUE);
sfree (db->instance);
sfree (db->host);
+ sfree (db->sock);
+
sfree (db->url);
sfree (db->user);
sfree (db->pass);
memset (db, 0, sizeof (*db));
if (strcasecmp ("URL", ci->key) == 0)
- {
status = cf_util_get_string (ci, &db->url);
- if (status != 0)
- {
- sfree (db);
- return (status);
- }
- }
+ else if (strcasecmp ("Sock", ci->key) == 0)
+ status = cf_util_get_string (ci, &db->sock);
else
{
ERROR ("curl_json plugin: cj_config: "
"Invalid key: %s", ci->key);
return (-1);
}
+ if (status != 0)
+ {
+ sfree (db);
+ return (status);
+ }
/* Fill the `cj_t' structure.. */
for (i = 0; i < ci->children_num; i++)
status = cf_util_get_string (child, &db->instance);
else if (strcasecmp ("Host", child->key) == 0)
status = cf_util_get_string (child, &db->host);
- else if (strcasecmp ("User", child->key) == 0)
+ else if (db->url && strcasecmp ("User", child->key) == 0)
status = cf_util_get_string (child, &db->user);
- else if (strcasecmp ("Password", child->key) == 0)
+ else if (db->url && strcasecmp ("Password", child->key) == 0)
status = cf_util_get_string (child, &db->pass);
- else if (strcasecmp ("VerifyPeer", child->key) == 0)
+ else if (db->url && strcasecmp ("VerifyPeer", child->key) == 0)
status = cf_util_get_boolean (child, &db->verify_peer);
- else if (strcasecmp ("VerifyHost", child->key) == 0)
+ else if (db->url && strcasecmp ("VerifyHost", child->key) == 0)
status = cf_util_get_boolean (child, &db->verify_host);
- else if (strcasecmp ("CACert", child->key) == 0)
+ else if (db->url && strcasecmp ("CACert", child->key) == 0)
status = cf_util_get_string (child, &db->cacert);
- else if (strcasecmp ("Header", child->key) == 0)
+ else if (db->url && strcasecmp ("Header", child->key) == 0)
status = cj_config_append_string ("Header", &db->headers, child);
- else if (strcasecmp ("Post", child->key) == 0)
+ else if (db->url && strcasecmp ("Post", child->key) == 0)
status = cf_util_get_string (child, &db->post_body);
else if (strcasecmp ("Key", child->key) == 0)
status = cj_config_add_key (db, child);
{
if (db->tree == NULL)
{
- WARNING ("curl_json plugin: No (valid) `Key' block "
- "within `URL' block `%s'.", db->url);
+ WARNING ("curl_json plugin: No (valid) `Key' block within `%s' \"`%s'\".",
+ db->url ? "URL" : "Sock", db->url ? db->url : db->sock);
status = -1;
}
- if (status == 0)
+ if (status == 0 && db->url)
status = cj_init_curl (db);
}
ud.free_func = cj_free;
ssnprintf (cb_name, sizeof (cb_name), "curl_json-%s-%s",
- db->instance, db->url);
+ db->instance, db->url ? db->url : db->sock);
plugin_register_complex_read (/* group = */ NULL, cb_name, cj_read,
/* interval = */ NULL, &ud);
{
oconfig_item_t *child = ci->children + i;
- if (strcasecmp ("URL", child->key) == 0)
+ if (strcasecmp ("Sock", child->key) == 0
+ || strcasecmp ("URL", child->key) == 0)
{
status = cj_config_add_url (child);
if (status == 0)
plugin_dispatch_values (&vl);
} /* }}} int cj_submit */
-static int cj_curl_perform (cj_t *db, CURL *curl) /* {{{ */
+static int cj_sock_perform (cj_t *db) /* {{{ */
{
- int status;
- long rc;
- char *url;
- yajl_handle yprev = db->yajl;
+ char errbuf[1024];
+ struct sockaddr_un sa_unix = {};
+ sa_unix.sun_family = AF_UNIX;
+ sstrncpy (sa_unix.sun_path, db->sock, sizeof (sa_unix.sun_path));
- db->yajl = yajl_alloc (&ycallbacks,
-#if HAVE_YAJL_V2
- /* alloc funcs = */ NULL,
-#else
- /* alloc funcs = */ NULL, NULL,
-#endif
- /* context = */ (void *)db);
- if (db->yajl == NULL)
+ int fd = socket (AF_UNIX, SOCK_STREAM, 0);
+ if (fd < 0)
+ return (-1);
+ if (connect (fd, (struct sockaddr *)&sa_unix, sizeof(sa_unix)) < 0)
{
- ERROR ("curl_json plugin: yajl_alloc failed.");
- db->yajl = yprev;
+ ERROR ("curl_json plugin: connect(%s) failed: %s",
+ (db->sock != NULL) ? db->sock : "<null>",
+ sstrerror(errno, errbuf, sizeof (errbuf)));
+ close (fd);
return (-1);
}
+ ssize_t red;
+ do {
+ unsigned char buffer[4096];
+ red = read (fd, buffer, sizeof(buffer));
+ if (red < 0) {
+ ERROR ("curl_json plugin: read(%s) failed: %s",
+ (db->sock != NULL) ? db->sock : "<null>",
+ sstrerror(errno, errbuf, sizeof (errbuf)));
+ close (fd);
+ return (-1);
+ }
+ if (!cj_curl_callback (buffer, red, 1, db))
+ break;
+ } while (red > 0);
+ close (fd);
+ return (0);
+} /* }}} int cj_sock_perform */
+
+
+static int cj_curl_perform(cj_t *db) /* {{{ */
+{
+ int status;
+ long rc;
+ char *url;
url = NULL;
- curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url);
+ curl_easy_getinfo(db->curl, CURLINFO_EFFECTIVE_URL, &url);
- status = curl_easy_perform (curl);
+ status = curl_easy_perform (db->curl);
if (status != CURLE_OK)
{
ERROR ("curl_json plugin: curl_easy_perform failed with status %i: %s (%s)",
status, db->curl_errbuf, (url != NULL) ? url : "<null>");
- yajl_free (db->yajl);
- db->yajl = yprev;
return (-1);
}
- curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &rc);
+ curl_easy_getinfo(db->curl, CURLINFO_RESPONSE_CODE, &rc);
/* 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);
+ return (-1);
+ }
+ return (0);
+} /* }}} int cj_curl_perform */
+
+static int cj_perform (cj_t *db) /* {{{ */
+{
+ int status;
+ yajl_handle yprev = db->yajl;
+
+ db->yajl = yajl_alloc (&ycallbacks,
+#if HAVE_YAJL_V2
+ /* alloc funcs = */ NULL,
+#else
+ /* alloc funcs = */ NULL, NULL,
+#endif
+ /* context = */ (void *)db);
+ if (db->yajl == NULL)
+ {
+ ERROR ("curl_json plugin: yajl_alloc failed.");
+ db->yajl = yprev;
+ return (-1);
+ }
+
+ if (db->url)
+ status = cj_curl_perform (db);
+ else
+ status = cj_sock_perform (db);
+ if (status < 0)
+ {
yajl_free (db->yajl);
db->yajl = yprev;
return (-1);
yajl_free (db->yajl);
db->yajl = yprev;
return (0);
-} /* }}} int cj_curl_perform */
+} /* }}} int cj_perform */
static int cj_read (user_data_t *ud) /* {{{ */
{
db->state[db->depth].tree = db->tree;
db->key = NULL;
- return cj_curl_perform (db, db->curl);
+ return cj_perform (db);
} /* }}} int cj_read */
void module_register (void)
static double *conf_timer_percentile = NULL;
static size_t conf_timer_percentile_num = 0;
+static _Bool conf_timer_lower = 0;
+static _Bool conf_timer_upper = 0;
+static _Bool conf_timer_sum = 0;
+static _Bool conf_timer_count = 0;
+
/* Must hold metrics_lock when calling this function. */
static statsd_metric_t *statsd_metric_lookup_unsafe (char const *name, /* {{{ */
metric_type_t type)
cf_util_get_boolean (child, &conf_delete_gauges);
else if (strcasecmp ("DeleteSets", child->key) == 0)
cf_util_get_boolean (child, &conf_delete_sets);
+ else if (strcasecmp ("TimerLower", child->key) == 0)
+ cf_util_get_boolean (child, &conf_timer_lower);
+ else if (strcasecmp ("TimerUpper", child->key) == 0)
+ cf_util_get_boolean (child, &conf_timer_upper);
+ else if (strcasecmp ("TimerSum", child->key) == 0)
+ cf_util_get_boolean (child, &conf_timer_sum);
+ else if (strcasecmp ("TimerCount", child->key) == 0)
+ cf_util_get_boolean (child, &conf_timer_count);
else if (strcasecmp ("TimerPercentile", child->key) == 0)
statsd_config_timer_percentile (child);
else
latency_counter_get_average (metric->latency));
plugin_dispatch_values (&vl);
+ if (conf_timer_lower) {
+ ssnprintf (vl.type_instance, sizeof (vl.type_instance),
+ "%s-lower", name);
+ values[0].gauge = CDTIME_T_TO_DOUBLE (
+ latency_counter_get_min (metric->latency));
+ plugin_dispatch_values (&vl);
+ }
+
+ if (conf_timer_upper) {
+ ssnprintf (vl.type_instance, sizeof (vl.type_instance),
+ "%s-upper", name);
+ values[0].gauge = CDTIME_T_TO_DOUBLE (
+ latency_counter_get_max (metric->latency));
+ plugin_dispatch_values (&vl);
+ }
+
+ if (conf_timer_sum) {
+ ssnprintf (vl.type_instance, sizeof (vl.type_instance),
+ "%s-sum", name);
+ values[0].gauge = CDTIME_T_TO_DOUBLE (
+ latency_counter_get_sum (metric->latency));
+ plugin_dispatch_values (&vl);
+ }
+
for (i = 0; i < conf_timer_percentile_num; i++)
{
ssnprintf (vl.type_instance, sizeof (vl.type_instance),
plugin_dispatch_values (&vl);
}
+ /* Keep this at the end, since vl.type is set to "gauge" here. The
+ * vl.type's above are implicitly set to "latency". */
+ if (conf_timer_count) {
+ sstrncpy (vl.type, "gauge", sizeof (vl.type));
+ ssnprintf (vl.type_instance, sizeof (vl.type_instance),
+ "%s-count", name);
+ values[0].gauge = latency_counter_get_num (metric->latency);
+ plugin_dispatch_values (&vl);
+ }
+
latency_counter_reset (metric->latency);
return (0);
}
ipt_bytes value:DERIVE:0:U
ipt_packets value:DERIVE:0:U
irq value:DERIVE:0:U
-latency value:GAUGE:0:65535
+latency value:GAUGE:0:U
links value:GAUGE:0:U
load shortterm:GAUGE:0:5000, midterm:GAUGE:0:5000, longterm:GAUGE:0:5000
md_disks value:GAUGE:0:U
return (lc->max);
} /* }}} cdtime_t latency_counter_get_max */
+cdtime_t latency_counter_get_sum (latency_counter_t *lc) /* {{{ */
+{
+ if (lc == NULL)
+ return (0);
+ return (lc->sum);
+} /* }}} cdtime_t latency_counter_get_sum */
+
+size_t latency_counter_get_num (latency_counter_t *lc) /* {{{ */
+{
+ if (lc == NULL)
+ return (0);
+ return (lc->num);
+} /* }}} size_t latency_counter_get_num */
+
cdtime_t latency_counter_get_average (latency_counter_t *lc) /* {{{ */
{
double average;
cdtime_t latency_counter_get_min (latency_counter_t *lc);
cdtime_t latency_counter_get_max (latency_counter_t *lc);
+cdtime_t latency_counter_get_sum (latency_counter_t *lc);
+size_t latency_counter_get_num (latency_counter_t *lc);
cdtime_t latency_counter_get_average (latency_counter_t *lc);
cdtime_t latency_counter_get_percentile (latency_counter_t *lc,
double percent);
#endif
_Bool collect_struct;
_Bool collect_totals;
+#ifdef HAVE_VARNISH_V3
_Bool collect_uptime;
+#endif
_Bool collect_vcl;
_Bool collect_workers;
};
varnish_submit_gauge (conf->instance, "struct", "current_sessions", "sess", stats->n_sess);
/* N struct object */
varnish_submit_gauge (conf->instance, "struct", "objects", "object", stats->n_object);
+#ifdef HAVE_VARNISH_V3
/* 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);
+#endif
/* N struct objecthead */
varnish_submit_gauge (conf->instance, "struct", "objects", "objecthead", stats->n_objecthead);
#ifdef HAVE_VARNISH_V2
varnish_submit_derive (conf->instance, "totals", "total_bytes", "body-bytes", stats->s_bodybytes);
}
+#ifdef HAVE_VARNISH_V3
if (conf->collect_uptime)
{
/* Client uptime */
varnish_submit_gauge (conf->instance, "uptime", "uptime", "client_uptime", stats->uptime);
}
+#endif
if (conf->collect_vcl)
{
conf->collect_sms = 0;
conf->collect_struct = 0;
conf->collect_totals = 0;
+#ifdef HAVE_VARNISH_V3
conf->collect_uptime = 0;
+#endif
conf->collect_vcl = 0;
conf->collect_workers = 0;
cf_util_get_boolean (child, &conf->collect_struct);
else if (strcasecmp ("CollectTotals", child->key) == 0)
cf_util_get_boolean (child, &conf->collect_totals);
+#ifdef HAVE_VARNISH_V3
else if (strcasecmp ("CollectUptime", child->key) == 0)
cf_util_get_boolean (child, &conf->collect_uptime);
+#endif
else if (strcasecmp ("CollectVCL", child->key) == 0)
cf_util_get_boolean (child, &conf->collect_vcl);
else if (strcasecmp ("CollectWorkers", child->key) == 0)
#endif
&& !conf->collect_struct
&& !conf->collect_totals
+#ifdef HAVE_VARNISH_V3
&& !conf->collect_uptime
+#endif
&& !conf->collect_vcl
&& !conf->collect_workers)
{