2 * collectd - src/varnish.c
3 * Copyright (C) 2010 Jérôme Renard
4 * Copyright (C) 2010 Marc Fournier
5 * Copyright (C) 2010-2012 Florian Forster
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; only version 2 of the License is applicable.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 * Jérôme Renard <jerome.renard at gmail.com>
22 * Marc Fournier <marc.fournier at camptocamp.com>
23 * Florian octo Forster <octo at collectd.org>
29 #include "configfile.h"
32 #include <varnish/vapi/vsm.h>
33 #include <varnish/vapi/vsc.h>
34 typedef struct VSC_C_main c_varnish_stats_t;
38 #include <varnish/varnishapi.h>
39 #include <varnish/vsc.h>
40 typedef struct VSC_C_main c_varnish_stats_t;
44 #include <varnish/varnishapi.h>
45 typedef struct varnish_stats c_varnish_stats_t;
48 /* {{{ user_config_s */
49 struct user_config_s {
53 _Bool collect_connections;
55 _Bool collect_backend;
56 #ifdef HAVE_VARNISH_V3
61 _Bool collect_objects;
67 _Bool collect_session;
76 #ifdef HAVE_VARNISH_V3
80 _Bool collect_workers;
82 typedef struct user_config_s user_config_t; /* }}} */
84 static _Bool have_instance = 0;
86 static int varnish_submit (const char *plugin_instance, /* {{{ */
87 const char *category, const char *type, const char *type_instance, value_t value)
89 value_list_t vl = VALUE_LIST_INIT;
94 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
96 sstrncpy (vl.plugin, "varnish", sizeof (vl.plugin));
98 if (plugin_instance == NULL)
99 plugin_instance = "default";
101 ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance),
102 "%s-%s", plugin_instance, category);
104 sstrncpy (vl.type, type, sizeof (vl.type));
106 if (type_instance != NULL)
107 sstrncpy (vl.type_instance, type_instance,
108 sizeof (vl.type_instance));
110 return (plugin_dispatch_values (&vl));
111 } /* }}} int varnish_submit */
113 static int varnish_submit_gauge (const char *plugin_instance, /* {{{ */
114 const char *category, const char *type, const char *type_instance,
115 uint64_t gauge_value)
119 value.gauge = (gauge_t) gauge_value;
121 return (varnish_submit (plugin_instance, category, type, type_instance, value));
122 } /* }}} int varnish_submit_gauge */
124 static int varnish_submit_derive (const char *plugin_instance, /* {{{ */
125 const char *category, const char *type, const char *type_instance,
126 uint64_t derive_value)
130 value.derive = (derive_t) derive_value;
132 return (varnish_submit (plugin_instance, category, type, type_instance, value));
133 } /* }}} int varnish_submit_derive */
135 static void varnish_monitor (const user_config_t *conf, /* {{{ */
136 const c_varnish_stats_t *stats)
138 if (conf->collect_cache)
141 varnish_submit_derive (conf->instance, "cache", "cache_result", "hit", stats->cache_hit);
143 varnish_submit_derive (conf->instance, "cache", "cache_result", "miss", stats->cache_miss);
144 /* Cache hits for pass */
145 varnish_submit_derive (conf->instance, "cache", "cache_result", "hitpass", stats->cache_hitpass);
148 if (conf->collect_connections)
150 /* Client connections accepted */
151 varnish_submit_derive (conf->instance, "connections", "connections", "accepted", stats->client_conn);
152 /* Connection dropped, no sess */
153 varnish_submit_derive (conf->instance, "connections", "connections", "dropped" , stats->client_drop);
154 /* Client requests received */
155 varnish_submit_derive (conf->instance, "connections", "connections", "received", stats->client_req);
158 #ifdef HAVE_VARNISH_V3
159 if (conf->collect_dirdns)
161 /* DNS director lookups */
162 varnish_submit_derive (conf->instance, "dirdns", "cache_operation", "lookups", stats->dir_dns_lookups);
163 /* DNS director failed lookups */
164 varnish_submit_derive (conf->instance, "dirdns", "cache_result", "failed", stats->dir_dns_failed);
165 /* DNS director cached lookups hit */
166 varnish_submit_derive (conf->instance, "dirdns", "cache_result", "hits", stats->dir_dns_hit);
167 /* DNS director full dnscache */
168 varnish_submit_derive (conf->instance, "dirdns", "cache_result", "cache_full", stats->dir_dns_cache_full);
172 if (conf->collect_esi)
174 /* ESI parse errors (unlock) */
175 varnish_submit_derive (conf->instance, "esi", "total_operations", "error", stats->esi_errors);
177 /* Objects ESI parsed (unlock) */
178 varnish_submit_derive (conf->instance, "esi", "total_operations", "parsed", stats->esi_parse);
180 /* ESI parse warnings (unlock) */
181 varnish_submit_derive (conf->instance, "esi", "total_operations", "warning", stats->esi_warnings);
185 if (conf->collect_backend)
187 /* Backend conn. success */
188 varnish_submit_derive (conf->instance, "backend", "connections", "success" , stats->backend_conn);
189 /* Backend conn. not attempted */
190 varnish_submit_derive (conf->instance, "backend", "connections", "not-attempted", stats->backend_unhealthy);
191 /* Backend conn. too many */
192 varnish_submit_derive (conf->instance, "backend", "connections", "too-many" , stats->backend_busy);
193 /* Backend conn. failures */
194 varnish_submit_derive (conf->instance, "backend", "connections", "failures" , stats->backend_fail);
195 /* Backend conn. reuses */
196 varnish_submit_derive (conf->instance, "backend", "connections", "reuses" , stats->backend_reuse);
197 /* Backend conn. was closed */
198 varnish_submit_derive (conf->instance, "backend", "connections", "was-closed" , stats->backend_toolate);
199 /* Backend conn. recycles */
200 varnish_submit_derive (conf->instance, "backend", "connections", "recycled" , stats->backend_recycle);
202 /* Backend conn. unused */
203 varnish_submit_derive (conf->instance, "backend", "connections", "unused" , stats->backend_unused);
205 /* Backend conn. retry */
206 varnish_submit_derive (conf->instance, "backend", "connections", "retries" , stats->backend_retry);
208 /* Backend requests mades */
209 varnish_submit_derive (conf->instance, "backend", "http_requests", "requests" , stats->backend_req);
211 varnish_submit_gauge (conf->instance, "backend", "backends", "n_backends" , stats->n_backend);
214 if (conf->collect_fetch)
217 varnish_submit_derive (conf->instance, "fetch", "http_requests", "head" , stats->fetch_head);
218 /* Fetch with length */
219 varnish_submit_derive (conf->instance, "fetch", "http_requests", "length" , stats->fetch_length);
221 varnish_submit_derive (conf->instance, "fetch", "http_requests", "chunked" , stats->fetch_chunked);
223 varnish_submit_derive (conf->instance, "fetch", "http_requests", "eof" , stats->fetch_eof);
224 /* Fetch bad headers */
225 varnish_submit_derive (conf->instance, "fetch", "http_requests", "bad_headers", stats->fetch_bad);
226 /* Fetch wanted close */
227 varnish_submit_derive (conf->instance, "fetch", "http_requests", "close" , stats->fetch_close);
228 /* Fetch pre HTTP/1.1 closed */
229 varnish_submit_derive (conf->instance, "fetch", "http_requests", "oldhttp" , stats->fetch_oldhttp);
231 varnish_submit_derive (conf->instance, "fetch", "http_requests", "zero" , stats->fetch_zero);
233 varnish_submit_derive (conf->instance, "fetch", "http_requests", "failed" , stats->fetch_failed);
235 /* Fetch no body (1xx) */
236 varnish_submit_derive (conf->instance, "fetch", "http_requests", "no_body_1xx", stats->fetch_1xx);
237 /* Fetch no body (204) */
238 varnish_submit_derive (conf->instance, "fetch", "http_requests", "no_body_204", stats->fetch_204);
239 /* Fetch no body (304) */
240 varnish_submit_derive (conf->instance, "fetch", "http_requests", "no_body_304", stats->fetch_304);
244 if (conf->collect_hcb)
246 /* HCB Lookups without lock */
247 varnish_submit_derive (conf->instance, "hcb", "cache_operation", "lookup_nolock", stats->hcb_nolock);
248 /* HCB Lookups with lock */
249 varnish_submit_derive (conf->instance, "hcb", "cache_operation", "lookup_lock", stats->hcb_lock);
251 varnish_submit_derive (conf->instance, "hcb", "cache_operation", "insert", stats->hcb_insert);
254 if (conf->collect_objects)
256 /* N expired objects */
257 varnish_submit_derive (conf->instance, "objects", "total_objects", "expired", stats->n_expired);
258 /* N LRU nuked objects */
259 varnish_submit_derive (conf->instance, "objects", "total_objects", "lru_nuked", stats->n_lru_nuked);
261 /* N LRU saved objects */
262 varnish_submit_derive (conf->instance, "objects", "total_objects", "lru_saved", stats->n_lru_saved);
264 /* N LRU moved objects */
265 varnish_submit_derive (conf->instance, "objects", "total_objects", "lru_moved", stats->n_lru_moved);
267 /* N objects on deathrow */
268 varnish_submit_derive (conf->instance, "objects", "total_objects", "deathrow", stats->n_deathrow);
270 /* HTTP header overflows */
271 varnish_submit_derive (conf->instance, "objects", "total_objects", "header_overflow", stats->losthdr);
272 /* Objects sent with sendfile */
273 varnish_submit_derive (conf->instance, "objects", "total_objects", "sent_sendfile", stats->n_objsendfile);
274 /* Objects sent with write */
275 varnish_submit_derive (conf->instance, "objects", "total_objects", "sent_write", stats->n_objwrite);
276 /* Objects overflowing workspace */
277 varnish_submit_derive (conf->instance, "objects", "total_objects", "workspace_overflow", stats->n_objoverflow);
281 if (conf->collect_purge)
283 /* N total active purges */
284 varnish_submit_derive (conf->instance, "purge", "total_operations", "total", stats->n_purge);
285 /* N new purges added */
286 varnish_submit_derive (conf->instance, "purge", "total_operations", "added", stats->n_purge_add);
287 /* N old purges deleted */
288 varnish_submit_derive (conf->instance, "purge", "total_operations", "deleted", stats->n_purge_retire);
289 /* N objects tested */
290 varnish_submit_derive (conf->instance, "purge", "total_operations", "objects_tested", stats->n_purge_obj_test);
291 /* N regexps tested against */
292 varnish_submit_derive (conf->instance, "purge", "total_operations", "regexps_tested", stats->n_purge_re_test);
293 /* N duplicate purges removed */
294 varnish_submit_derive (conf->instance, "purge", "total_operations", "duplicate", stats->n_purge_dups);
297 if (conf->collect_ban)
299 /* N total active bans */
300 varnish_submit_derive (conf->instance, "ban", "total_operations", "total", stats->n_ban);
301 /* N new bans added */
302 varnish_submit_derive (conf->instance, "ban", "total_operations", "added", stats->n_ban_add);
303 /* N old bans deleted */
304 varnish_submit_derive (conf->instance, "ban", "total_operations", "deleted", stats->n_ban_retire);
305 /* N objects tested */
306 varnish_submit_derive (conf->instance, "ban", "total_operations", "objects_tested", stats->n_ban_obj_test);
307 /* N regexps tested against */
308 varnish_submit_derive (conf->instance, "ban", "total_operations", "regexps_tested", stats->n_ban_re_test);
309 /* N duplicate bans removed */
310 varnish_submit_derive (conf->instance, "ban", "total_operations", "duplicate", stats->n_ban_dups);
314 if (conf->collect_session)
317 varnish_submit_derive (conf->instance, "session", "total_operations", "closed", stats->sess_closed);
318 /* Session Pipeline */
319 varnish_submit_derive (conf->instance, "session", "total_operations", "pipeline", stats->sess_pipeline);
320 /* Session Read Ahead */
321 varnish_submit_derive (conf->instance, "session", "total_operations", "readahead", stats->sess_readahead);
323 varnish_submit_derive (conf->instance, "session", "total_operations", "linger", stats->sess_linger);
325 varnish_submit_derive (conf->instance, "session", "total_operations", "herd", stats->sess_herd);
328 if (conf->collect_shm)
331 varnish_submit_derive (conf->instance, "shm", "total_operations", "records" , stats->shm_records);
333 varnish_submit_derive (conf->instance, "shm", "total_operations", "writes" , stats->shm_writes);
334 /* SHM flushes due to overflow */
335 varnish_submit_derive (conf->instance, "shm", "total_operations", "flushes" , stats->shm_flushes);
336 /* SHM MTX contention */
337 varnish_submit_derive (conf->instance, "shm", "total_operations", "contention", stats->shm_cont);
338 /* SHM cycles through buffer */
339 varnish_submit_derive (conf->instance, "shm", "total_operations", "cycles" , stats->shm_cycles);
343 if (conf->collect_sm)
345 /* allocator requests */
346 varnish_submit_derive (conf->instance, "sm", "total_requests", "nreq", stats->sm_nreq);
347 /* outstanding allocations */
348 varnish_submit_gauge (conf->instance, "sm", "requests", "outstanding", stats->sm_nobj);
349 /* bytes allocated */
350 varnish_submit_derive (conf->instance, "sm", "total_bytes", "allocated", stats->sm_balloc);
352 varnish_submit_derive (conf->instance, "sm", "total_bytes", "free", stats->sm_bfree);
355 if (conf->collect_sma)
357 /* SMA allocator requests */
358 varnish_submit_derive (conf->instance, "sma", "total_requests", "nreq", stats->sma_nreq);
359 /* SMA outstanding allocations */
360 varnish_submit_gauge (conf->instance, "sma", "requests", "outstanding", stats->sma_nobj);
361 /* SMA outstanding bytes */
362 varnish_submit_gauge (conf->instance, "sma", "bytes", "outstanding", stats->sma_nbytes);
363 /* SMA bytes allocated */
364 varnish_submit_derive (conf->instance, "sma", "total_bytes", "allocated", stats->sma_balloc);
366 varnish_submit_derive (conf->instance, "sma", "total_bytes", "free" , stats->sma_bfree);
370 if (conf->collect_sms)
372 /* SMS allocator requests */
373 varnish_submit_derive (conf->instance, "sms", "total_requests", "allocator", stats->sms_nreq);
374 /* SMS outstanding allocations */
375 varnish_submit_gauge (conf->instance, "sms", "requests", "outstanding", stats->sms_nobj);
376 /* SMS outstanding bytes */
377 varnish_submit_gauge (conf->instance, "sms", "bytes", "outstanding", stats->sms_nbytes);
378 /* SMS bytes allocated */
379 varnish_submit_derive (conf->instance, "sms", "total_bytes", "allocated", stats->sms_balloc);
380 /* SMS bytes freed */
381 varnish_submit_derive (conf->instance, "sms", "total_bytes", "free", stats->sms_bfree);
384 if (conf->collect_struct)
386 /* N struct sess_mem */
387 varnish_submit_gauge (conf->instance, "struct", "current_sessions", "sess_mem", stats->n_sess_mem);
389 varnish_submit_gauge (conf->instance, "struct", "current_sessions", "sess", stats->n_sess);
390 /* N struct object */
391 varnish_submit_gauge (conf->instance, "struct", "objects", "object", stats->n_object);
392 #ifdef HAVE_VARNISH_V3
393 /* N unresurrected objects */
394 varnish_submit_gauge (conf->instance, "struct", "objects", "vampireobject", stats->n_vampireobject);
395 /* N struct objectcore */
396 varnish_submit_gauge (conf->instance, "struct", "objects", "objectcore", stats->n_objectcore);
398 /* N struct objecthead */
399 varnish_submit_gauge (conf->instance, "struct", "objects", "objecthead", stats->n_objecthead);
400 #ifdef HAVE_VARNISH_V2
402 varnish_submit_gauge (conf->instance, "struct", "objects", "smf", stats->n_smf);
403 /* N small free smf */
404 varnish_submit_gauge (conf->instance, "struct", "objects", "smf_frag", stats->n_smf_frag);
405 /* N large free smf */
406 varnish_submit_gauge (conf->instance, "struct", "objects", "smf_large", stats->n_smf_large);
407 /* N struct vbe_conn */
408 varnish_submit_gauge (conf->instance, "struct", "objects", "vbe_conn", stats->n_vbe_conn);
412 if (conf->collect_totals)
415 varnish_submit_derive (conf->instance, "totals", "total_sessions", "sessions", stats->s_sess);
417 varnish_submit_derive (conf->instance, "totals", "total_requests", "requests", stats->s_req);
419 varnish_submit_derive (conf->instance, "totals", "total_operations", "pipe", stats->s_pipe);
421 varnish_submit_derive (conf->instance, "totals", "total_operations", "pass", stats->s_pass);
423 varnish_submit_derive (conf->instance, "totals", "total_operations", "fetches", stats->s_fetch);
424 /* Total header bytes */
425 varnish_submit_derive (conf->instance, "totals", "total_bytes", "header-bytes", stats->s_hdrbytes);
426 /* Total body byte */
427 varnish_submit_derive (conf->instance, "totals", "total_bytes", "body-bytes", stats->s_bodybytes);
430 #ifdef HAVE_VARNISH_V3
431 if (conf->collect_uptime)
434 varnish_submit_gauge (conf->instance, "uptime", "uptime", "client_uptime", stats->uptime);
438 if (conf->collect_vcl)
441 varnish_submit_gauge (conf->instance, "vcl", "vcl", "total_vcl", stats->n_vcl);
442 /* N vcl available */
443 varnish_submit_gauge (conf->instance, "vcl", "vcl", "avail_vcl", stats->n_vcl_avail);
444 /* N vcl discarded */
445 varnish_submit_gauge (conf->instance, "vcl", "vcl", "discarded_vcl", stats->n_vcl_discard);
448 if (conf->collect_workers)
451 varnish_submit_gauge (conf->instance, "workers", "threads", "worker", stats->n_wrk);
452 /* worker threads created */
453 varnish_submit_derive (conf->instance, "workers", "total_threads", "created", stats->n_wrk_create);
454 /* worker threads not created */
455 varnish_submit_derive (conf->instance, "workers", "total_threads", "failed", stats->n_wrk_failed);
456 /* worker threads limited */
457 varnish_submit_derive (conf->instance, "workers", "total_threads", "limited", stats->n_wrk_max);
458 /* dropped work requests */
459 varnish_submit_derive (conf->instance, "workers", "total_requests", "dropped", stats->n_wrk_drop);
460 #ifdef HAVE_VARNISH_V2
461 /* queued work requests */
462 varnish_submit_derive (conf->instance, "workers", "total_requests", "queued", stats->n_wrk_queue);
463 /* overflowed work requests */
464 varnish_submit_derive (conf->instance, "workers", "total_requests", "overflowed", stats->n_wrk_overflow);
466 /* queued work requests */
467 varnish_submit_derive (conf->instance, "workers", "total_requests", "queued", stats->n_wrk_queued);
468 /* work request queue length */
469 varnish_submit_derive (conf->instance, "workers", "total_requests", "queue_length", stats->n_wrk_lqueue);
472 } /* }}} void varnish_monitor */
474 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
475 static int varnish_read (user_data_t *ud) /* {{{ */
478 const c_varnish_stats_t *stats;
482 if ((ud == NULL) || (ud->data == NULL))
492 if (conf->instance != NULL)
496 status = VSM_n_Arg (vd, conf->instance);
499 ERROR ("varnish plugin: VSM_n_Arg (\"%s\") failed "
501 conf->instance, status);
507 if (VSC_Open (vd, /* diag = */ 1))
508 #else /* if HAVE_VARNISH_V4 */
512 ERROR ("varnish plugin: Unable to load statistics.");
518 stats = VSC_Main(vd);
519 #else /* if HAVE_VARNISH_V4 */
520 stats = VSC_Main(vd, NULL);
523 varnish_monitor (conf, stats);
528 #else /* if HAVE_VARNISH_V2 */
529 static int varnish_read (user_data_t *ud) /* {{{ */
531 const c_varnish_stats_t *stats;
535 if ((ud == NULL) || (ud->data == NULL))
540 stats = VSL_OpenStats (conf->instance);
543 ERROR ("Varnish plugin : unable to load statistics");
548 varnish_monitor (conf, stats);
554 static void varnish_config_free (void *ptr) /* {{{ */
556 user_config_t *conf = ptr;
561 sfree (conf->instance);
565 static int varnish_config_apply_default (user_config_t *conf) /* {{{ */
570 conf->collect_backend = 1;
571 conf->collect_cache = 1;
572 conf->collect_connections = 1;
573 #ifdef HAVE_VARNISH_V3
574 conf->collect_dirdns = 0;
576 conf->collect_esi = 0;
577 conf->collect_fetch = 0;
578 conf->collect_hcb = 0;
579 conf->collect_objects = 0;
581 conf->collect_purge = 0;
583 conf->collect_ban = 0;
585 conf->collect_session = 0;
586 conf->collect_shm = 1;
588 conf->collect_sm = 0;
589 conf->collect_sma = 0;
591 conf->collect_sms = 0;
592 conf->collect_struct = 0;
593 conf->collect_totals = 0;
594 #ifdef HAVE_VARNISH_V3
595 conf->collect_uptime = 0;
597 conf->collect_vcl = 0;
598 conf->collect_workers = 0;
601 } /* }}} int varnish_config_apply_default */
603 static int varnish_init (void) /* {{{ */
611 conf = malloc (sizeof (*conf));
614 memset (conf, 0, sizeof (*conf));
616 /* Default settings: */
617 conf->instance = NULL;
619 varnish_config_apply_default (conf);
622 ud.free_func = varnish_config_free;
624 plugin_register_complex_read (/* group = */ "varnish",
625 /* name = */ "varnish/localhost",
626 /* callback = */ varnish_read,
627 /* interval = */ NULL,
628 /* user data = */ &ud);
631 } /* }}} int varnish_init */
633 static int varnish_config_instance (const oconfig_item_t *ci) /* {{{ */
637 char callback_name[DATA_MAX_NAME_LEN];
640 conf = malloc (sizeof (*conf));
643 memset (conf, 0, sizeof (*conf));
644 conf->instance = NULL;
646 varnish_config_apply_default (conf);
648 if (ci->values_num == 1)
652 status = cf_util_get_string (ci, &conf->instance);
658 assert (conf->instance != NULL);
660 if (strcmp ("localhost", conf->instance) == 0)
662 sfree (conf->instance);
663 conf->instance = NULL;
666 else if (ci->values_num > 1)
668 WARNING ("Varnish plugin: \"Instance\" blocks accept only "
673 for (i = 0; i < ci->children_num; i++)
675 oconfig_item_t *child = ci->children + i;
677 if (strcasecmp ("CollectCache", child->key) == 0)
678 cf_util_get_boolean (child, &conf->collect_cache);
679 else if (strcasecmp ("CollectConnections", child->key) == 0)
680 cf_util_get_boolean (child, &conf->collect_connections);
681 else if (strcasecmp ("CollectESI", child->key) == 0)
682 cf_util_get_boolean (child, &conf->collect_esi);
683 #ifdef HAVE_VARNISH_V3
684 else if (strcasecmp ("CollectDirectorDNS", child->key) == 0)
685 cf_util_get_boolean (child, &conf->collect_dirdns);
687 else if (strcasecmp ("CollectBackend", child->key) == 0)
688 cf_util_get_boolean (child, &conf->collect_backend);
689 else if (strcasecmp ("CollectFetch", child->key) == 0)
690 cf_util_get_boolean (child, &conf->collect_fetch);
691 else if (strcasecmp ("CollectHCB", child->key) == 0)
692 cf_util_get_boolean (child, &conf->collect_hcb);
693 else if (strcasecmp ("CollectObjects", child->key) == 0)
694 cf_util_get_boolean (child, &conf->collect_objects);
696 else if (strcasecmp ("CollectPurge", child->key) == 0)
697 cf_util_get_boolean (child, &conf->collect_purge);
699 else if (strcasecmp ("CollectBan", child->key) == 0)
700 cf_util_get_boolean (child, &conf->collect_ban);
702 else if (strcasecmp ("CollectSession", child->key) == 0)
703 cf_util_get_boolean (child, &conf->collect_session);
704 else if (strcasecmp ("CollectSHM", child->key) == 0)
705 cf_util_get_boolean (child, &conf->collect_shm);
706 else if (strcasecmp ("CollectSMS", child->key) == 0)
707 cf_util_get_boolean (child, &conf->collect_sms);
709 else if (strcasecmp ("CollectSMA", child->key) == 0)
710 cf_util_get_boolean (child, &conf->collect_sma);
711 else if (strcasecmp ("CollectSM", child->key) == 0)
712 cf_util_get_boolean (child, &conf->collect_sm);
714 else if (strcasecmp ("CollectStruct", child->key) == 0)
715 cf_util_get_boolean (child, &conf->collect_struct);
716 else if (strcasecmp ("CollectTotals", child->key) == 0)
717 cf_util_get_boolean (child, &conf->collect_totals);
718 #ifdef HAVE_VARNISH_V3
719 else if (strcasecmp ("CollectUptime", child->key) == 0)
720 cf_util_get_boolean (child, &conf->collect_uptime);
722 else if (strcasecmp ("CollectVCL", child->key) == 0)
723 cf_util_get_boolean (child, &conf->collect_vcl);
724 else if (strcasecmp ("CollectWorkers", child->key) == 0)
725 cf_util_get_boolean (child, &conf->collect_workers);
728 WARNING ("Varnish plugin: Ignoring unknown "
729 "configuration option: \"%s\". Did "
730 "you forget to add an <Instance /> "
731 "block around the configuration?",
736 if (!conf->collect_cache
737 && !conf->collect_connections
738 && !conf->collect_esi
739 && !conf->collect_backend
740 #ifdef HAVE_VARNISH_V3
741 && !conf->collect_dirdns
743 && !conf->collect_fetch
744 && !conf->collect_hcb
745 && !conf->collect_objects
747 && !conf->collect_purge
749 && !conf->collect_ban
751 && !conf->collect_session
752 && !conf->collect_shm
753 && !conf->collect_sms
755 && !conf->collect_sma
758 && !conf->collect_struct
759 && !conf->collect_totals
760 #ifdef HAVE_VARNISH_V3
761 && !conf->collect_uptime
763 && !conf->collect_vcl
764 && !conf->collect_workers)
766 WARNING ("Varnish plugin: No metric has been configured for "
767 "instance \"%s\". Disabling this instance.",
768 (conf->instance == NULL) ? "localhost" : conf->instance);
772 ssnprintf (callback_name, sizeof (callback_name), "varnish/%s",
773 (conf->instance == NULL) ? "localhost" : conf->instance);
776 ud.free_func = varnish_config_free;
778 plugin_register_complex_read (/* group = */ "varnish",
779 /* name = */ callback_name,
780 /* callback = */ varnish_read,
781 /* interval = */ NULL,
782 /* user data = */ &ud);
787 } /* }}} int varnish_config_instance */
789 static int varnish_config (oconfig_item_t *ci) /* {{{ */
793 for (i = 0; i < ci->children_num; i++)
795 oconfig_item_t *child = ci->children + i;
797 if (strcasecmp ("Instance", child->key) == 0)
798 varnish_config_instance (child);
801 WARNING ("Varnish plugin: Ignoring unknown "
802 "configuration option: \"%s\"",
808 } /* }}} int varnish_config */
810 void module_register (void) /* {{{ */
812 plugin_register_complex_config ("varnish", varnish_config);
813 plugin_register_init ("varnish", varnish_init);
816 /* vim: set sw=8 noet fdm=marker : */