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>
24 * Denes Matetelki <dmatetelki at varnish-software.com>
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;
74 #if HAVE_VARNISH_V2 || HAVE_VARNISH_V4
79 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
83 _Bool collect_workers;
87 _Bool collect_mempool;
93 typedef struct user_config_s user_config_t; /* }}} */
95 static _Bool have_instance = 0;
97 static int varnish_submit(const char *plugin_instance, /* {{{ */
98 const char *category, const char *type,
99 const char *type_instance, value_t value) {
100 value_list_t vl = VALUE_LIST_INIT;
105 sstrncpy(vl.plugin, "varnish", sizeof(vl.plugin));
107 if (plugin_instance == NULL)
108 plugin_instance = "default";
109 snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s-%s",
110 plugin_instance, category);
112 sstrncpy(vl.type, type, sizeof(vl.type));
114 if (type_instance != NULL)
115 sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance));
117 return plugin_dispatch_values(&vl);
118 } /* }}} int varnish_submit */
120 static int varnish_submit_gauge(const char *plugin_instance, /* {{{ */
121 const char *category, const char *type,
122 const char *type_instance,
123 uint64_t gauge_value) {
124 return varnish_submit(plugin_instance, category, type, type_instance,
126 .gauge = (gauge_t)gauge_value,
128 } /* }}} int varnish_submit_gauge */
130 static int varnish_submit_derive(const char *plugin_instance, /* {{{ */
131 const char *category, const char *type,
132 const char *type_instance,
133 uint64_t derive_value) {
134 return varnish_submit(plugin_instance, category, type, type_instance,
136 .derive = (derive_t)derive_value,
138 } /* }}} int varnish_submit_derive */
140 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
141 static int varnish_monitor(void *priv,
142 const struct VSC_point *const pt) /* {{{ */
145 const user_config_t *conf;
155 class = pt->section->fantom->type;
156 name = pt->desc->name;
158 if (strcmp(class, "MAIN") != 0)
161 #elif HAVE_VARNISH_V3
165 if (strcmp(class, "") != 0)
169 val = *(const volatile uint64_t *)pt->ptr;
171 if (conf->collect_cache) {
172 if (strcmp(name, "cache_hit") == 0)
173 return varnish_submit_derive(conf->instance, "cache", "cache_result",
175 else if (strcmp(name, "cache_miss") == 0)
176 return varnish_submit_derive(conf->instance, "cache", "cache_result",
178 else if (strcmp(name, "cache_hitpass") == 0)
179 return varnish_submit_derive(conf->instance, "cache", "cache_result",
183 if (conf->collect_connections) {
184 if (strcmp(name, "client_conn") == 0)
185 return varnish_submit_derive(conf->instance, "connections", "connections",
187 else if (strcmp(name, "client_drop") == 0)
188 return varnish_submit_derive(conf->instance, "connections", "connections",
190 else if (strcmp(name, "client_req") == 0)
191 return varnish_submit_derive(conf->instance, "connections", "connections",
193 #ifdef HAVE_VARNISH_V4
194 else if (strcmp(name, "client_req_400") == 0)
195 return varnish_submit_derive(conf->instance, "connections", "connections",
197 else if (strcmp(name, "client_req_417") == 0)
198 return varnish_submit_derive(conf->instance, "connections", "connections",
203 #ifdef HAVE_VARNISH_V3
204 if (conf->collect_dirdns) {
205 if (strcmp(name, "dir_dns_lookups") == 0)
206 return varnish_submit_derive(conf->instance, "dirdns", "cache_operation",
208 else if (strcmp(name, "dir_dns_failed") == 0)
209 return varnish_submit_derive(conf->instance, "dirdns", "cache_result",
211 else if (strcmp(name, "dir_dns_hit") == 0)
212 return varnish_submit_derive(conf->instance, "dirdns", "cache_result",
214 else if (strcmp(name, "dir_dns_cache_full") == 0)
215 return varnish_submit_derive(conf->instance, "dirdns", "cache_result",
220 if (conf->collect_esi) {
221 if (strcmp(name, "esi_errors") == 0)
222 return varnish_submit_derive(conf->instance, "esi", "total_operations",
224 else if (strcmp(name, "esi_parse") == 0)
225 return varnish_submit_derive(conf->instance, "esi", "total_operations",
227 else if (strcmp(name, "esi_warnings") == 0)
228 return varnish_submit_derive(conf->instance, "esi", "total_operations",
232 if (conf->collect_backend) {
233 if (strcmp(name, "backend_conn") == 0)
234 return varnish_submit_derive(conf->instance, "backend", "connections",
236 else if (strcmp(name, "backend_unhealthy") == 0)
237 return varnish_submit_derive(conf->instance, "backend", "connections",
238 "not-attempted", val);
239 else if (strcmp(name, "backend_busy") == 0)
240 return varnish_submit_derive(conf->instance, "backend", "connections",
242 else if (strcmp(name, "backend_fail") == 0)
243 return varnish_submit_derive(conf->instance, "backend", "connections",
245 else if (strcmp(name, "backend_reuse") == 0)
246 return varnish_submit_derive(conf->instance, "backend", "connections",
248 else if (strcmp(name, "backend_toolate") == 0)
249 return varnish_submit_derive(conf->instance, "backend", "connections",
251 else if (strcmp(name, "backend_recycle") == 0)
252 return varnish_submit_derive(conf->instance, "backend", "connections",
254 else if (strcmp(name, "backend_unused") == 0)
255 return varnish_submit_derive(conf->instance, "backend", "connections",
257 else if (strcmp(name, "backend_retry") == 0)
258 return varnish_submit_derive(conf->instance, "backend", "connections",
260 else if (strcmp(name, "backend_req") == 0)
261 return varnish_submit_derive(conf->instance, "backend", "http_requests",
263 else if (strcmp(name, "n_backend") == 0)
264 return varnish_submit_gauge(conf->instance, "backend", "backends",
268 if (conf->collect_fetch) {
269 if (strcmp(name, "fetch_head") == 0)
270 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
272 else if (strcmp(name, "fetch_length") == 0)
273 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
275 else if (strcmp(name, "fetch_chunked") == 0)
276 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
278 else if (strcmp(name, "fetch_eof") == 0)
279 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
281 else if (strcmp(name, "fetch_bad") == 0)
282 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
284 else if (strcmp(name, "fetch_close") == 0)
285 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
287 else if (strcmp(name, "fetch_oldhttp") == 0)
288 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
290 else if (strcmp(name, "fetch_zero") == 0)
291 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
293 else if (strcmp(name, "fetch_failed") == 0)
294 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
296 else if (strcmp(name, "fetch_1xx") == 0)
297 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
299 else if (strcmp(name, "fetch_204") == 0)
300 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
302 else if (strcmp(name, "fetch_304") == 0)
303 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
306 else if (strcmp(name, "fetch_no_thread") == 0)
307 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
309 else if (strcmp(name, "fetch_none") == 0)
310 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
312 else if (strcmp(name, "busy_sleep") == 0)
313 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
315 else if (strcmp(name, "busy_wakeup") == 0)
316 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
321 if (conf->collect_hcb) {
322 if (strcmp(name, "hcb_nolock") == 0)
323 return varnish_submit_derive(conf->instance, "hcb", "cache_operation",
324 "lookup_nolock", val);
325 else if (strcmp(name, "hcb_lock") == 0)
326 return varnish_submit_derive(conf->instance, "hcb", "cache_operation",
328 else if (strcmp(name, "hcb_insert") == 0)
329 return varnish_submit_derive(conf->instance, "hcb", "cache_operation",
333 if (conf->collect_objects) {
334 if (strcmp(name, "n_expired") == 0)
335 return varnish_submit_derive(conf->instance, "objects", "total_objects",
337 else if (strcmp(name, "n_lru_nuked") == 0)
338 return varnish_submit_derive(conf->instance, "objects", "total_objects",
340 else if (strcmp(name, "n_lru_saved") == 0)
341 return varnish_submit_derive(conf->instance, "objects", "total_objects",
343 else if (strcmp(name, "n_lru_moved") == 0)
344 return varnish_submit_derive(conf->instance, "objects", "total_objects",
346 else if (strcmp(name, "n_deathrow") == 0)
347 return varnish_submit_derive(conf->instance, "objects", "total_objects",
349 else if (strcmp(name, "losthdr") == 0)
350 return varnish_submit_derive(conf->instance, "objects", "total_objects",
351 "header_overflow", val);
352 else if (strcmp(name, "n_obj_purged") == 0)
353 return varnish_submit_derive(conf->instance, "objects", "total_objects",
355 else if (strcmp(name, "n_objsendfile") == 0)
356 return varnish_submit_derive(conf->instance, "objects", "total_objects",
357 "sent_sendfile", val);
358 else if (strcmp(name, "n_objwrite") == 0)
359 return varnish_submit_derive(conf->instance, "objects", "total_objects",
361 else if (strcmp(name, "n_objoverflow") == 0)
362 return varnish_submit_derive(conf->instance, "objects", "total_objects",
363 "workspace_overflow", val);
365 else if (strcmp(name, "exp_mailed") == 0)
366 return varnish_submit_derive(conf->instance, "struct", "objects",
368 else if (strcmp(name, "exp_received") == 0)
369 return varnish_submit_derive(conf->instance, "struct", "objects",
370 "exp_received", val);
375 if (conf->collect_ban) {
376 if (strcmp(name, "n_ban") == 0)
377 return varnish_submit_derive(conf->instance, "ban", "total_operations",
379 else if (strcmp(name, "n_ban_add") == 0)
380 return varnish_submit_derive(conf->instance, "ban", "total_operations",
382 else if (strcmp(name, "n_ban_retire") == 0)
383 return varnish_submit_derive(conf->instance, "ban", "total_operations",
385 else if (strcmp(name, "n_ban_obj_test") == 0)
386 return varnish_submit_derive(conf->instance, "ban", "total_operations",
387 "objects_tested", val);
388 else if (strcmp(name, "n_ban_re_test") == 0)
389 return varnish_submit_derive(conf->instance, "ban", "total_operations",
390 "regexps_tested", val);
391 else if (strcmp(name, "n_ban_dups") == 0)
392 return varnish_submit_derive(conf->instance, "ban", "total_operations",
397 if (conf->collect_ban) {
398 if (strcmp(name, "bans") == 0)
399 return varnish_submit_derive(conf->instance, "ban", "total_operations",
401 else if (strcmp(name, "bans_added") == 0)
402 return varnish_submit_derive(conf->instance, "ban", "total_operations",
404 else if (strcmp(name, "bans_obj") == 0)
405 return varnish_submit_derive(conf->instance, "ban", "total_operations",
407 else if (strcmp(name, "bans_req") == 0)
408 return varnish_submit_derive(conf->instance, "ban", "total_operations",
410 else if (strcmp(name, "bans_completed") == 0)
411 return varnish_submit_derive(conf->instance, "ban", "total_operations",
413 else if (strcmp(name, "bans_deleted") == 0)
414 return varnish_submit_derive(conf->instance, "ban", "total_operations",
416 else if (strcmp(name, "bans_tested") == 0)
417 return varnish_submit_derive(conf->instance, "ban", "total_operations",
419 else if (strcmp(name, "bans_dups") == 0)
420 return varnish_submit_derive(conf->instance, "ban", "total_operations",
422 else if (strcmp(name, "bans_tested") == 0)
423 return varnish_submit_derive(conf->instance, "ban", "total_operations",
425 else if (strcmp(name, "bans_lurker_contention") == 0)
426 return varnish_submit_derive(conf->instance, "ban", "total_operations",
427 "lurker_contention", val);
428 else if (strcmp(name, "bans_lurker_obj_killed") == 0)
429 return varnish_submit_derive(conf->instance, "ban", "total_operations",
430 "lurker_obj_killed", val);
431 else if (strcmp(name, "bans_lurker_tested") == 0)
432 return varnish_submit_derive(conf->instance, "ban", "total_operations",
433 "lurker_tested", val);
434 else if (strcmp(name, "bans_lurker_tests_tested") == 0)
435 return varnish_submit_derive(conf->instance, "ban", "total_operations",
436 "lurker_tests_tested", val);
437 else if (strcmp(name, "bans_obj_killed") == 0)
438 return varnish_submit_derive(conf->instance, "ban", "total_operations",
440 else if (strcmp(name, "bans_persisted_bytes") == 0)
441 return varnish_submit_gauge(conf->instance, "ban", "total_bytes",
442 "persisted_bytes", val);
443 else if (strcmp(name, "bans_persisted_fragmentation") == 0)
444 return varnish_submit_gauge(conf->instance, "ban", "total_bytes",
445 "persisted_fragmentation", val);
446 else if (strcmp(name, "bans_tests_tested") == 0)
447 return varnish_submit_derive(conf->instance, "ban", "total_operations",
448 "tests_tested", val);
453 if (conf->collect_session) {
454 if (strcmp(name, "sess_closed") == 0)
455 return varnish_submit_derive(conf->instance, "session",
456 "total_operations", "closed", val);
457 else if (strcmp(name, "sess_pipeline") == 0)
458 return varnish_submit_derive(conf->instance, "session",
459 "total_operations", "pipeline", val);
460 else if (strcmp(name, "sess_readahead") == 0)
461 return varnish_submit_derive(conf->instance, "session",
462 "total_operations", "readahead", val);
463 else if (strcmp(name, "sess_conn") == 0)
464 return varnish_submit_derive(conf->instance, "session",
465 "total_operations", "accepted", val);
466 else if (strcmp(name, "sess_drop") == 0)
467 return varnish_submit_derive(conf->instance, "session",
468 "total_operations", "dropped", val);
469 else if (strcmp(name, "sess_fail") == 0)
470 return varnish_submit_derive(conf->instance, "session",
471 "total_operations", "failed", val);
472 else if (strcmp(name, "sess_pipe_overflow") == 0)
473 return varnish_submit_derive(conf->instance, "session",
474 "total_operations", "overflow", val);
475 else if (strcmp(name, "sess_queued") == 0)
476 return varnish_submit_derive(conf->instance, "session",
477 "total_operations", "queued", val);
478 else if (strcmp(name, "sess_linger") == 0)
479 return varnish_submit_derive(conf->instance, "session",
480 "total_operations", "linger", val);
481 else if (strcmp(name, "sess_herd") == 0)
482 return varnish_submit_derive(conf->instance, "session",
483 "total_operations", "herd", val);
485 else if (strcmp(name, "sess_closed_err") == 0)
486 return varnish_submit_derive(conf->instance, "session",
487 "total_operations", "closed_err", val);
488 else if (strcmp(name, "sess_dropped") == 0)
489 return varnish_submit_derive(conf->instance, "session",
490 "total_operations", "dropped_for_thread", val);
494 if (conf->collect_shm) {
495 if (strcmp(name, "shm_records") == 0)
496 return varnish_submit_derive(conf->instance, "shm", "total_operations",
498 else if (strcmp(name, "shm_writes") == 0)
499 return varnish_submit_derive(conf->instance, "shm", "total_operations",
501 else if (strcmp(name, "shm_flushes") == 0)
502 return varnish_submit_derive(conf->instance, "shm", "total_operations",
504 else if (strcmp(name, "shm_cont") == 0)
505 return varnish_submit_derive(conf->instance, "shm", "total_operations",
507 else if (strcmp(name, "shm_cycles") == 0)
508 return varnish_submit_derive(conf->instance, "shm", "total_operations",
512 if (conf->collect_sms) {
513 if (strcmp(name, "sms_nreq") == 0)
514 return varnish_submit_derive(conf->instance, "sms", "total_requests",
516 else if (strcmp(name, "sms_nobj") == 0)
517 return varnish_submit_gauge(conf->instance, "sms", "requests",
519 else if (strcmp(name, "sms_nbytes") == 0)
520 return varnish_submit_gauge(conf->instance, "sms", "bytes", "outstanding",
522 else if (strcmp(name, "sms_balloc") == 0)
523 return varnish_submit_derive(conf->instance, "sms", "total_bytes",
525 else if (strcmp(name, "sms_bfree") == 0)
526 return varnish_submit_derive(conf->instance, "sms", "total_bytes", "free",
530 if (conf->collect_struct) {
531 if (strcmp(name, "n_sess_mem") == 0)
532 return varnish_submit_gauge(conf->instance, "struct", "current_sessions",
534 else if (strcmp(name, "n_sess") == 0)
535 return varnish_submit_gauge(conf->instance, "struct", "current_sessions",
537 else if (strcmp(name, "n_object") == 0)
538 return varnish_submit_gauge(conf->instance, "struct", "objects", "object",
540 else if (strcmp(name, "n_vampireobject") == 0)
541 return varnish_submit_gauge(conf->instance, "struct", "objects",
542 "vampireobject", val);
543 else if (strcmp(name, "n_objectcore") == 0)
544 return varnish_submit_gauge(conf->instance, "struct", "objects",
546 else if (strcmp(name, "n_waitinglist") == 0)
547 return varnish_submit_gauge(conf->instance, "struct", "objects",
549 else if (strcmp(name, "n_objecthead") == 0)
550 return varnish_submit_gauge(conf->instance, "struct", "objects",
552 else if (strcmp(name, "n_smf") == 0)
553 return varnish_submit_gauge(conf->instance, "struct", "objects", "smf",
555 else if (strcmp(name, "n_smf_frag") == 0)
556 return varnish_submit_gauge(conf->instance, "struct", "objects",
558 else if (strcmp(name, "n_smf_large") == 0)
559 return varnish_submit_gauge(conf->instance, "struct", "objects",
561 else if (strcmp(name, "n_vbe_conn") == 0)
562 return varnish_submit_gauge(conf->instance, "struct", "objects",
566 if (conf->collect_totals) {
567 if (strcmp(name, "s_sess") == 0)
568 return varnish_submit_derive(conf->instance, "totals", "total_sessions",
570 else if (strcmp(name, "s_req") == 0)
571 return varnish_submit_derive(conf->instance, "totals", "total_requests",
573 else if (strcmp(name, "s_pipe") == 0)
574 return varnish_submit_derive(conf->instance, "totals", "total_operations",
576 else if (strcmp(name, "s_pass") == 0)
577 return varnish_submit_derive(conf->instance, "totals", "total_operations",
579 else if (strcmp(name, "s_fetch") == 0)
580 return varnish_submit_derive(conf->instance, "totals", "total_operations",
582 else if (strcmp(name, "s_synth") == 0)
583 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
585 else if (strcmp(name, "s_req_hdrbytes") == 0)
586 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
588 else if (strcmp(name, "s_req_bodybytes") == 0)
589 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
591 else if (strcmp(name, "s_resp_hdrbytes") == 0)
592 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
594 else if (strcmp(name, "s_resp_bodybytes") == 0)
595 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
597 else if (strcmp(name, "s_pipe_hdrbytes") == 0)
598 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
600 else if (strcmp(name, "s_pipe_in") == 0)
601 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
603 else if (strcmp(name, "s_pipe_out") == 0)
604 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
606 else if (strcmp(name, "n_purges") == 0)
607 return varnish_submit_derive(conf->instance, "totals", "total_operations",
609 else if (strcmp(name, "s_hdrbytes") == 0)
610 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
611 "header-bytes", val);
612 else if (strcmp(name, "s_bodybytes") == 0)
613 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
615 else if (strcmp(name, "n_gzip") == 0)
616 return varnish_submit_derive(conf->instance, "totals", "total_operations",
618 else if (strcmp(name, "n_gunzip") == 0)
619 return varnish_submit_derive(conf->instance, "totals", "total_operations",
623 if (conf->collect_uptime) {
624 if (strcmp(name, "uptime") == 0)
625 return varnish_submit_gauge(conf->instance, "uptime", "uptime",
626 "client_uptime", val);
629 if (conf->collect_vcl) {
630 if (strcmp(name, "n_vcl") == 0)
631 return varnish_submit_gauge(conf->instance, "vcl", "vcl", "total_vcl",
633 else if (strcmp(name, "n_vcl_avail") == 0)
634 return varnish_submit_gauge(conf->instance, "vcl", "vcl", "avail_vcl",
636 else if (strcmp(name, "n_vcl_discard") == 0)
637 return varnish_submit_gauge(conf->instance, "vcl", "vcl", "discarded_vcl",
639 else if (strcmp(name, "vmods") == 0)
640 return varnish_submit_gauge(conf->instance, "vcl", "objects", "vmod",
644 if (conf->collect_workers) {
645 if (strcmp(name, "threads") == 0)
646 return varnish_submit_gauge(conf->instance, "workers", "threads",
648 else if (strcmp(name, "threads_created") == 0)
649 return varnish_submit_derive(conf->instance, "workers", "total_threads",
651 else if (strcmp(name, "threads_failed") == 0)
652 return varnish_submit_derive(conf->instance, "workers", "total_threads",
654 else if (strcmp(name, "threads_limited") == 0)
655 return varnish_submit_derive(conf->instance, "workers", "total_threads",
657 else if (strcmp(name, "threads_destroyed") == 0)
658 return varnish_submit_derive(conf->instance, "workers", "total_threads",
660 else if (strcmp(name, "thread_queue_len") == 0)
661 return varnish_submit_derive(conf->instance, "workers", "queue_length",
663 else if (strcmp(name, "n_wrk") == 0)
664 return varnish_submit_gauge(conf->instance, "workers", "threads",
666 else if (strcmp(name, "n_wrk_create") == 0)
667 return varnish_submit_derive(conf->instance, "workers", "total_threads",
669 else if (strcmp(name, "n_wrk_failed") == 0)
670 return varnish_submit_derive(conf->instance, "workers", "total_threads",
672 else if (strcmp(name, "n_wrk_max") == 0)
673 return varnish_submit_derive(conf->instance, "workers", "total_threads",
675 else if (strcmp(name, "n_wrk_drop") == 0)
676 return varnish_submit_derive(conf->instance, "workers", "total_threads",
678 else if (strcmp(name, "n_wrk_queue") == 0)
679 return varnish_submit_derive(conf->instance, "workers", "total_requests",
681 else if (strcmp(name, "n_wrk_overflow") == 0)
682 return varnish_submit_derive(conf->instance, "workers", "total_requests",
684 else if (strcmp(name, "n_wrk_queued") == 0)
685 return varnish_submit_derive(conf->instance, "workers", "total_requests",
687 else if (strcmp(name, "n_wrk_lqueue") == 0)
688 return varnish_submit_derive(conf->instance, "workers", "total_requests",
689 "queue_length", val);
691 else if (strcmp(name, "pools") == 0)
692 return varnish_submit_gauge(conf->instance, "workers", "pools",
694 else if (strcmp(name, "busy_killed") == 0)
695 return varnish_submit_derive(conf->instance, "workers", "http_requests",
702 if (conf->collect_vsm) {
703 if (strcmp(name, "vsm_free") == 0)
704 return varnish_submit_gauge(conf->instance, "vsm", "bytes", "free", val);
705 else if (strcmp(name, "vsm_used") == 0)
706 return varnish_submit_gauge(conf->instance, "vsm", "bytes", "used", val);
707 else if (strcmp(name, "vsm_cooling") == 0)
708 return varnish_submit_gauge(conf->instance, "vsm", "bytes", "cooling",
710 else if (strcmp(name, "vsm_overflow") == 0)
711 return varnish_submit_gauge(conf->instance, "vsm", "bytes", "overflow",
713 else if (strcmp(name, "vsm_overflowed") == 0)
714 return varnish_submit_derive(conf->instance, "vsm", "total_bytes",
718 if (conf->collect_vbe) {
719 /* @TODO figure out the collectd type for bitmap
720 if (strcmp(name, "happy") == 0)
721 return varnish_submit_derive(conf->instance, "vbe",
722 "bitmap", "happy_hprobes", val);
724 if (strcmp(name, "bereq_hdrbytes") == 0)
725 return varnish_submit_derive(conf->instance, "vbe",
726 "total_bytes", "bereq_hdrbytes", val);
727 else if (strcmp(name, "bereq_bodybytes") == 0)
728 return varnish_submit_derive(conf->instance, "vbe",
729 "total_bytes", "bereq_bodybytes", val);
730 else if (strcmp(name, "beresp_hdrbytes") == 0)
731 return varnish_submit_derive(conf->instance, "vbe",
732 "total_bytes", "beresp_hdrbytes", val);
733 else if (strcmp(name, "beresp_bodybytes") == 0)
734 return varnish_submit_derive(conf->instance, "vbe",
735 "total_bytes", "beresp_bodybytes", val);
736 else if (strcmp(name, "pipe_hdrbytes") == 0)
737 return varnish_submit_derive(conf->instance, "vbe",
738 "total_bytes", "pipe_hdrbytes", val);
739 else if (strcmp(name, "pipe_out") == 0)
740 return varnish_submit_derive(conf->instance, "vbe",
741 "total_bytes", "pipe_out", val);
742 else if (strcmp(name, "pipe_in") == 0)
743 return varnish_submit_derive(conf->instance, "vbe",
744 "total_bytes", "pipe_in", val);
745 else if (strcmp(name, "conn") == 0)
746 return varnish_submit_derive(conf->instance, "vbe", "connections",
748 else if (strcmp(name, "req") == 0)
749 return varnish_submit_gauge(conf->instance, "vbe", "http_requests",
753 /* All Stevedores support these counters */
754 if (conf->collect_sma || conf->collect_smf) {
757 if (conf->collect_sma)
758 strncpy(category, "sma", 4);
760 strncpy(category, "smf", 4);
762 if (strcmp(name, "c_req") == 0)
763 return varnish_submit_derive(conf->instance, category,
764 "total_operations", "alloc_req", val);
765 else if (strcmp(name, "c_fail") == 0)
766 return varnish_submit_derive(conf->instance, category,
767 "total_operations", "alloc_fail", val);
768 else if (strcmp(name, "c_bytes") == 0)
769 return varnish_submit_derive(conf->instance, category,
770 "total_bytes", "bytes_allocated", val);
771 else if (strcmp(name, "c_freed") == 0)
772 return varnish_submit_derive(conf->instance, category,
773 "total_bytes", "bytes_freed", val);
774 else if (strcmp(name, "g_alloc") == 0)
775 return varnish_submit_gauge(conf->instance, category,
776 "total_operations", "alloc_outstanding", val);
777 else if (strcmp(name, "g_bytes") == 0)
778 return varnish_submit_gauge(conf->instance, category, "bytes",
779 "bytes_outstanding", val);
780 else if (strcmp(name, "g_space") == 0)
781 return varnish_submit_gauge(conf->instance, category, "bytes",
782 "bytes_available", val);
785 /* No SMA specific counters */
787 if (conf->collect_smf) {
788 if (strcmp(name, "g_smf") == 0)
789 return varnish_submit_gauge(conf->instance, "smf", "objects",
790 "n_struct_smf", val);
791 else if (strcmp(name, "g_smf_frag") == 0)
792 return varnish_submit_gauge(conf->instance, "smf", "objects",
793 "n_small_free_smf", val);
794 else if (strcmp(name, "g_smf_large") == 0)
795 return varnish_submit_gauge(conf->instance, "smf", "objects",
796 "n_large_free_smf", val);
799 if (conf->collect_mgt) {
800 if (strcmp(name, "uptime") == 0)
801 return varnish_submit_gauge(conf->instance, "mgt", "uptime",
802 "mgt_proc_uptime", val);
803 else if (strcmp(name, "child_start") == 0)
804 return varnish_submit_derive(conf->instance, "mgt",
805 "total_operations", "child_start", val);
806 else if (strcmp(name, "child_exit") == 0)
807 return varnish_submit_derive(conf->instance, "mgt",
808 "total_operations", "child_exit", val);
809 else if (strcmp(name, "child_stop") == 0)
810 return varnish_submit_derive(conf->instance, "mgt",
811 "total_operations", "child_stop", val);
812 else if (strcmp(name, "child_died") == 0)
813 return varnish_submit_derive(conf->instance, "mgt",
814 "total_operations", "child_died", val);
815 else if (strcmp(name, "child_dump") == 0)
816 return varnish_submit_derive(conf->instance, "mgt",
817 "total_operations", "child_dump", val);
818 else if (strcmp(name, "child_panic") == 0)
819 return varnish_submit_derive(conf->instance, "mgt",
820 "total_operations", "child_panic", val);
823 if (conf->collect_lck) {
824 if (strcmp(name, "creat") == 0)
825 return varnish_submit_derive(conf->instance, "lck", "objects",
827 else if (strcmp(name, "destroy") == 0)
828 return varnish_submit_derive(conf->instance, "lck", "objects",
830 else if (strcmp(name, "locks") == 0)
831 return varnish_submit_derive(conf->instance, "lck", "total_operations",
835 if (conf->collect_mempool) {
836 if (strcmp(name, "live") == 0)
837 return varnish_submit_gauge(conf->instance, "mempool", "objects",
839 else if (strcmp(name, "pool") == 0)
840 return varnish_submit_gauge(conf->instance, "mempool", "objects",
842 else if (strcmp(name, "sz_wanted") == 0)
843 return varnish_submit_gauge(conf->instance, "mempool", "bytes",
844 "size_requested", val);
845 else if (strcmp(name, "sz_actual") == 0)
846 return varnish_submit_gauge(conf->instance, "mempool", "bytes",
847 "size_allocated", val);
848 else if (strcmp(name, "allocs") == 0)
849 return varnish_submit_derive(conf->instance, "mempool",
850 "total_operations", "allocations", val);
851 else if (strcmp(name, "frees") == 0)
852 return varnish_submit_derive(conf->instance, "mempool",
853 "total_operations", "frees", val);
854 else if (strcmp(name, "recycle") == 0)
855 return varnish_submit_derive(conf->instance, "mempool",
856 "objects", "recycled", val);
857 else if (strcmp(name, "timeout") == 0)
858 return varnish_submit_derive(conf->instance, "mempool",
859 "objects", "timed_out", val);
860 else if (strcmp(name, "toosmall") == 0)
861 return varnish_submit_derive(conf->instance, "mempool",
862 "objects", "too_small", val);
863 else if (strcmp(name, "surplus") == 0)
864 return varnish_submit_derive(conf->instance, "mempool",
865 "objects", "surplus", val);
866 else if (strcmp(name, "randry") == 0)
867 return varnish_submit_derive(conf->instance, "mempool",
868 "objects", "ran_dry", val);
874 } /* }}} static int varnish_monitor */
875 #else /* if HAVE_VARNISH_V2 */
876 static void varnish_monitor(const user_config_t *conf, /* {{{ */
877 const c_varnish_stats_t *stats) {
878 if (conf->collect_cache) {
880 varnish_submit_derive(conf->instance, "cache", "cache_result", "hit",
883 varnish_submit_derive(conf->instance, "cache", "cache_result", "miss",
885 /* Cache hits for pass */
886 varnish_submit_derive(conf->instance, "cache", "cache_result", "hitpass",
887 stats->cache_hitpass);
890 if (conf->collect_connections) {
891 /* Client connections accepted */
892 varnish_submit_derive(conf->instance, "connections", "connections",
893 "accepted", stats->client_conn);
894 /* Connection dropped, no sess */
895 varnish_submit_derive(conf->instance, "connections", "connections",
896 "dropped", stats->client_drop);
897 /* Client requests received */
898 varnish_submit_derive(conf->instance, "connections", "connections",
899 "received", stats->client_req);
902 if (conf->collect_esi) {
903 /* ESI parse errors (unlock) */
904 varnish_submit_derive(conf->instance, "esi", "total_operations", "error",
906 /* Objects ESI parsed (unlock) */
907 varnish_submit_derive(conf->instance, "esi", "total_operations", "parsed",
911 if (conf->collect_backend) {
912 /* Backend conn. success */
913 varnish_submit_derive(conf->instance, "backend", "connections", "success",
914 stats->backend_conn);
915 /* Backend conn. not attempted */
916 varnish_submit_derive(conf->instance, "backend", "connections",
917 "not-attempted", stats->backend_unhealthy);
918 /* Backend conn. too many */
919 varnish_submit_derive(conf->instance, "backend", "connections", "too-many",
920 stats->backend_busy);
921 /* Backend conn. failures */
922 varnish_submit_derive(conf->instance, "backend", "connections", "failures",
923 stats->backend_fail);
924 /* Backend conn. reuses */
925 varnish_submit_derive(conf->instance, "backend", "connections", "reuses",
926 stats->backend_reuse);
927 /* Backend conn. was closed */
928 varnish_submit_derive(conf->instance, "backend", "connections",
929 "was-closed", stats->backend_toolate);
930 /* Backend conn. recycles */
931 varnish_submit_derive(conf->instance, "backend", "connections", "recycled",
932 stats->backend_recycle);
933 /* Backend conn. unused */
934 varnish_submit_derive(conf->instance, "backend", "connections", "unused",
935 stats->backend_unused);
936 /* Backend requests mades */
937 varnish_submit_derive(conf->instance, "backend", "http_requests",
938 "requests", stats->backend_req);
940 varnish_submit_gauge(conf->instance, "backend", "backends", "n_backends",
944 if (conf->collect_fetch) {
946 varnish_submit_derive(conf->instance, "fetch", "http_requests", "head",
948 /* Fetch with length */
949 varnish_submit_derive(conf->instance, "fetch", "http_requests", "length",
950 stats->fetch_length);
952 varnish_submit_derive(conf->instance, "fetch", "http_requests", "chunked",
953 stats->fetch_chunked);
955 varnish_submit_derive(conf->instance, "fetch", "http_requests", "eof",
957 /* Fetch bad headers */
958 varnish_submit_derive(conf->instance, "fetch", "http_requests",
959 "bad_headers", stats->fetch_bad);
960 /* Fetch wanted close */
961 varnish_submit_derive(conf->instance, "fetch", "http_requests", "close",
963 /* Fetch pre HTTP/1.1 closed */
964 varnish_submit_derive(conf->instance, "fetch", "http_requests", "oldhttp",
965 stats->fetch_oldhttp);
967 varnish_submit_derive(conf->instance, "fetch", "http_requests", "zero",
970 varnish_submit_derive(conf->instance, "fetch", "http_requests", "failed",
971 stats->fetch_failed);
974 if (conf->collect_hcb) {
975 /* HCB Lookups without lock */
976 varnish_submit_derive(conf->instance, "hcb", "cache_operation",
977 "lookup_nolock", stats->hcb_nolock);
978 /* HCB Lookups with lock */
979 varnish_submit_derive(conf->instance, "hcb", "cache_operation",
980 "lookup_lock", stats->hcb_lock);
982 varnish_submit_derive(conf->instance, "hcb", "cache_operation", "insert",
986 if (conf->collect_objects) {
987 /* N expired objects */
988 varnish_submit_derive(conf->instance, "objects", "total_objects", "expired",
990 /* N LRU nuked objects */
991 varnish_submit_derive(conf->instance, "objects", "total_objects",
992 "lru_nuked", stats->n_lru_nuked);
993 /* N LRU saved objects */
994 varnish_submit_derive(conf->instance, "objects", "total_objects",
995 "lru_saved", stats->n_lru_saved);
996 /* N LRU moved objects */
997 varnish_submit_derive(conf->instance, "objects", "total_objects",
998 "lru_moved", stats->n_lru_moved);
999 /* N objects on deathrow */
1000 varnish_submit_derive(conf->instance, "objects", "total_objects",
1001 "deathrow", stats->n_deathrow);
1002 /* HTTP header overflows */
1003 varnish_submit_derive(conf->instance, "objects", "total_objects",
1004 "header_overflow", stats->losthdr);
1005 /* Objects sent with sendfile */
1006 varnish_submit_derive(conf->instance, "objects", "total_objects",
1007 "sent_sendfile", stats->n_objsendfile);
1008 /* Objects sent with write */
1009 varnish_submit_derive(conf->instance, "objects", "total_objects",
1010 "sent_write", stats->n_objwrite);
1011 /* Objects overflowing workspace */
1012 varnish_submit_derive(conf->instance, "objects", "total_objects",
1013 "workspace_overflow", stats->n_objoverflow);
1016 if (conf->collect_purge) {
1017 /* N total active purges */
1018 varnish_submit_derive(conf->instance, "purge", "total_operations", "total",
1020 /* N new purges added */
1021 varnish_submit_derive(conf->instance, "purge", "total_operations", "added",
1022 stats->n_purge_add);
1023 /* N old purges deleted */
1024 varnish_submit_derive(conf->instance, "purge", "total_operations",
1025 "deleted", stats->n_purge_retire);
1026 /* N objects tested */
1027 varnish_submit_derive(conf->instance, "purge", "total_operations",
1028 "objects_tested", stats->n_purge_obj_test);
1029 /* N regexps tested against */
1030 varnish_submit_derive(conf->instance, "purge", "total_operations",
1031 "regexps_tested", stats->n_purge_re_test);
1032 /* N duplicate purges removed */
1033 varnish_submit_derive(conf->instance, "purge", "total_operations",
1034 "duplicate", stats->n_purge_dups);
1037 if (conf->collect_session) {
1038 /* Session Closed */
1039 varnish_submit_derive(conf->instance, "session", "total_operations",
1040 "closed", stats->sess_closed);
1041 /* Session Pipeline */
1042 varnish_submit_derive(conf->instance, "session", "total_operations",
1043 "pipeline", stats->sess_pipeline);
1044 /* Session Read Ahead */
1045 varnish_submit_derive(conf->instance, "session", "total_operations",
1046 "readahead", stats->sess_readahead);
1047 /* Session Linger */
1048 varnish_submit_derive(conf->instance, "session", "total_operations",
1049 "linger", stats->sess_linger);
1051 varnish_submit_derive(conf->instance, "session", "total_operations", "herd",
1055 if (conf->collect_shm) {
1057 varnish_submit_derive(conf->instance, "shm", "total_operations", "records",
1058 stats->shm_records);
1060 varnish_submit_derive(conf->instance, "shm", "total_operations", "writes",
1062 /* SHM flushes due to overflow */
1063 varnish_submit_derive(conf->instance, "shm", "total_operations", "flushes",
1064 stats->shm_flushes);
1065 /* SHM MTX contention */
1066 varnish_submit_derive(conf->instance, "shm", "total_operations",
1067 "contention", stats->shm_cont);
1068 /* SHM cycles through buffer */
1069 varnish_submit_derive(conf->instance, "shm", "total_operations", "cycles",
1073 if (conf->collect_sm) {
1074 /* allocator requests */
1075 varnish_submit_derive(conf->instance, "sm", "total_requests", "nreq",
1077 /* outstanding allocations */
1078 varnish_submit_gauge(conf->instance, "sm", "requests", "outstanding",
1080 /* bytes allocated */
1081 varnish_submit_derive(conf->instance, "sm", "total_bytes", "allocated",
1084 varnish_submit_derive(conf->instance, "sm", "total_bytes", "free",
1088 if (conf->collect_sma) {
1089 /* SMA allocator requests */
1090 varnish_submit_derive(conf->instance, "sma", "total_requests", "nreq",
1092 /* SMA outstanding allocations */
1093 varnish_submit_gauge(conf->instance, "sma", "requests", "outstanding",
1095 /* SMA outstanding bytes */
1096 varnish_submit_gauge(conf->instance, "sma", "bytes", "outstanding",
1098 /* SMA bytes allocated */
1099 varnish_submit_derive(conf->instance, "sma", "total_bytes", "allocated",
1101 /* SMA bytes free */
1102 varnish_submit_derive(conf->instance, "sma", "total_bytes", "free",
1106 if (conf->collect_sms) {
1107 /* SMS allocator requests */
1108 varnish_submit_derive(conf->instance, "sms", "total_requests", "allocator",
1110 /* SMS outstanding allocations */
1111 varnish_submit_gauge(conf->instance, "sms", "requests", "outstanding",
1113 /* SMS outstanding bytes */
1114 varnish_submit_gauge(conf->instance, "sms", "bytes", "outstanding",
1116 /* SMS bytes allocated */
1117 varnish_submit_derive(conf->instance, "sms", "total_bytes", "allocated",
1119 /* SMS bytes freed */
1120 varnish_submit_derive(conf->instance, "sms", "total_bytes", "free",
1124 if (conf->collect_struct) {
1125 /* N struct sess_mem */
1126 varnish_submit_gauge(conf->instance, "struct", "current_sessions",
1127 "sess_mem", stats->n_sess_mem);
1129 varnish_submit_gauge(conf->instance, "struct", "current_sessions", "sess",
1131 /* N struct object */
1132 varnish_submit_gauge(conf->instance, "struct", "objects", "object",
1134 /* N struct objecthead */
1135 varnish_submit_gauge(conf->instance, "struct", "objects", "objecthead",
1136 stats->n_objecthead);
1138 varnish_submit_gauge(conf->instance, "struct", "objects", "smf",
1140 /* N small free smf */
1141 varnish_submit_gauge(conf->instance, "struct", "objects", "smf_frag",
1143 /* N large free smf */
1144 varnish_submit_gauge(conf->instance, "struct", "objects", "smf_large",
1145 stats->n_smf_large);
1146 /* N struct vbe_conn */
1147 varnish_submit_gauge(conf->instance, "struct", "objects", "vbe_conn",
1151 if (conf->collect_totals) {
1152 /* Total Sessions */
1153 varnish_submit_derive(conf->instance, "totals", "total_sessions",
1154 "sessions", stats->s_sess);
1155 /* Total Requests */
1156 varnish_submit_derive(conf->instance, "totals", "total_requests",
1157 "requests", stats->s_req);
1159 varnish_submit_derive(conf->instance, "totals", "total_operations", "pipe",
1162 varnish_submit_derive(conf->instance, "totals", "total_operations", "pass",
1165 varnish_submit_derive(conf->instance, "totals", "total_operations",
1166 "fetches", stats->s_fetch);
1167 /* Total header bytes */
1168 varnish_submit_derive(conf->instance, "totals", "total_bytes",
1169 "header-bytes", stats->s_hdrbytes);
1170 /* Total body byte */
1171 varnish_submit_derive(conf->instance, "totals", "total_bytes", "body-bytes",
1172 stats->s_bodybytes);
1175 if (conf->collect_vcl) {
1177 varnish_submit_gauge(conf->instance, "vcl", "vcl", "total_vcl",
1179 /* N vcl available */
1180 varnish_submit_gauge(conf->instance, "vcl", "vcl", "avail_vcl",
1181 stats->n_vcl_avail);
1182 /* N vcl discarded */
1183 varnish_submit_gauge(conf->instance, "vcl", "vcl", "discarded_vcl",
1184 stats->n_vcl_discard);
1187 if (conf->collect_workers) {
1188 /* worker threads */
1189 varnish_submit_gauge(conf->instance, "workers", "threads", "worker",
1191 /* worker threads created */
1192 varnish_submit_derive(conf->instance, "workers", "total_threads", "created",
1193 stats->n_wrk_create);
1194 /* worker threads not created */
1195 varnish_submit_derive(conf->instance, "workers", "total_threads", "failed",
1196 stats->n_wrk_failed);
1197 /* worker threads limited */
1198 varnish_submit_derive(conf->instance, "workers", "total_threads", "limited",
1200 /* dropped work requests */
1201 varnish_submit_derive(conf->instance, "workers", "total_threads", "dropped",
1203 /* queued work requests */
1204 varnish_submit_derive(conf->instance, "workers", "total_requests", "queued",
1205 stats->n_wrk_queue);
1206 /* overflowed work requests */
1207 varnish_submit_derive(conf->instance, "workers", "total_requests",
1208 "overflowed", stats->n_wrk_overflow);
1211 } /* }}} void varnish_monitor */
1214 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
1215 static int varnish_read(user_data_t *ud) /* {{{ */
1217 struct VSM_data *vd;
1218 const c_varnish_stats_t *stats;
1221 user_config_t *conf;
1223 if ((ud == NULL) || (ud->data == NULL))
1233 if (conf->instance != NULL) {
1236 status = VSM_n_Arg(vd, conf->instance);
1239 ERROR("varnish plugin: VSM_n_Arg (\"%s\") failed "
1241 conf->instance, status);
1247 ok = (VSC_Open(vd, /* diag = */ 1) == 0);
1248 #else /* if HAVE_VARNISH_V4 */
1249 ok = (VSM_Open(vd) == 0);
1253 ERROR("varnish plugin: Unable to open connection.");
1259 stats = VSC_Main(vd);
1260 #else /* if HAVE_VARNISH_V4 */
1261 stats = VSC_Main(vd, NULL);
1265 ERROR("varnish plugin: Unable to get statistics.");
1271 VSC_Iter(vd, varnish_monitor, conf);
1272 #else /* if HAVE_VARNISH_V4 */
1273 VSC_Iter(vd, NULL, varnish_monitor, conf);
1279 #else /* if HAVE_VARNISH_V2 */
1280 static int varnish_read(user_data_t *ud) /* {{{ */
1282 const c_varnish_stats_t *stats;
1284 user_config_t *conf;
1286 if ((ud == NULL) || (ud->data == NULL))
1291 stats = VSL_OpenStats(conf->instance);
1292 if (stats == NULL) {
1293 ERROR("Varnish plugin : unable to load statistics");
1298 varnish_monitor(conf, stats);
1304 static void varnish_config_free(void *ptr) /* {{{ */
1306 user_config_t *conf = ptr;
1311 sfree(conf->instance);
1315 static int varnish_config_apply_default(user_config_t *conf) /* {{{ */
1320 conf->collect_backend = 1;
1321 conf->collect_cache = 1;
1322 conf->collect_connections = 1;
1323 #ifdef HAVE_VARNISH_V3
1324 conf->collect_dirdns = 0;
1326 conf->collect_esi = 0;
1327 conf->collect_fetch = 0;
1328 conf->collect_hcb = 0;
1329 conf->collect_objects = 0;
1331 conf->collect_purge = 0;
1333 conf->collect_ban = 0;
1335 conf->collect_session = 0;
1336 conf->collect_shm = 1;
1338 conf->collect_sm = 0;
1340 #if HAVE_VARNISH_V2 || HAVE_VARNISH_V4
1341 conf->collect_sma = 0;
1343 conf->collect_sms = 0;
1344 conf->collect_struct = 0;
1345 conf->collect_totals = 0;
1346 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
1347 conf->collect_uptime = 0;
1349 conf->collect_vcl = 0;
1350 conf->collect_workers = 0;
1352 conf->collect_vsm = 0;
1353 conf->collect_lck = 0;
1354 conf->collect_mempool = 0;
1355 conf->collect_mgt = 0;
1356 conf->collect_smf = 0;
1357 conf->collect_vbe = 0;
1361 } /* }}} int varnish_config_apply_default */
1363 static int varnish_init(void) /* {{{ */
1365 user_config_t *conf;
1370 conf = calloc(1, sizeof(*conf));
1374 /* Default settings: */
1375 conf->instance = NULL;
1377 varnish_config_apply_default(conf);
1379 plugin_register_complex_read(
1380 /* group = */ "varnish",
1381 /* name = */ "varnish/localhost",
1382 /* callback = */ varnish_read,
1385 .data = conf, .free_func = varnish_config_free,
1389 } /* }}} int varnish_init */
1391 static int varnish_config_instance(const oconfig_item_t *ci) /* {{{ */
1393 user_config_t *conf;
1394 char callback_name[DATA_MAX_NAME_LEN];
1396 conf = calloc(1, sizeof(*conf));
1399 conf->instance = NULL;
1401 varnish_config_apply_default(conf);
1403 if (ci->values_num == 1) {
1406 status = cf_util_get_string(ci, &conf->instance);
1411 assert(conf->instance != NULL);
1413 if (strcmp("localhost", conf->instance) == 0) {
1414 sfree(conf->instance);
1415 conf->instance = NULL;
1417 } else if (ci->values_num > 1) {
1418 WARNING("Varnish plugin: \"Instance\" blocks accept only "
1424 for (int i = 0; i < ci->children_num; i++) {
1425 oconfig_item_t *child = ci->children + i;
1427 if (strcasecmp("CollectCache", child->key) == 0)
1428 cf_util_get_boolean(child, &conf->collect_cache);
1429 else if (strcasecmp("CollectConnections", child->key) == 0)
1430 cf_util_get_boolean(child, &conf->collect_connections);
1431 else if (strcasecmp("CollectESI", child->key) == 0)
1432 cf_util_get_boolean(child, &conf->collect_esi);
1433 else if (strcasecmp("CollectDirectorDNS", child->key) == 0)
1434 #ifdef HAVE_VARNISH_V3
1435 cf_util_get_boolean(child, &conf->collect_dirdns);
1437 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1440 else if (strcasecmp("CollectBackend", child->key) == 0)
1441 cf_util_get_boolean(child, &conf->collect_backend);
1442 else if (strcasecmp("CollectFetch", child->key) == 0)
1443 cf_util_get_boolean(child, &conf->collect_fetch);
1444 else if (strcasecmp("CollectHCB", child->key) == 0)
1445 cf_util_get_boolean(child, &conf->collect_hcb);
1446 else if (strcasecmp("CollectObjects", child->key) == 0)
1447 cf_util_get_boolean(child, &conf->collect_objects);
1448 else if (strcasecmp("CollectPurge", child->key) == 0)
1450 cf_util_get_boolean(child, &conf->collect_purge);
1452 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1455 else if (strcasecmp("CollectBan", child->key) == 0)
1457 WARNING("Varnish plugin: \"%s\" is not available for Varnish %s.",
1460 cf_util_get_boolean(child, &conf->collect_ban);
1462 else if (strcasecmp("CollectSession", child->key) == 0)
1463 cf_util_get_boolean(child, &conf->collect_session);
1464 else if (strcasecmp("CollectSHM", child->key) == 0)
1465 cf_util_get_boolean(child, &conf->collect_shm);
1466 else if (strcasecmp("CollectSMS", child->key) == 0)
1467 cf_util_get_boolean(child, &conf->collect_sms);
1468 else if (strcasecmp("CollectSMA", child->key) == 0)
1469 #if HAVE_VARNISH_V2 || HAVE_VARNISH_V4
1470 cf_util_get_boolean(child, &conf->collect_sma);
1472 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1473 child->key, "v2 and v4");
1475 else if (strcasecmp("CollectSM", child->key) == 0)
1477 cf_util_get_boolean(child, &conf->collect_sm);
1479 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1482 else if (strcasecmp("CollectStruct", child->key) == 0)
1483 cf_util_get_boolean(child, &conf->collect_struct);
1484 else if (strcasecmp("CollectTotals", child->key) == 0)
1485 cf_util_get_boolean(child, &conf->collect_totals);
1486 else if (strcasecmp("CollectUptime", child->key) == 0)
1487 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
1488 cf_util_get_boolean(child, &conf->collect_uptime);
1490 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1491 child->key, "v3 and v4");
1493 else if (strcasecmp("CollectVCL", child->key) == 0)
1494 cf_util_get_boolean(child, &conf->collect_vcl);
1495 else if (strcasecmp("CollectWorkers", child->key) == 0)
1496 cf_util_get_boolean(child, &conf->collect_workers);
1497 else if (strcasecmp("CollectVSM", child->key) == 0)
1499 cf_util_get_boolean(child, &conf->collect_vsm);
1501 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1504 else if (strcasecmp("CollectLock", child->key) == 0)
1506 cf_util_get_boolean(child, &conf->collect_lck);
1508 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1511 else if (strcasecmp("CollectMempool", child->key) == 0)
1513 cf_util_get_boolean(child, &conf->collect_mempool);
1515 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1518 else if (strcasecmp("CollectManagement", child->key) == 0)
1520 cf_util_get_boolean(child, &conf->collect_mgt);
1522 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1525 else if (strcasecmp("CollectSMF", child->key) == 0)
1527 cf_util_get_boolean(child, &conf->collect_smf);
1529 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1532 else if (strcasecmp("CollectSMF", child->key) == 0)
1534 cf_util_get_boolean(child, &conf->collect_smf);
1536 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1539 else if (strcasecmp("CollectVBE", child->key) == 0)
1541 cf_util_get_boolean(child, &conf->collect_vbe);
1543 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1547 WARNING("Varnish plugin: Ignoring unknown "
1548 "configuration option: \"%s\". Did "
1549 "you forget to add an <Instance /> "
1550 "block around the configuration?",
1555 if (!conf->collect_cache && !conf->collect_connections &&
1556 !conf->collect_esi && !conf->collect_backend
1557 #ifdef HAVE_VARNISH_V3
1558 && !conf->collect_dirdns
1560 && !conf->collect_fetch && !conf->collect_hcb && !conf->collect_objects
1562 && !conf->collect_purge
1564 && !conf->collect_ban
1566 && !conf->collect_session && !conf->collect_shm && !conf->collect_sms
1568 && !conf->collect_sm
1570 #if HAVE_VARNISH_V2 || HAVE_VARNISH_V4
1571 && !conf->collect_sma
1573 && !conf->collect_struct && !conf->collect_totals
1574 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
1575 && !conf->collect_uptime
1577 && !conf->collect_vcl && !conf->collect_workers
1579 && !conf->collect_vsm && !conf->collect_vbe && !conf->collect_smf
1580 && !conf->collect_mgt && !conf->collect_lck && !conf->collect_mempool
1583 WARNING("Varnish plugin: No metric has been configured for "
1584 "instance \"%s\". Disabling this instance.",
1585 (conf->instance == NULL) ? "localhost" : conf->instance);
1590 snprintf(callback_name, sizeof(callback_name), "varnish/%s",
1591 (conf->instance == NULL) ? "localhost" : conf->instance);
1593 plugin_register_complex_read(
1594 /* group = */ "varnish",
1595 /* name = */ callback_name,
1596 /* callback = */ varnish_read,
1599 .data = conf, .free_func = varnish_config_free,
1605 } /* }}} int varnish_config_instance */
1607 static int varnish_config(oconfig_item_t *ci) /* {{{ */
1609 for (int i = 0; i < ci->children_num; i++) {
1610 oconfig_item_t *child = ci->children + i;
1612 if (strcasecmp("Instance", child->key) == 0)
1613 varnish_config_instance(child);
1615 WARNING("Varnish plugin: Ignoring unknown "
1616 "configuration option: \"%s\"",
1622 } /* }}} int varnish_config */
1624 void module_register(void) /* {{{ */
1626 plugin_register_complex_config("varnish", varnish_config);
1627 plugin_register_init("varnish", varnish_init);