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>
30 #include "configfile.h"
35 typedef struct VSC_C_main c_varnish_stats_t;
39 #include <varnishapi.h>
41 typedef struct VSC_C_main c_varnish_stats_t;
45 #include <varnishapi.h>
46 typedef struct varnish_stats c_varnish_stats_t;
49 /* {{{ user_config_s */
50 struct user_config_s {
54 _Bool collect_connections;
56 _Bool collect_backend;
57 #ifdef HAVE_VARNISH_V3
62 _Bool collect_objects;
68 _Bool collect_session;
77 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
81 _Bool collect_workers;
86 typedef struct user_config_s user_config_t; /* }}} */
88 static _Bool have_instance = 0;
90 static int varnish_submit (const char *plugin_instance, /* {{{ */
91 const char *category, const char *type, const char *type_instance, value_t value)
93 value_list_t vl = VALUE_LIST_INIT;
98 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
100 sstrncpy (vl.plugin, "varnish", sizeof (vl.plugin));
102 if (plugin_instance == NULL)
103 plugin_instance = "default";
105 ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance),
106 "%s-%s", plugin_instance, category);
108 sstrncpy (vl.type, type, sizeof (vl.type));
110 if (type_instance != NULL)
111 sstrncpy (vl.type_instance, type_instance,
112 sizeof (vl.type_instance));
114 return (plugin_dispatch_values (&vl));
115 } /* }}} int varnish_submit */
117 static int varnish_submit_gauge (const char *plugin_instance, /* {{{ */
118 const char *category, const char *type, const char *type_instance,
119 uint64_t gauge_value)
123 value.gauge = (gauge_t) gauge_value;
125 return (varnish_submit (plugin_instance, category, type, type_instance, value));
126 } /* }}} int varnish_submit_gauge */
128 static int varnish_submit_derive (const char *plugin_instance, /* {{{ */
129 const char *category, const char *type, const char *type_instance,
130 uint64_t derive_value)
134 value.derive = (derive_t) derive_value;
136 return (varnish_submit (plugin_instance, category, type, type_instance, value));
137 } /* }}} int varnish_submit_derive */
139 static void varnish_monitor (const user_config_t *conf, /* {{{ */
140 const c_varnish_stats_t *stats)
142 if (conf->collect_cache)
145 varnish_submit_derive (conf->instance, "cache", "cache_result", "hit", stats->cache_hit);
147 varnish_submit_derive (conf->instance, "cache", "cache_result", "miss", stats->cache_miss);
148 /* Cache hits for pass */
149 varnish_submit_derive (conf->instance, "cache", "cache_result", "hitpass", stats->cache_hitpass);
152 if (conf->collect_connections)
154 #ifndef HAVE_VARNISH_V4
155 /* Client connections accepted */
156 varnish_submit_derive (conf->instance, "connections", "connections", "accepted", stats->client_conn);
157 /* Connection dropped, no sess */
158 varnish_submit_derive (conf->instance, "connections", "connections", "dropped" , stats->client_drop);
160 /* Client requests received */
161 varnish_submit_derive (conf->instance, "connections", "connections", "received", stats->client_req);
164 #ifdef HAVE_VARNISH_V3
165 if (conf->collect_dirdns)
167 /* DNS director lookups */
168 varnish_submit_derive (conf->instance, "dirdns", "cache_operation", "lookups", stats->dir_dns_lookups);
169 /* DNS director failed lookups */
170 varnish_submit_derive (conf->instance, "dirdns", "cache_result", "failed", stats->dir_dns_failed);
171 /* DNS director cached lookups hit */
172 varnish_submit_derive (conf->instance, "dirdns", "cache_result", "hits", stats->dir_dns_hit);
173 /* DNS director full dnscache */
174 varnish_submit_derive (conf->instance, "dirdns", "cache_result", "cache_full", stats->dir_dns_cache_full);
178 if (conf->collect_esi)
180 /* ESI parse errors (unlock) */
181 varnish_submit_derive (conf->instance, "esi", "total_operations", "error", stats->esi_errors);
183 /* Objects ESI parsed (unlock) */
184 varnish_submit_derive (conf->instance, "esi", "total_operations", "parsed", stats->esi_parse);
186 /* ESI parse warnings (unlock) */
187 varnish_submit_derive (conf->instance, "esi", "total_operations", "warning", stats->esi_warnings);
191 if (conf->collect_backend)
193 /* Backend conn. success */
194 varnish_submit_derive (conf->instance, "backend", "connections", "success" , stats->backend_conn);
195 /* Backend conn. not attempted */
196 varnish_submit_derive (conf->instance, "backend", "connections", "not-attempted", stats->backend_unhealthy);
197 /* Backend conn. too many */
198 varnish_submit_derive (conf->instance, "backend", "connections", "too-many" , stats->backend_busy);
199 /* Backend conn. failures */
200 varnish_submit_derive (conf->instance, "backend", "connections", "failures" , stats->backend_fail);
201 /* Backend conn. reuses */
202 varnish_submit_derive (conf->instance, "backend", "connections", "reuses" , stats->backend_reuse);
203 /* Backend conn. was closed */
204 varnish_submit_derive (conf->instance, "backend", "connections", "was-closed" , stats->backend_toolate);
205 /* Backend conn. recycles */
206 varnish_submit_derive (conf->instance, "backend", "connections", "recycled" , stats->backend_recycle);
208 /* Backend conn. unused */
209 varnish_submit_derive (conf->instance, "backend", "connections", "unused" , stats->backend_unused);
211 /* Backend conn. retry */
212 varnish_submit_derive (conf->instance, "backend", "connections", "retries" , stats->backend_retry);
214 /* Backend requests mades */
215 varnish_submit_derive (conf->instance, "backend", "http_requests", "requests" , stats->backend_req);
217 varnish_submit_gauge (conf->instance, "backend", "backends", "n_backends" , stats->n_backend);
220 if (conf->collect_fetch)
223 varnish_submit_derive (conf->instance, "fetch", "http_requests", "head" , stats->fetch_head);
224 /* Fetch with length */
225 varnish_submit_derive (conf->instance, "fetch", "http_requests", "length" , stats->fetch_length);
227 varnish_submit_derive (conf->instance, "fetch", "http_requests", "chunked" , stats->fetch_chunked);
229 varnish_submit_derive (conf->instance, "fetch", "http_requests", "eof" , stats->fetch_eof);
230 /* Fetch bad headers */
231 varnish_submit_derive (conf->instance, "fetch", "http_requests", "bad_headers", stats->fetch_bad);
232 /* Fetch wanted close */
233 varnish_submit_derive (conf->instance, "fetch", "http_requests", "close" , stats->fetch_close);
234 /* Fetch pre HTTP/1.1 closed */
235 varnish_submit_derive (conf->instance, "fetch", "http_requests", "oldhttp" , stats->fetch_oldhttp);
237 varnish_submit_derive (conf->instance, "fetch", "http_requests", "zero" , stats->fetch_zero);
239 varnish_submit_derive (conf->instance, "fetch", "http_requests", "failed" , stats->fetch_failed);
240 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
241 /* Fetch no body (1xx) */
242 varnish_submit_derive (conf->instance, "fetch", "http_requests", "no_body_1xx", stats->fetch_1xx);
243 /* Fetch no body (204) */
244 varnish_submit_derive (conf->instance, "fetch", "http_requests", "no_body_204", stats->fetch_204);
245 /* Fetch no body (304) */
246 varnish_submit_derive (conf->instance, "fetch", "http_requests", "no_body_304", stats->fetch_304);
250 if (conf->collect_hcb)
252 /* HCB Lookups without lock */
253 varnish_submit_derive (conf->instance, "hcb", "cache_operation", "lookup_nolock", stats->hcb_nolock);
254 /* HCB Lookups with lock */
255 varnish_submit_derive (conf->instance, "hcb", "cache_operation", "lookup_lock", stats->hcb_lock);
257 varnish_submit_derive (conf->instance, "hcb", "cache_operation", "insert", stats->hcb_insert);
260 if (conf->collect_objects)
262 /* N expired objects */
263 varnish_submit_derive (conf->instance, "objects", "total_objects", "expired", stats->n_expired);
264 /* N LRU nuked objects */
265 varnish_submit_derive (conf->instance, "objects", "total_objects", "lru_nuked", stats->n_lru_nuked);
267 /* N LRU saved objects */
268 varnish_submit_derive (conf->instance, "objects", "total_objects", "lru_saved", stats->n_lru_saved);
270 /* N LRU moved objects */
271 varnish_submit_derive (conf->instance, "objects", "total_objects", "lru_moved", stats->n_lru_moved);
273 /* N objects on deathrow */
274 varnish_submit_derive (conf->instance, "objects", "total_objects", "deathrow", stats->n_deathrow);
276 /* HTTP header overflows */
277 varnish_submit_derive (conf->instance, "objects", "total_objects", "header_overflow", stats->losthdr);
279 /* N purged objects */
280 varnish_submit_derive (conf->instance, "objects", "total_objects", "purged", stats->n_obj_purged);
282 /* Objects sent with sendfile */
283 varnish_submit_derive (conf->instance, "objects", "total_objects", "sent_sendfile", stats->n_objsendfile);
284 /* Objects sent with write */
285 varnish_submit_derive (conf->instance, "objects", "total_objects", "sent_write", stats->n_objwrite);
286 /* Objects overflowing workspace */
287 varnish_submit_derive (conf->instance, "objects", "total_objects", "workspace_overflow", stats->n_objoverflow);
292 if (conf->collect_purge)
294 /* N total active purges */
295 varnish_submit_derive (conf->instance, "purge", "total_operations", "total", stats->n_purge);
296 /* N new purges added */
297 varnish_submit_derive (conf->instance, "purge", "total_operations", "added", stats->n_purge_add);
298 /* N old purges deleted */
299 varnish_submit_derive (conf->instance, "purge", "total_operations", "deleted", stats->n_purge_retire);
300 /* N objects tested */
301 varnish_submit_derive (conf->instance, "purge", "total_operations", "objects_tested", stats->n_purge_obj_test);
302 /* N regexps tested against */
303 varnish_submit_derive (conf->instance, "purge", "total_operations", "regexps_tested", stats->n_purge_re_test);
304 /* N duplicate purges removed */
305 varnish_submit_derive (conf->instance, "purge", "total_operations", "duplicate", stats->n_purge_dups);
309 if (conf->collect_ban)
311 /* N total active bans */
312 varnish_submit_derive (conf->instance, "ban", "total_operations", "total", stats->n_ban);
313 /* N new bans added */
314 varnish_submit_derive (conf->instance, "ban", "total_operations", "added", stats->n_ban_add);
315 /* N old bans deleted */
316 varnish_submit_derive (conf->instance, "ban", "total_operations", "deleted", stats->n_ban_retire);
317 /* N objects tested */
318 varnish_submit_derive (conf->instance, "ban", "total_operations", "objects_tested", stats->n_ban_obj_test);
319 /* N regexps tested against */
320 varnish_submit_derive (conf->instance, "ban", "total_operations", "regexps_tested", stats->n_ban_re_test);
321 /* N duplicate bans removed */
322 varnish_submit_derive (conf->instance, "ban", "total_operations", "duplicate", stats->n_ban_dups);
326 if (conf->collect_ban)
328 /* N total active bans */
329 varnish_submit_derive (conf->instance, "ban", "total_operations", "total", stats->bans);
330 /* N new bans added */
331 varnish_submit_derive (conf->instance, "ban", "total_operations", "added", stats->bans_added);
332 /* N bans using obj */
333 varnish_submit_derive (conf->instance, "ban", "total_operations", "obj", stats->bans_obj);
334 /* N bans using req */
335 varnish_submit_derive (conf->instance, "ban", "total_operations", "req", stats->bans_req);
336 /* N new bans completed */
337 varnish_submit_derive (conf->instance, "ban", "total_operations", "completed", stats->bans_completed);
338 /* N old bans deleted */
339 varnish_submit_derive (conf->instance, "ban", "total_operations", "deleted", stats->bans_deleted);
340 /* N objects tested */
341 varnish_submit_derive (conf->instance, "ban", "total_operations", "tested", stats->bans_tested);
342 /* N duplicate bans removed */
343 varnish_submit_derive (conf->instance, "ban", "total_operations", "duplicate", stats->bans_dups);
347 if (conf->collect_session)
350 varnish_submit_derive (conf->instance, "session", "total_operations", "closed", stats->sess_closed);
351 /* Session Pipeline */
352 varnish_submit_derive (conf->instance, "session", "total_operations", "pipeline", stats->sess_pipeline);
353 /* Session Read Ahead */
354 varnish_submit_derive (conf->instance, "session", "total_operations", "readahead", stats->sess_readahead);
356 /* Sessions accepted */
357 varnish_submit_derive (conf->instance, "session", "total_operations", "accepted", stats->sess_conn);
358 /* Sessions dropped for thread */
359 varnish_submit_derive (conf->instance, "session", "total_operations", "dropped", stats->sess_drop);
360 /* Sessions accept failure */
361 varnish_submit_derive (conf->instance, "session", "total_operations", "failed", stats->sess_fail);
362 /* Sessions pipe overflow */
363 varnish_submit_derive (conf->instance, "session", "total_operations", "overflow", stats->sess_pipe_overflow);
364 /* Sessions queued for thread */
365 varnish_submit_derive (conf->instance, "session", "total_operations", "queued", stats->sess_queued);
368 varnish_submit_derive (conf->instance, "session", "total_operations", "linger", stats->sess_linger);
371 varnish_submit_derive (conf->instance, "session", "total_operations", "herd", stats->sess_herd);
374 if (conf->collect_shm)
377 varnish_submit_derive (conf->instance, "shm", "total_operations", "records" , stats->shm_records);
379 varnish_submit_derive (conf->instance, "shm", "total_operations", "writes" , stats->shm_writes);
380 /* SHM flushes due to overflow */
381 varnish_submit_derive (conf->instance, "shm", "total_operations", "flushes" , stats->shm_flushes);
382 /* SHM MTX contention */
383 varnish_submit_derive (conf->instance, "shm", "total_operations", "contention", stats->shm_cont);
384 /* SHM cycles through buffer */
385 varnish_submit_derive (conf->instance, "shm", "total_operations", "cycles" , stats->shm_cycles);
389 if (conf->collect_sm)
391 /* allocator requests */
392 varnish_submit_derive (conf->instance, "sm", "total_requests", "nreq", stats->sm_nreq);
393 /* outstanding allocations */
394 varnish_submit_gauge (conf->instance, "sm", "requests", "outstanding", stats->sm_nobj);
395 /* bytes allocated */
396 varnish_submit_derive (conf->instance, "sm", "total_bytes", "allocated", stats->sm_balloc);
398 varnish_submit_derive (conf->instance, "sm", "total_bytes", "free", stats->sm_bfree);
401 if (conf->collect_sma)
403 /* SMA allocator requests */
404 varnish_submit_derive (conf->instance, "sma", "total_requests", "nreq", stats->sma_nreq);
405 /* SMA outstanding allocations */
406 varnish_submit_gauge (conf->instance, "sma", "requests", "outstanding", stats->sma_nobj);
407 /* SMA outstanding bytes */
408 varnish_submit_gauge (conf->instance, "sma", "bytes", "outstanding", stats->sma_nbytes);
409 /* SMA bytes allocated */
410 varnish_submit_derive (conf->instance, "sma", "total_bytes", "allocated", stats->sma_balloc);
412 varnish_submit_derive (conf->instance, "sma", "total_bytes", "free" , stats->sma_bfree);
416 if (conf->collect_sms)
418 /* SMS allocator requests */
419 varnish_submit_derive (conf->instance, "sms", "total_requests", "allocator", stats->sms_nreq);
420 /* SMS outstanding allocations */
421 varnish_submit_gauge (conf->instance, "sms", "requests", "outstanding", stats->sms_nobj);
422 /* SMS outstanding bytes */
423 varnish_submit_gauge (conf->instance, "sms", "bytes", "outstanding", stats->sms_nbytes);
424 /* SMS bytes allocated */
425 varnish_submit_derive (conf->instance, "sms", "total_bytes", "allocated", stats->sms_balloc);
426 /* SMS bytes freed */
427 varnish_submit_derive (conf->instance, "sms", "total_bytes", "free", stats->sms_bfree);
430 if (conf->collect_struct)
433 /* N struct sess_mem */
434 varnish_submit_gauge (conf->instance, "struct", "current_sessions", "sess_mem", stats->n_sess_mem);
436 varnish_submit_gauge (conf->instance, "struct", "current_sessions", "sess", stats->n_sess);
438 /* N struct object */
439 varnish_submit_gauge (conf->instance, "struct", "objects", "object", stats->n_object);
440 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
441 /* N unresurrected objects */
442 varnish_submit_gauge (conf->instance, "struct", "objects", "vampireobject", stats->n_vampireobject);
443 /* N struct objectcore */
444 varnish_submit_gauge (conf->instance, "struct", "objects", "objectcore", stats->n_objectcore);
445 /* N struct waitinglist */
446 varnish_submit_gauge (conf->instance, "struct", "objects", "waitinglist", stats->n_waitinglist);
448 /* N struct objecthead */
449 varnish_submit_gauge (conf->instance, "struct", "objects", "objecthead", stats->n_objecthead);
450 #ifdef HAVE_VARNISH_V2
452 varnish_submit_gauge (conf->instance, "struct", "objects", "smf", stats->n_smf);
453 /* N small free smf */
454 varnish_submit_gauge (conf->instance, "struct", "objects", "smf_frag", stats->n_smf_frag);
455 /* N large free smf */
456 varnish_submit_gauge (conf->instance, "struct", "objects", "smf_large", stats->n_smf_large);
457 /* N struct vbe_conn */
458 varnish_submit_gauge (conf->instance, "struct", "objects", "vbe_conn", stats->n_vbe_conn);
462 if (conf->collect_totals)
465 varnish_submit_derive (conf->instance, "totals", "total_sessions", "sessions", stats->s_sess);
467 varnish_submit_derive (conf->instance, "totals", "total_requests", "requests", stats->s_req);
469 varnish_submit_derive (conf->instance, "totals", "total_operations", "pipe", stats->s_pipe);
471 varnish_submit_derive (conf->instance, "totals", "total_operations", "pass", stats->s_pass);
473 varnish_submit_derive (conf->instance, "totals", "total_operations", "fetches", stats->s_fetch);
476 varnish_submit_derive (conf->instance, "totals", "total_bytes", "synth", stats->s_synth);
477 /* Request header bytes */
478 varnish_submit_derive (conf->instance, "totals", "total_bytes", "req_header", stats->s_req_hdrbytes);
479 /* Request body byte */
480 varnish_submit_derive (conf->instance, "totals", "total_bytes", "req_body", stats->s_req_bodybytes);
481 /* Response header bytes */
482 varnish_submit_derive (conf->instance, "totals", "total_bytes", "resp_header", stats->s_resp_hdrbytes);
483 /* Response body byte */
484 varnish_submit_derive (conf->instance, "totals", "total_bytes", "resp_body", stats->s_resp_bodybytes);
485 /* Pipe request header bytes */
486 varnish_submit_derive (conf->instance, "totals", "total_bytes", "pipe_header", stats->s_pipe_hdrbytes);
487 /* Piped bytes from client */
488 varnish_submit_derive (conf->instance, "totals", "total_bytes", "pipe_in", stats->s_pipe_in);
489 /* Piped bytes to client */
490 varnish_submit_derive (conf->instance, "totals", "total_bytes", "pipe_out", stats->s_pipe_out);
491 /* Number of purge operations */
492 varnish_submit_derive (conf->instance, "totals", "total_operations", "purges", stats->n_purges);
494 /* Total header bytes */
495 varnish_submit_derive (conf->instance, "totals", "total_bytes", "header-bytes", stats->s_hdrbytes);
496 /* Total body byte */
497 varnish_submit_derive (conf->instance, "totals", "total_bytes", "body-bytes", stats->s_bodybytes);
499 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
500 /* Gzip operations */
501 varnish_submit_derive (conf->instance, "totals", "total_operations", "gzip", stats->n_gzip);
502 /* Gunzip operations */
503 varnish_submit_derive (conf->instance, "totals", "total_operations", "gunzip", stats->n_gunzip);
507 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
508 if (conf->collect_uptime)
511 varnish_submit_gauge (conf->instance, "uptime", "uptime", "client_uptime", stats->uptime);
515 if (conf->collect_vcl)
518 varnish_submit_gauge (conf->instance, "vcl", "vcl", "total_vcl", stats->n_vcl);
519 /* N vcl available */
520 varnish_submit_gauge (conf->instance, "vcl", "vcl", "avail_vcl", stats->n_vcl_avail);
521 /* N vcl discarded */
522 varnish_submit_gauge (conf->instance, "vcl", "vcl", "discarded_vcl", stats->n_vcl_discard);
523 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
525 varnish_submit_gauge (conf->instance, "vcl", "objects", "vmod", stats->vmods);
529 if (conf->collect_workers)
531 #ifdef HAVE_VARNISH_V4
532 /* total number of threads */
533 varnish_submit_gauge (conf->instance, "workers", "threads", "worker", stats->threads);
534 /* threads created */
535 varnish_submit_derive (conf->instance, "workers", "total_threads", "created", stats->threads_created);
536 /* thread creation failed */
537 varnish_submit_derive (conf->instance, "workers", "total_threads", "failed", stats->threads_failed);
538 /* threads hit max */
539 varnish_submit_derive (conf->instance, "workers", "total_threads", "limited", stats->threads_limited);
540 /* threads destroyed */
541 varnish_submit_derive (conf->instance, "workers", "total_threads", "dropped", stats->threads_destroyed);
542 /* length of session queue */
543 varnish_submit_derive (conf->instance, "workers", "queue_length", "threads", stats->thread_queue_len);
546 varnish_submit_gauge (conf->instance, "workers", "threads", "worker", stats->n_wrk);
547 /* worker threads created */
548 varnish_submit_derive (conf->instance, "workers", "total_threads", "created", stats->n_wrk_create);
549 /* worker threads not created */
550 varnish_submit_derive (conf->instance, "workers", "total_threads", "failed", stats->n_wrk_failed);
551 /* worker threads limited */
552 varnish_submit_derive (conf->instance, "workers", "total_threads", "limited", stats->n_wrk_max);
553 /* dropped work requests */
554 varnish_submit_derive (conf->instance, "workers", "total_threads", "dropped", stats->n_wrk_drop);
555 #ifdef HAVE_VARNISH_V2
556 /* queued work requests */
557 varnish_submit_derive (conf->instance, "workers", "total_requests", "queued", stats->n_wrk_queue);
558 /* overflowed work requests */
559 varnish_submit_derive (conf->instance, "workers", "total_requests", "overflowed", stats->n_wrk_overflow);
560 #else /* HAVE_VARNISH_V3 */
561 /* queued work requests */
562 varnish_submit_derive (conf->instance, "workers", "total_requests", "queued", stats->n_wrk_queued);
563 /* work request queue length */
564 varnish_submit_derive (conf->instance, "workers", "total_requests", "queue_length", stats->n_wrk_lqueue);
570 if (conf->collect_vsm)
573 varnish_submit_gauge (conf->instance, "vsm", "bytes", "free", stats->vsm_free);
575 varnish_submit_gauge (conf->instance, "vsm", "bytes", "used", stats->vsm_used);
576 /* Cooling VSM space */
577 varnish_submit_gauge (conf->instance, "vsm", "bytes", "cooling", stats->vsm_cooling);
578 /* Overflow VSM space */
579 varnish_submit_gauge (conf->instance, "vsm", "bytes", "overflow", stats->vsm_overflow);
580 /* Total overflowed VSM space */
581 varnish_submit_derive (conf->instance, "vsm", "total_bytes", "overflowed", stats->vsm_overflowed);
585 } /* }}} void varnish_monitor */
587 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
588 static int varnish_read (user_data_t *ud) /* {{{ */
591 const c_varnish_stats_t *stats;
596 if ((ud == NULL) || (ud->data == NULL))
606 if (conf->instance != NULL)
610 status = VSM_n_Arg (vd, conf->instance);
614 ERROR ("varnish plugin: VSM_n_Arg (\"%s\") failed "
616 conf->instance, status);
622 test = VSC_Open (vd, /* diag = */ 1);
623 #else /* if HAVE_VARNISH_V4 */
624 test = VSM_Open (vd);
629 ERROR ("varnish plugin: Unable to open connection.");
635 stats = VSC_Main(vd);
636 #else /* if HAVE_VARNISH_V4 */
637 stats = VSC_Main(vd, NULL);
642 ERROR ("varnish plugin: Unable to get statistics.");
648 varnish_monitor (conf, stats);
653 #else /* if HAVE_VARNISH_V2 */
654 static int varnish_read (user_data_t *ud) /* {{{ */
656 const c_varnish_stats_t *stats;
660 if ((ud == NULL) || (ud->data == NULL))
665 stats = VSL_OpenStats (conf->instance);
668 ERROR ("Varnish plugin : unable to load statistics");
673 varnish_monitor (conf, stats);
679 static void varnish_config_free (void *ptr) /* {{{ */
681 user_config_t *conf = ptr;
686 sfree (conf->instance);
690 static int varnish_config_apply_default (user_config_t *conf) /* {{{ */
695 conf->collect_backend = 1;
696 conf->collect_cache = 1;
697 conf->collect_connections = 1;
698 #ifdef HAVE_VARNISH_V3
699 conf->collect_dirdns = 0;
701 conf->collect_esi = 0;
702 conf->collect_fetch = 0;
703 conf->collect_hcb = 0;
704 conf->collect_objects = 0;
706 conf->collect_purge = 0;
708 conf->collect_ban = 0;
710 conf->collect_session = 0;
711 conf->collect_shm = 1;
713 conf->collect_sm = 0;
714 conf->collect_sma = 0;
716 conf->collect_sms = 0;
717 conf->collect_struct = 0;
718 conf->collect_totals = 0;
719 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
720 conf->collect_uptime = 0;
722 conf->collect_vcl = 0;
723 conf->collect_workers = 0;
725 conf->collect_vsm = 0;
729 } /* }}} int varnish_config_apply_default */
731 static int varnish_init (void) /* {{{ */
739 conf = malloc (sizeof (*conf));
742 memset (conf, 0, sizeof (*conf));
744 /* Default settings: */
745 conf->instance = NULL;
747 varnish_config_apply_default (conf);
750 ud.free_func = varnish_config_free;
752 plugin_register_complex_read (/* group = */ "varnish",
753 /* name = */ "varnish/localhost",
754 /* callback = */ varnish_read,
756 /* user data = */ &ud);
759 } /* }}} int varnish_init */
761 static int varnish_config_instance (const oconfig_item_t *ci) /* {{{ */
765 char callback_name[DATA_MAX_NAME_LEN];
768 conf = malloc (sizeof (*conf));
771 memset (conf, 0, sizeof (*conf));
772 conf->instance = NULL;
774 varnish_config_apply_default (conf);
776 if (ci->values_num == 1)
780 status = cf_util_get_string (ci, &conf->instance);
786 assert (conf->instance != NULL);
788 if (strcmp ("localhost", conf->instance) == 0)
790 sfree (conf->instance);
791 conf->instance = NULL;
794 else if (ci->values_num > 1)
796 WARNING ("Varnish plugin: \"Instance\" blocks accept only "
801 for (i = 0; i < ci->children_num; i++)
803 oconfig_item_t *child = ci->children + i;
805 if (strcasecmp ("CollectCache", child->key) == 0)
806 cf_util_get_boolean (child, &conf->collect_cache);
807 else if (strcasecmp ("CollectConnections", child->key) == 0)
808 cf_util_get_boolean (child, &conf->collect_connections);
809 else if (strcasecmp ("CollectESI", child->key) == 0)
810 cf_util_get_boolean (child, &conf->collect_esi);
811 #ifdef HAVE_VARNISH_V3
812 else if (strcasecmp ("CollectDirectorDNS", child->key) == 0)
813 cf_util_get_boolean (child, &conf->collect_dirdns);
815 else if (strcasecmp ("CollectBackend", child->key) == 0)
816 cf_util_get_boolean (child, &conf->collect_backend);
817 else if (strcasecmp ("CollectFetch", child->key) == 0)
818 cf_util_get_boolean (child, &conf->collect_fetch);
819 else if (strcasecmp ("CollectHCB", child->key) == 0)
820 cf_util_get_boolean (child, &conf->collect_hcb);
821 else if (strcasecmp ("CollectObjects", child->key) == 0)
822 cf_util_get_boolean (child, &conf->collect_objects);
824 else if (strcasecmp ("CollectPurge", child->key) == 0)
825 cf_util_get_boolean (child, &conf->collect_purge);
827 else if (strcasecmp ("CollectBan", child->key) == 0)
828 cf_util_get_boolean (child, &conf->collect_ban);
830 else if (strcasecmp ("CollectSession", child->key) == 0)
831 cf_util_get_boolean (child, &conf->collect_session);
832 else if (strcasecmp ("CollectSHM", child->key) == 0)
833 cf_util_get_boolean (child, &conf->collect_shm);
834 else if (strcasecmp ("CollectSMS", child->key) == 0)
835 cf_util_get_boolean (child, &conf->collect_sms);
837 else if (strcasecmp ("CollectSMA", child->key) == 0)
838 cf_util_get_boolean (child, &conf->collect_sma);
839 else if (strcasecmp ("CollectSM", child->key) == 0)
840 cf_util_get_boolean (child, &conf->collect_sm);
842 else if (strcasecmp ("CollectStruct", child->key) == 0)
843 cf_util_get_boolean (child, &conf->collect_struct);
844 else if (strcasecmp ("CollectTotals", child->key) == 0)
845 cf_util_get_boolean (child, &conf->collect_totals);
846 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
847 else if (strcasecmp ("CollectUptime", child->key) == 0)
848 cf_util_get_boolean (child, &conf->collect_uptime);
850 else if (strcasecmp ("CollectVCL", child->key) == 0)
851 cf_util_get_boolean (child, &conf->collect_vcl);
852 else if (strcasecmp ("CollectWorkers", child->key) == 0)
853 cf_util_get_boolean (child, &conf->collect_workers);
855 else if (strcasecmp ("CollectVSM", child->key) == 0)
856 cf_util_get_boolean (child, &conf->collect_vsm);
860 WARNING ("Varnish plugin: Ignoring unknown "
861 "configuration option: \"%s\". Did "
862 "you forget to add an <Instance /> "
863 "block around the configuration?",
868 if (!conf->collect_cache
869 && !conf->collect_connections
870 && !conf->collect_esi
871 && !conf->collect_backend
872 #ifdef HAVE_VARNISH_V3
873 && !conf->collect_dirdns
875 && !conf->collect_fetch
876 && !conf->collect_hcb
877 && !conf->collect_objects
879 && !conf->collect_purge
881 && !conf->collect_ban
883 && !conf->collect_session
884 && !conf->collect_shm
885 && !conf->collect_sms
887 && !conf->collect_sma
890 && !conf->collect_struct
891 && !conf->collect_totals
892 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
893 && !conf->collect_uptime
895 && !conf->collect_vcl
896 && !conf->collect_workers
898 && !conf->collect_vsm
902 WARNING ("Varnish plugin: No metric has been configured for "
903 "instance \"%s\". Disabling this instance.",
904 (conf->instance == NULL) ? "localhost" : conf->instance);
908 ssnprintf (callback_name, sizeof (callback_name), "varnish/%s",
909 (conf->instance == NULL) ? "localhost" : conf->instance);
912 ud.free_func = varnish_config_free;
914 plugin_register_complex_read (/* group = */ "varnish",
915 /* name = */ callback_name,
916 /* callback = */ varnish_read,
918 /* user data = */ &ud);
923 } /* }}} int varnish_config_instance */
925 static int varnish_config (oconfig_item_t *ci) /* {{{ */
929 for (i = 0; i < ci->children_num; i++)
931 oconfig_item_t *child = ci->children + i;
933 if (strcasecmp ("Instance", child->key) == 0)
934 varnish_config_instance (child);
937 WARNING ("Varnish plugin: Ignoring unknown "
938 "configuration option: \"%s\"",
944 } /* }}} int varnish_config */
946 void module_register (void) /* {{{ */
948 plugin_register_complex_config ("varnish", varnish_config);
949 plugin_register_init ("varnish", varnish_init);
952 /* vim: set sw=8 noet fdm=marker : */