X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fvarnish.c;h=1089222327ac8a61f540f4a27d333ed1455c6a66;hb=dab48f284f9d4bb6ae98244310c5cdb6c5d91bf3;hp=e3b6cec14d6a5c73484a6969b965922a1e935faf;hpb=a9a8e4bcd0e688e054ae816813475c8784cc4012;p=collectd.git diff --git a/src/varnish.c b/src/varnish.c index e3b6cec1..10892223 100644 --- a/src/varnish.c +++ b/src/varnish.c @@ -29,19 +29,19 @@ #include "configfile.h" #if HAVE_VARNISH_V4 -#include -#include +#include +#include typedef struct VSC_C_main c_varnish_stats_t; #endif #if HAVE_VARNISH_V3 -#include -#include +#include +#include typedef struct VSC_C_main c_varnish_stats_t; #endif #if HAVE_VARNISH_V2 -#include +#include typedef struct varnish_stats c_varnish_stats_t; #endif @@ -78,6 +78,9 @@ struct user_config_s { #endif _Bool collect_vcl; _Bool collect_workers; +#if HAVE_VARNISH_V4 + _Bool collect_vsm; +#endif }; typedef struct user_config_s user_config_t; /* }}} */ @@ -271,7 +274,10 @@ static void varnish_monitor (const user_config_t *conf, /* {{{ */ #endif /* HTTP header overflows */ varnish_submit_derive (conf->instance, "objects", "total_objects", "header_overflow", stats->losthdr); -#if !HAVE_VARNISH_V4 +#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 */ @@ -435,6 +441,8 @@ static void varnish_monitor (const user_config_t *conf, /* {{{ */ 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); @@ -479,12 +487,20 @@ static void varnish_monitor (const user_config_t *conf, /* {{{ */ 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 @@ -503,6 +519,10 @@ static void varnish_monitor (const user_config_t *conf, /* {{{ */ 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) @@ -530,7 +550,7 @@ static void varnish_monitor (const user_config_t *conf, /* {{{ */ /* worker threads limited */ varnish_submit_derive (conf->instance, "workers", "total_threads", "limited", stats->n_wrk_max); /* dropped work requests */ - varnish_submit_derive (conf->instance, "workers", "total_requests", "dropped", stats->n_wrk_drop); + 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); @@ -544,6 +564,23 @@ static void varnish_monitor (const user_config_t *conf, /* {{{ */ #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 */ #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 @@ -571,6 +608,7 @@ static int varnish_read (user_data_t *ud) /* {{{ */ status = VSM_n_Arg (vd, conf->instance); if (status < 0) { + VSM_Delete (vd); ERROR ("varnish plugin: VSM_n_Arg (\"%s\") failed " "with status %i.", conf->instance, status); @@ -584,7 +622,8 @@ static int varnish_read (user_data_t *ud) /* {{{ */ if (VSM_Open (vd)) #endif { - ERROR ("varnish plugin: Unable to load statistics."); + VSM_Delete (vd); + ERROR ("varnish plugin: Unable to open connection."); return (-1); } @@ -594,9 +633,17 @@ static int varnish_read (user_data_t *ud) /* {{{ */ #else /* if HAVE_VARNISH_V4 */ stats = VSC_Main(vd, NULL); #endif + if (!stats) + { + VSM_Delete (vd); + ERROR ("varnish plugin: Unable to get statistics."); + + return (-1); + } + varnish_monitor (conf, stats); - VSM_Close (vd); + VSM_Delete (vd); return (0); } /* }}} */ @@ -671,6 +718,9 @@ static int varnish_config_apply_default (user_config_t *conf) /* {{{ */ #endif conf->collect_vcl = 0; conf->collect_workers = 0; +#if HAVE_VARNISH_V4 + conf->collect_vsm = 0; +#endif return (0); } /* }}} int varnish_config_apply_default */ @@ -798,6 +848,10 @@ static int varnish_config_instance (const oconfig_item_t *ci) /* {{{ */ cf_util_get_boolean (child, &conf->collect_vcl); else if (strcasecmp ("CollectWorkers", child->key) == 0) cf_util_get_boolean (child, &conf->collect_workers); +#if HAVE_VARNISH_V4 + else if (strcasecmp ("CollectVSM", child->key) == 0) + cf_util_get_boolean (child, &conf->collect_vsm); +#endif else { WARNING ("Varnish plugin: Ignoring unknown " @@ -836,7 +890,11 @@ static int varnish_config_instance (const oconfig_item_t *ci) /* {{{ */ && !conf->collect_uptime #endif && !conf->collect_vcl - && !conf->collect_workers) + && !conf->collect_workers +#if HAVE_VARNISH_V4 + && !conf->collect_vsm +#endif + ) { WARNING ("Varnish plugin: No metric has been configured for " "instance \"%s\". Disabling this instance.",