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 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
80 _Bool collect_workers;
85 typedef struct user_config_s user_config_t; /* }}} */
87 static _Bool have_instance = 0;
89 static int varnish_submit (const char *plugin_instance, /* {{{ */
90 const char *category, const char *type, const char *type_instance, value_t value)
92 value_list_t vl = VALUE_LIST_INIT;
97 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
99 sstrncpy (vl.plugin, "varnish", sizeof (vl.plugin));
101 if (plugin_instance == NULL)
102 plugin_instance = "default";
104 ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance),
105 "%s-%s", plugin_instance, category);
107 sstrncpy (vl.type, type, sizeof (vl.type));
109 if (type_instance != NULL)
110 sstrncpy (vl.type_instance, type_instance,
111 sizeof (vl.type_instance));
113 return (plugin_dispatch_values (&vl));
114 } /* }}} int varnish_submit */
116 static int varnish_submit_gauge (const char *plugin_instance, /* {{{ */
117 const char *category, const char *type, const char *type_instance,
118 uint64_t gauge_value)
122 value.gauge = (gauge_t) gauge_value;
124 return (varnish_submit (plugin_instance, category, type, type_instance, value));
125 } /* }}} int varnish_submit_gauge */
127 static int varnish_submit_derive (const char *plugin_instance, /* {{{ */
128 const char *category, const char *type, const char *type_instance,
129 uint64_t derive_value)
133 value.derive = (derive_t) derive_value;
135 return (varnish_submit (plugin_instance, category, type, type_instance, value));
136 } /* }}} int varnish_submit_derive */
138 static void varnish_monitor (const user_config_t *conf, /* {{{ */
139 const c_varnish_stats_t *stats)
141 if (conf->collect_cache)
144 varnish_submit_derive (conf->instance, "cache", "cache_result", "hit", stats->cache_hit);
146 varnish_submit_derive (conf->instance, "cache", "cache_result", "miss", stats->cache_miss);
147 /* Cache hits for pass */
148 varnish_submit_derive (conf->instance, "cache", "cache_result", "hitpass", stats->cache_hitpass);
151 if (conf->collect_connections)
153 #ifndef HAVE_VARNISH_V4
154 /* Client connections accepted */
155 varnish_submit_derive (conf->instance, "connections", "connections", "accepted", stats->client_conn);
156 /* Connection dropped, no sess */
157 varnish_submit_derive (conf->instance, "connections", "connections", "dropped" , stats->client_drop);
159 /* Client requests received */
160 varnish_submit_derive (conf->instance, "connections", "connections", "received", stats->client_req);
163 #ifdef HAVE_VARNISH_V3
164 if (conf->collect_dirdns)
166 /* DNS director lookups */
167 varnish_submit_derive (conf->instance, "dirdns", "cache_operation", "lookups", stats->dir_dns_lookups);
168 /* DNS director failed lookups */
169 varnish_submit_derive (conf->instance, "dirdns", "cache_result", "failed", stats->dir_dns_failed);
170 /* DNS director cached lookups hit */
171 varnish_submit_derive (conf->instance, "dirdns", "cache_result", "hits", stats->dir_dns_hit);
172 /* DNS director full dnscache */
173 varnish_submit_derive (conf->instance, "dirdns", "cache_result", "cache_full", stats->dir_dns_cache_full);
177 if (conf->collect_esi)
179 /* ESI parse errors (unlock) */
180 varnish_submit_derive (conf->instance, "esi", "total_operations", "error", stats->esi_errors);
182 /* Objects ESI parsed (unlock) */
183 varnish_submit_derive (conf->instance, "esi", "total_operations", "parsed", stats->esi_parse);
185 /* ESI parse warnings (unlock) */
186 varnish_submit_derive (conf->instance, "esi", "total_operations", "warning", stats->esi_warnings);
190 if (conf->collect_backend)
192 /* Backend conn. success */
193 varnish_submit_derive (conf->instance, "backend", "connections", "success" , stats->backend_conn);
194 /* Backend conn. not attempted */
195 varnish_submit_derive (conf->instance, "backend", "connections", "not-attempted", stats->backend_unhealthy);
196 /* Backend conn. too many */
197 varnish_submit_derive (conf->instance, "backend", "connections", "too-many" , stats->backend_busy);
198 /* Backend conn. failures */
199 varnish_submit_derive (conf->instance, "backend", "connections", "failures" , stats->backend_fail);
200 /* Backend conn. reuses */
201 varnish_submit_derive (conf->instance, "backend", "connections", "reuses" , stats->backend_reuse);
202 /* Backend conn. was closed */
203 varnish_submit_derive (conf->instance, "backend", "connections", "was-closed" , stats->backend_toolate);
204 /* Backend conn. recycles */
205 varnish_submit_derive (conf->instance, "backend", "connections", "recycled" , stats->backend_recycle);
207 /* Backend conn. unused */
208 varnish_submit_derive (conf->instance, "backend", "connections", "unused" , stats->backend_unused);
210 /* Backend conn. retry */
211 varnish_submit_derive (conf->instance, "backend", "connections", "retries" , stats->backend_retry);
213 /* Backend requests mades */
214 varnish_submit_derive (conf->instance, "backend", "http_requests", "requests" , stats->backend_req);
216 varnish_submit_gauge (conf->instance, "backend", "backends", "n_backends" , stats->n_backend);
219 if (conf->collect_fetch)
222 varnish_submit_derive (conf->instance, "fetch", "http_requests", "head" , stats->fetch_head);
223 /* Fetch with length */
224 varnish_submit_derive (conf->instance, "fetch", "http_requests", "length" , stats->fetch_length);
226 varnish_submit_derive (conf->instance, "fetch", "http_requests", "chunked" , stats->fetch_chunked);
228 varnish_submit_derive (conf->instance, "fetch", "http_requests", "eof" , stats->fetch_eof);
229 /* Fetch bad headers */
230 varnish_submit_derive (conf->instance, "fetch", "http_requests", "bad_headers", stats->fetch_bad);
231 /* Fetch wanted close */
232 varnish_submit_derive (conf->instance, "fetch", "http_requests", "close" , stats->fetch_close);
233 /* Fetch pre HTTP/1.1 closed */
234 varnish_submit_derive (conf->instance, "fetch", "http_requests", "oldhttp" , stats->fetch_oldhttp);
236 varnish_submit_derive (conf->instance, "fetch", "http_requests", "zero" , stats->fetch_zero);
238 varnish_submit_derive (conf->instance, "fetch", "http_requests", "failed" , stats->fetch_failed);
239 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
240 /* Fetch no body (1xx) */
241 varnish_submit_derive (conf->instance, "fetch", "http_requests", "no_body_1xx", stats->fetch_1xx);
242 /* Fetch no body (204) */
243 varnish_submit_derive (conf->instance, "fetch", "http_requests", "no_body_204", stats->fetch_204);
244 /* Fetch no body (304) */
245 varnish_submit_derive (conf->instance, "fetch", "http_requests", "no_body_304", stats->fetch_304);
249 if (conf->collect_hcb)
251 /* HCB Lookups without lock */
252 varnish_submit_derive (conf->instance, "hcb", "cache_operation", "lookup_nolock", stats->hcb_nolock);
253 /* HCB Lookups with lock */
254 varnish_submit_derive (conf->instance, "hcb", "cache_operation", "lookup_lock", stats->hcb_lock);
256 varnish_submit_derive (conf->instance, "hcb", "cache_operation", "insert", stats->hcb_insert);
259 if (conf->collect_objects)
261 /* N expired objects */
262 varnish_submit_derive (conf->instance, "objects", "total_objects", "expired", stats->n_expired);
263 /* N LRU nuked objects */
264 varnish_submit_derive (conf->instance, "objects", "total_objects", "lru_nuked", stats->n_lru_nuked);
266 /* N LRU saved objects */
267 varnish_submit_derive (conf->instance, "objects", "total_objects", "lru_saved", stats->n_lru_saved);
269 /* N LRU moved objects */
270 varnish_submit_derive (conf->instance, "objects", "total_objects", "lru_moved", stats->n_lru_moved);
272 /* N objects on deathrow */
273 varnish_submit_derive (conf->instance, "objects", "total_objects", "deathrow", stats->n_deathrow);
275 /* HTTP header overflows */
276 varnish_submit_derive (conf->instance, "objects", "total_objects", "header_overflow", stats->losthdr);
278 /* N purged objects */
279 varnish_submit_derive (conf->instance, "objects", "total_objects", "purged", stats->n_obj_purged);
281 /* Objects sent with sendfile */
282 varnish_submit_derive (conf->instance, "objects", "total_objects", "sent_sendfile", stats->n_objsendfile);
283 /* Objects sent with write */
284 varnish_submit_derive (conf->instance, "objects", "total_objects", "sent_write", stats->n_objwrite);
285 /* Objects overflowing workspace */
286 varnish_submit_derive (conf->instance, "objects", "total_objects", "workspace_overflow", stats->n_objoverflow);
291 if (conf->collect_purge)
293 /* N total active purges */
294 varnish_submit_derive (conf->instance, "purge", "total_operations", "total", stats->n_purge);
295 /* N new purges added */
296 varnish_submit_derive (conf->instance, "purge", "total_operations", "added", stats->n_purge_add);
297 /* N old purges deleted */
298 varnish_submit_derive (conf->instance, "purge", "total_operations", "deleted", stats->n_purge_retire);
299 /* N objects tested */
300 varnish_submit_derive (conf->instance, "purge", "total_operations", "objects_tested", stats->n_purge_obj_test);
301 /* N regexps tested against */
302 varnish_submit_derive (conf->instance, "purge", "total_operations", "regexps_tested", stats->n_purge_re_test);
303 /* N duplicate purges removed */
304 varnish_submit_derive (conf->instance, "purge", "total_operations", "duplicate", stats->n_purge_dups);
308 if (conf->collect_ban)
310 /* N total active bans */
311 varnish_submit_derive (conf->instance, "ban", "total_operations", "total", stats->n_ban);
312 /* N new bans added */
313 varnish_submit_derive (conf->instance, "ban", "total_operations", "added", stats->n_ban_add);
314 /* N old bans deleted */
315 varnish_submit_derive (conf->instance, "ban", "total_operations", "deleted", stats->n_ban_retire);
316 /* N objects tested */
317 varnish_submit_derive (conf->instance, "ban", "total_operations", "objects_tested", stats->n_ban_obj_test);
318 /* N regexps tested against */
319 varnish_submit_derive (conf->instance, "ban", "total_operations", "regexps_tested", stats->n_ban_re_test);
320 /* N duplicate bans removed */
321 varnish_submit_derive (conf->instance, "ban", "total_operations", "duplicate", stats->n_ban_dups);
325 if (conf->collect_ban)
327 /* N total active bans */
328 varnish_submit_derive (conf->instance, "ban", "total_operations", "total", stats->bans);
329 /* N new bans added */
330 varnish_submit_derive (conf->instance, "ban", "total_operations", "added", stats->bans_added);
331 /* N bans using obj */
332 varnish_submit_derive (conf->instance, "ban", "total_operations", "obj", stats->bans_obj);
333 /* N bans using req */
334 varnish_submit_derive (conf->instance, "ban", "total_operations", "req", stats->bans_req);
335 /* N new bans completed */
336 varnish_submit_derive (conf->instance, "ban", "total_operations", "completed", stats->bans_completed);
337 /* N old bans deleted */
338 varnish_submit_derive (conf->instance, "ban", "total_operations", "deleted", stats->bans_deleted);
339 /* N objects tested */
340 varnish_submit_derive (conf->instance, "ban", "total_operations", "tested", stats->bans_tested);
341 /* N duplicate bans removed */
342 varnish_submit_derive (conf->instance, "ban", "total_operations", "duplicate", stats->bans_dups);
346 if (conf->collect_session)
349 varnish_submit_derive (conf->instance, "session", "total_operations", "closed", stats->sess_closed);
350 /* Session Pipeline */
351 varnish_submit_derive (conf->instance, "session", "total_operations", "pipeline", stats->sess_pipeline);
352 /* Session Read Ahead */
353 varnish_submit_derive (conf->instance, "session", "total_operations", "readahead", stats->sess_readahead);
355 /* Sessions accepted */
356 varnish_submit_derive (conf->instance, "session", "total_operations", "accepted", stats->sess_conn);
357 /* Sessions dropped for thread */
358 varnish_submit_derive (conf->instance, "session", "total_operations", "dropped", stats->sess_drop);
359 /* Sessions accept failure */
360 varnish_submit_derive (conf->instance, "session", "total_operations", "failed", stats->sess_fail);
361 /* Sessions pipe overflow */
362 varnish_submit_derive (conf->instance, "session", "total_operations", "overflow", stats->sess_pipe_overflow);
363 /* Sessions queued for thread */
364 varnish_submit_derive (conf->instance, "session", "total_operations", "queued", stats->sess_queued);
367 varnish_submit_derive (conf->instance, "session", "total_operations", "linger", stats->sess_linger);
370 varnish_submit_derive (conf->instance, "session", "total_operations", "herd", stats->sess_herd);
373 if (conf->collect_shm)
376 varnish_submit_derive (conf->instance, "shm", "total_operations", "records" , stats->shm_records);
378 varnish_submit_derive (conf->instance, "shm", "total_operations", "writes" , stats->shm_writes);
379 /* SHM flushes due to overflow */
380 varnish_submit_derive (conf->instance, "shm", "total_operations", "flushes" , stats->shm_flushes);
381 /* SHM MTX contention */
382 varnish_submit_derive (conf->instance, "shm", "total_operations", "contention", stats->shm_cont);
383 /* SHM cycles through buffer */
384 varnish_submit_derive (conf->instance, "shm", "total_operations", "cycles" , stats->shm_cycles);
388 if (conf->collect_sm)
390 /* allocator requests */
391 varnish_submit_derive (conf->instance, "sm", "total_requests", "nreq", stats->sm_nreq);
392 /* outstanding allocations */
393 varnish_submit_gauge (conf->instance, "sm", "requests", "outstanding", stats->sm_nobj);
394 /* bytes allocated */
395 varnish_submit_derive (conf->instance, "sm", "total_bytes", "allocated", stats->sm_balloc);
397 varnish_submit_derive (conf->instance, "sm", "total_bytes", "free", stats->sm_bfree);
400 if (conf->collect_sma)
402 /* SMA allocator requests */
403 varnish_submit_derive (conf->instance, "sma", "total_requests", "nreq", stats->sma_nreq);
404 /* SMA outstanding allocations */
405 varnish_submit_gauge (conf->instance, "sma", "requests", "outstanding", stats->sma_nobj);
406 /* SMA outstanding bytes */
407 varnish_submit_gauge (conf->instance, "sma", "bytes", "outstanding", stats->sma_nbytes);
408 /* SMA bytes allocated */
409 varnish_submit_derive (conf->instance, "sma", "total_bytes", "allocated", stats->sma_balloc);
411 varnish_submit_derive (conf->instance, "sma", "total_bytes", "free" , stats->sma_bfree);
415 if (conf->collect_sms)
417 /* SMS allocator requests */
418 varnish_submit_derive (conf->instance, "sms", "total_requests", "allocator", stats->sms_nreq);
419 /* SMS outstanding allocations */
420 varnish_submit_gauge (conf->instance, "sms", "requests", "outstanding", stats->sms_nobj);
421 /* SMS outstanding bytes */
422 varnish_submit_gauge (conf->instance, "sms", "bytes", "outstanding", stats->sms_nbytes);
423 /* SMS bytes allocated */
424 varnish_submit_derive (conf->instance, "sms", "total_bytes", "allocated", stats->sms_balloc);
425 /* SMS bytes freed */
426 varnish_submit_derive (conf->instance, "sms", "total_bytes", "free", stats->sms_bfree);
429 if (conf->collect_struct)
432 /* N struct sess_mem */
433 varnish_submit_gauge (conf->instance, "struct", "current_sessions", "sess_mem", stats->n_sess_mem);
435 varnish_submit_gauge (conf->instance, "struct", "current_sessions", "sess", stats->n_sess);
437 /* N struct object */
438 varnish_submit_gauge (conf->instance, "struct", "objects", "object", stats->n_object);
439 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
440 /* N unresurrected objects */
441 varnish_submit_gauge (conf->instance, "struct", "objects", "vampireobject", stats->n_vampireobject);
442 /* N struct objectcore */
443 varnish_submit_gauge (conf->instance, "struct", "objects", "objectcore", stats->n_objectcore);
444 /* N struct waitinglist */
445 varnish_submit_gauge (conf->instance, "struct", "objects", "waitinglist", stats->n_waitinglist);
447 /* N struct objecthead */
448 varnish_submit_gauge (conf->instance, "struct", "objects", "objecthead", stats->n_objecthead);
449 #ifdef HAVE_VARNISH_V2
451 varnish_submit_gauge (conf->instance, "struct", "objects", "smf", stats->n_smf);
452 /* N small free smf */
453 varnish_submit_gauge (conf->instance, "struct", "objects", "smf_frag", stats->n_smf_frag);
454 /* N large free smf */
455 varnish_submit_gauge (conf->instance, "struct", "objects", "smf_large", stats->n_smf_large);
456 /* N struct vbe_conn */
457 varnish_submit_gauge (conf->instance, "struct", "objects", "vbe_conn", stats->n_vbe_conn);
461 if (conf->collect_totals)
464 varnish_submit_derive (conf->instance, "totals", "total_sessions", "sessions", stats->s_sess);
466 varnish_submit_derive (conf->instance, "totals", "total_requests", "requests", stats->s_req);
468 varnish_submit_derive (conf->instance, "totals", "total_operations", "pipe", stats->s_pipe);
470 varnish_submit_derive (conf->instance, "totals", "total_operations", "pass", stats->s_pass);
472 varnish_submit_derive (conf->instance, "totals", "total_operations", "fetches", stats->s_fetch);
475 varnish_submit_derive (conf->instance, "totals", "total_bytes", "synth", stats->s_synth);
476 /* Request header bytes */
477 varnish_submit_derive (conf->instance, "totals", "total_bytes", "req_header", stats->s_req_hdrbytes);
478 /* Request body byte */
479 varnish_submit_derive (conf->instance, "totals", "total_bytes", "req_body", stats->s_req_bodybytes);
480 /* Response header bytes */
481 varnish_submit_derive (conf->instance, "totals", "total_bytes", "resp_header", stats->s_resp_hdrbytes);
482 /* Response body byte */
483 varnish_submit_derive (conf->instance, "totals", "total_bytes", "resp_body", stats->s_resp_bodybytes);
484 /* Pipe request header bytes */
485 varnish_submit_derive (conf->instance, "totals", "total_bytes", "pipe_header", stats->s_pipe_hdrbytes);
486 /* Piped bytes from client */
487 varnish_submit_derive (conf->instance, "totals", "total_bytes", "pipe_in", stats->s_pipe_in);
488 /* Piped bytes to client */
489 varnish_submit_derive (conf->instance, "totals", "total_bytes", "pipe_out", stats->s_pipe_out);
490 /* Number of purge operations */
491 varnish_submit_derive (conf->instance, "totals", "total_operations", "purges", stats->n_purges);
493 /* Total header bytes */
494 varnish_submit_derive (conf->instance, "totals", "total_bytes", "header-bytes", stats->s_hdrbytes);
495 /* Total body byte */
496 varnish_submit_derive (conf->instance, "totals", "total_bytes", "body-bytes", stats->s_bodybytes);
498 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
499 /* Gzip operations */
500 varnish_submit_derive (conf->instance, "totals", "total_operations", "gzip", stats->n_gzip);
501 /* Gunzip operations */
502 varnish_submit_derive (conf->instance, "totals", "total_operations", "gunzip", stats->n_gunzip);
506 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
507 if (conf->collect_uptime)
510 varnish_submit_gauge (conf->instance, "uptime", "uptime", "client_uptime", stats->uptime);
514 if (conf->collect_vcl)
517 varnish_submit_gauge (conf->instance, "vcl", "vcl", "total_vcl", stats->n_vcl);
518 /* N vcl available */
519 varnish_submit_gauge (conf->instance, "vcl", "vcl", "avail_vcl", stats->n_vcl_avail);
520 /* N vcl discarded */
521 varnish_submit_gauge (conf->instance, "vcl", "vcl", "discarded_vcl", stats->n_vcl_discard);
522 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
524 varnish_submit_gauge (conf->instance, "vcl", "objects", "vmod", stats->vmods);
528 if (conf->collect_workers)
530 #ifdef HAVE_VARNISH_V4
531 /* total number of threads */
532 varnish_submit_gauge (conf->instance, "workers", "threads", "worker", stats->threads);
533 /* threads created */
534 varnish_submit_derive (conf->instance, "workers", "total_threads", "created", stats->threads_created);
535 /* thread creation failed */
536 varnish_submit_derive (conf->instance, "workers", "total_threads", "failed", stats->threads_failed);
537 /* threads hit max */
538 varnish_submit_derive (conf->instance, "workers", "total_threads", "limited", stats->threads_limited);
539 /* threads destroyed */
540 varnish_submit_derive (conf->instance, "workers", "total_threads", "dropped", stats->threads_destroyed);
541 /* length of session queue */
542 varnish_submit_derive (conf->instance, "workers", "queue_length", "threads", stats->thread_queue_len);
545 varnish_submit_gauge (conf->instance, "workers", "threads", "worker", stats->n_wrk);
546 /* worker threads created */
547 varnish_submit_derive (conf->instance, "workers", "total_threads", "created", stats->n_wrk_create);
548 /* worker threads not created */
549 varnish_submit_derive (conf->instance, "workers", "total_threads", "failed", stats->n_wrk_failed);
550 /* worker threads limited */
551 varnish_submit_derive (conf->instance, "workers", "total_threads", "limited", stats->n_wrk_max);
552 /* dropped work requests */
553 varnish_submit_derive (conf->instance, "workers", "total_threads", "dropped", stats->n_wrk_drop);
554 #ifdef HAVE_VARNISH_V2
555 /* queued work requests */
556 varnish_submit_derive (conf->instance, "workers", "total_requests", "queued", stats->n_wrk_queue);
557 /* overflowed work requests */
558 varnish_submit_derive (conf->instance, "workers", "total_requests", "overflowed", stats->n_wrk_overflow);
559 #else /* HAVE_VARNISH_V3 */
560 /* queued work requests */
561 varnish_submit_derive (conf->instance, "workers", "total_requests", "queued", stats->n_wrk_queued);
562 /* work request queue length */
563 varnish_submit_derive (conf->instance, "workers", "total_requests", "queue_length", stats->n_wrk_lqueue);
569 if (conf->collect_vsm)
572 varnish_submit_gauge (conf->instance, "vsm", "bytes", "free", stats->vsm_free);
574 varnish_submit_gauge (conf->instance, "vsm", "bytes", "used", stats->vsm_used);
575 /* Cooling VSM space */
576 varnish_submit_gauge (conf->instance, "vsm", "bytes", "cooling", stats->vsm_cooling);
577 /* Overflow VSM space */
578 varnish_submit_gauge (conf->instance, "vsm", "bytes", "overflow", stats->vsm_overflow);
579 /* Total overflowed VSM space */
580 varnish_submit_derive (conf->instance, "vsm", "total_bytes", "overflowed", stats->vsm_overflowed);
584 } /* }}} void varnish_monitor */
586 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
587 static int varnish_read (user_data_t *ud) /* {{{ */
590 const c_varnish_stats_t *stats;
594 if ((ud == NULL) || (ud->data == NULL))
604 if (conf->instance != NULL)
608 status = VSM_n_Arg (vd, conf->instance);
611 ERROR ("varnish plugin: VSM_n_Arg (\"%s\") failed "
613 conf->instance, status);
619 if (VSC_Open (vd, /* diag = */ 1))
620 #else /* if HAVE_VARNISH_V4 */
624 ERROR ("varnish plugin: Unable to load statistics.");
630 stats = VSC_Main(vd);
631 #else /* if HAVE_VARNISH_V4 */
632 stats = VSC_Main(vd, NULL);
635 varnish_monitor (conf, stats);
640 #else /* if HAVE_VARNISH_V2 */
641 static int varnish_read (user_data_t *ud) /* {{{ */
643 const c_varnish_stats_t *stats;
647 if ((ud == NULL) || (ud->data == NULL))
652 stats = VSL_OpenStats (conf->instance);
655 ERROR ("Varnish plugin : unable to load statistics");
660 varnish_monitor (conf, stats);
666 static void varnish_config_free (void *ptr) /* {{{ */
668 user_config_t *conf = ptr;
673 sfree (conf->instance);
677 static int varnish_config_apply_default (user_config_t *conf) /* {{{ */
682 conf->collect_backend = 1;
683 conf->collect_cache = 1;
684 conf->collect_connections = 1;
685 #ifdef HAVE_VARNISH_V3
686 conf->collect_dirdns = 0;
688 conf->collect_esi = 0;
689 conf->collect_fetch = 0;
690 conf->collect_hcb = 0;
691 conf->collect_objects = 0;
693 conf->collect_purge = 0;
695 conf->collect_ban = 0;
697 conf->collect_session = 0;
698 conf->collect_shm = 1;
700 conf->collect_sm = 0;
701 conf->collect_sma = 0;
703 conf->collect_sms = 0;
704 conf->collect_struct = 0;
705 conf->collect_totals = 0;
706 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
707 conf->collect_uptime = 0;
709 conf->collect_vcl = 0;
710 conf->collect_workers = 0;
712 conf->collect_vsm = 0;
716 } /* }}} int varnish_config_apply_default */
718 static int varnish_init (void) /* {{{ */
726 conf = malloc (sizeof (*conf));
729 memset (conf, 0, sizeof (*conf));
731 /* Default settings: */
732 conf->instance = NULL;
734 varnish_config_apply_default (conf);
737 ud.free_func = varnish_config_free;
739 plugin_register_complex_read (/* group = */ "varnish",
740 /* name = */ "varnish/localhost",
741 /* callback = */ varnish_read,
742 /* interval = */ NULL,
743 /* user data = */ &ud);
746 } /* }}} int varnish_init */
748 static int varnish_config_instance (const oconfig_item_t *ci) /* {{{ */
752 char callback_name[DATA_MAX_NAME_LEN];
755 conf = malloc (sizeof (*conf));
758 memset (conf, 0, sizeof (*conf));
759 conf->instance = NULL;
761 varnish_config_apply_default (conf);
763 if (ci->values_num == 1)
767 status = cf_util_get_string (ci, &conf->instance);
773 assert (conf->instance != NULL);
775 if (strcmp ("localhost", conf->instance) == 0)
777 sfree (conf->instance);
778 conf->instance = NULL;
781 else if (ci->values_num > 1)
783 WARNING ("Varnish plugin: \"Instance\" blocks accept only "
788 for (i = 0; i < ci->children_num; i++)
790 oconfig_item_t *child = ci->children + i;
792 if (strcasecmp ("CollectCache", child->key) == 0)
793 cf_util_get_boolean (child, &conf->collect_cache);
794 else if (strcasecmp ("CollectConnections", child->key) == 0)
795 cf_util_get_boolean (child, &conf->collect_connections);
796 else if (strcasecmp ("CollectESI", child->key) == 0)
797 cf_util_get_boolean (child, &conf->collect_esi);
798 #ifdef HAVE_VARNISH_V3
799 else if (strcasecmp ("CollectDirectorDNS", child->key) == 0)
800 cf_util_get_boolean (child, &conf->collect_dirdns);
802 else if (strcasecmp ("CollectBackend", child->key) == 0)
803 cf_util_get_boolean (child, &conf->collect_backend);
804 else if (strcasecmp ("CollectFetch", child->key) == 0)
805 cf_util_get_boolean (child, &conf->collect_fetch);
806 else if (strcasecmp ("CollectHCB", child->key) == 0)
807 cf_util_get_boolean (child, &conf->collect_hcb);
808 else if (strcasecmp ("CollectObjects", child->key) == 0)
809 cf_util_get_boolean (child, &conf->collect_objects);
811 else if (strcasecmp ("CollectPurge", child->key) == 0)
812 cf_util_get_boolean (child, &conf->collect_purge);
814 else if (strcasecmp ("CollectBan", child->key) == 0)
815 cf_util_get_boolean (child, &conf->collect_ban);
817 else if (strcasecmp ("CollectSession", child->key) == 0)
818 cf_util_get_boolean (child, &conf->collect_session);
819 else if (strcasecmp ("CollectSHM", child->key) == 0)
820 cf_util_get_boolean (child, &conf->collect_shm);
821 else if (strcasecmp ("CollectSMS", child->key) == 0)
822 cf_util_get_boolean (child, &conf->collect_sms);
824 else if (strcasecmp ("CollectSMA", child->key) == 0)
825 cf_util_get_boolean (child, &conf->collect_sma);
826 else if (strcasecmp ("CollectSM", child->key) == 0)
827 cf_util_get_boolean (child, &conf->collect_sm);
829 else if (strcasecmp ("CollectStruct", child->key) == 0)
830 cf_util_get_boolean (child, &conf->collect_struct);
831 else if (strcasecmp ("CollectTotals", child->key) == 0)
832 cf_util_get_boolean (child, &conf->collect_totals);
833 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
834 else if (strcasecmp ("CollectUptime", child->key) == 0)
835 cf_util_get_boolean (child, &conf->collect_uptime);
837 else if (strcasecmp ("CollectVCL", child->key) == 0)
838 cf_util_get_boolean (child, &conf->collect_vcl);
839 else if (strcasecmp ("CollectWorkers", child->key) == 0)
840 cf_util_get_boolean (child, &conf->collect_workers);
842 else if (strcasecmp ("CollectVSM", child->key) == 0)
843 cf_util_get_boolean (child, &conf->collect_vsm);
847 WARNING ("Varnish plugin: Ignoring unknown "
848 "configuration option: \"%s\". Did "
849 "you forget to add an <Instance /> "
850 "block around the configuration?",
855 if (!conf->collect_cache
856 && !conf->collect_connections
857 && !conf->collect_esi
858 && !conf->collect_backend
859 #ifdef HAVE_VARNISH_V3
860 && !conf->collect_dirdns
862 && !conf->collect_fetch
863 && !conf->collect_hcb
864 && !conf->collect_objects
866 && !conf->collect_purge
868 && !conf->collect_ban
870 && !conf->collect_session
871 && !conf->collect_shm
872 && !conf->collect_sms
874 && !conf->collect_sma
877 && !conf->collect_struct
878 && !conf->collect_totals
879 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
880 && !conf->collect_uptime
882 && !conf->collect_vcl
883 && !conf->collect_workers
885 && !conf->collect_vsm
889 WARNING ("Varnish plugin: No metric has been configured for "
890 "instance \"%s\". Disabling this instance.",
891 (conf->instance == NULL) ? "localhost" : conf->instance);
895 ssnprintf (callback_name, sizeof (callback_name), "varnish/%s",
896 (conf->instance == NULL) ? "localhost" : conf->instance);
899 ud.free_func = varnish_config_free;
901 plugin_register_complex_read (/* group = */ "varnish",
902 /* name = */ callback_name,
903 /* callback = */ varnish_read,
904 /* interval = */ NULL,
905 /* user data = */ &ud);
910 } /* }}} int varnish_config_instance */
912 static int varnish_config (oconfig_item_t *ci) /* {{{ */
916 for (i = 0; i < ci->children_num; i++)
918 oconfig_item_t *child = ci->children + i;
920 if (strcasecmp ("Instance", child->key) == 0)
921 varnish_config_instance (child);
924 WARNING ("Varnish plugin: Ignoring unknown "
925 "configuration option: \"%s\"",
931 } /* }}} int varnish_config */
933 void module_register (void) /* {{{ */
935 plugin_register_complex_config ("varnish", varnish_config);
936 plugin_register_init ("varnish", varnish_init);
939 /* vim: set sw=8 noet fdm=marker : */