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;
94 typedef struct user_config_s user_config_t; /* }}} */
96 static _Bool have_instance = 0;
98 static int varnish_submit(const char *plugin_instance, /* {{{ */
99 const char *category, const char *type,
100 const char *type_instance, value_t value) {
101 value_list_t vl = VALUE_LIST_INIT;
106 sstrncpy(vl.plugin, "varnish", sizeof(vl.plugin));
108 if (plugin_instance == NULL)
109 plugin_instance = "default";
110 snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s-%s",
111 plugin_instance, category);
113 sstrncpy(vl.type, type, sizeof(vl.type));
115 if (type_instance != NULL)
116 sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance));
118 return plugin_dispatch_values(&vl);
119 } /* }}} int varnish_submit */
121 static int varnish_submit_gauge(const char *plugin_instance, /* {{{ */
122 const char *category, const char *type,
123 const char *type_instance,
124 uint64_t gauge_value) {
125 return varnish_submit(plugin_instance, category, type, type_instance,
127 .gauge = (gauge_t)gauge_value,
129 } /* }}} int varnish_submit_gauge */
131 static int varnish_submit_derive(const char *plugin_instance, /* {{{ */
132 const char *category, const char *type,
133 const char *type_instance,
134 uint64_t derive_value) {
135 return varnish_submit(plugin_instance, category, type, type_instance,
137 .derive = (derive_t)derive_value,
139 } /* }}} int varnish_submit_derive */
141 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
142 static int varnish_monitor(void *priv,
143 const struct VSC_point *const pt) /* {{{ */
146 const user_config_t *conf;
156 class = pt->section->fantom->type;
157 name = pt->desc->name;
159 if (strcmp(class, "MAIN") != 0)
162 #elif HAVE_VARNISH_V3
166 if (strcmp(class, "") != 0)
170 val = *(const volatile uint64_t *)pt->ptr;
172 if (conf->collect_cache) {
173 if (strcmp(name, "cache_hit") == 0)
174 return varnish_submit_derive(conf->instance, "cache", "cache_result",
176 else if (strcmp(name, "cache_miss") == 0)
177 return varnish_submit_derive(conf->instance, "cache", "cache_result",
179 else if (strcmp(name, "cache_hitpass") == 0)
180 return varnish_submit_derive(conf->instance, "cache", "cache_result",
184 if (conf->collect_connections) {
185 if (strcmp(name, "client_conn") == 0)
186 return varnish_submit_derive(conf->instance, "connections", "connections",
188 else if (strcmp(name, "client_drop") == 0)
189 return varnish_submit_derive(conf->instance, "connections", "connections",
191 else if (strcmp(name, "client_req") == 0)
192 return varnish_submit_derive(conf->instance, "connections", "connections",
194 #ifdef HAVE_VARNISH_V4
195 else if (strcmp(name, "client_req_400") == 0)
196 return varnish_submit_derive(conf->instance, "connections", "connections",
198 else if (strcmp(name, "client_req_417") == 0)
199 return varnish_submit_derive(conf->instance, "connections", "connections",
204 #ifdef HAVE_VARNISH_V3
205 if (conf->collect_dirdns) {
206 if (strcmp(name, "dir_dns_lookups") == 0)
207 return varnish_submit_derive(conf->instance, "dirdns", "cache_operation",
209 else if (strcmp(name, "dir_dns_failed") == 0)
210 return varnish_submit_derive(conf->instance, "dirdns", "cache_result",
212 else if (strcmp(name, "dir_dns_hit") == 0)
213 return varnish_submit_derive(conf->instance, "dirdns", "cache_result",
215 else if (strcmp(name, "dir_dns_cache_full") == 0)
216 return varnish_submit_derive(conf->instance, "dirdns", "cache_result",
221 if (conf->collect_esi) {
222 if (strcmp(name, "esi_errors") == 0)
223 return varnish_submit_derive(conf->instance, "esi", "total_operations",
225 else if (strcmp(name, "esi_parse") == 0)
226 return varnish_submit_derive(conf->instance, "esi", "total_operations",
228 else if (strcmp(name, "esi_warnings") == 0)
229 return varnish_submit_derive(conf->instance, "esi", "total_operations",
231 else if (strcmp(name, "esi_maxdepth") == 0)
232 return varnish_submit_derive(conf->instance, "esi", "total_operations",
236 if (conf->collect_backend) {
237 if (strcmp(name, "backend_conn") == 0)
238 return varnish_submit_derive(conf->instance, "backend", "connections",
240 else if (strcmp(name, "backend_unhealthy") == 0)
241 return varnish_submit_derive(conf->instance, "backend", "connections",
242 "not-attempted", val);
243 else if (strcmp(name, "backend_busy") == 0)
244 return varnish_submit_derive(conf->instance, "backend", "connections",
246 else if (strcmp(name, "backend_fail") == 0)
247 return varnish_submit_derive(conf->instance, "backend", "connections",
249 else if (strcmp(name, "backend_reuse") == 0)
250 return varnish_submit_derive(conf->instance, "backend", "connections",
252 else if (strcmp(name, "backend_toolate") == 0)
253 return varnish_submit_derive(conf->instance, "backend", "connections",
255 else if (strcmp(name, "backend_recycle") == 0)
256 return varnish_submit_derive(conf->instance, "backend", "connections",
258 else if (strcmp(name, "backend_unused") == 0)
259 return varnish_submit_derive(conf->instance, "backend", "connections",
261 else if (strcmp(name, "backend_retry") == 0)
262 return varnish_submit_derive(conf->instance, "backend", "connections",
264 else if (strcmp(name, "backend_req") == 0)
265 return varnish_submit_derive(conf->instance, "backend", "http_requests",
267 else if (strcmp(name, "n_backend") == 0)
268 return varnish_submit_gauge(conf->instance, "backend", "backends",
272 if (conf->collect_fetch) {
273 if (strcmp(name, "fetch_head") == 0)
274 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
276 else if (strcmp(name, "fetch_length") == 0)
277 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
279 else if (strcmp(name, "fetch_chunked") == 0)
280 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
282 else if (strcmp(name, "fetch_eof") == 0)
283 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
285 else if (strcmp(name, "fetch_bad") == 0)
286 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
288 else if (strcmp(name, "fetch_close") == 0)
289 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
291 else if (strcmp(name, "fetch_oldhttp") == 0)
292 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
294 else if (strcmp(name, "fetch_zero") == 0)
295 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
297 else if (strcmp(name, "fetch_failed") == 0)
298 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
300 else if (strcmp(name, "fetch_1xx") == 0)
301 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
303 else if (strcmp(name, "fetch_204") == 0)
304 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
306 else if (strcmp(name, "fetch_304") == 0)
307 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
310 else if (strcmp(name, "fetch_no_thread") == 0)
311 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
313 else if (strcmp(name, "fetch_none") == 0)
314 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
316 else if (strcmp(name, "busy_sleep") == 0)
317 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
319 else if (strcmp(name, "busy_wakeup") == 0)
320 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
325 if (conf->collect_hcb) {
326 if (strcmp(name, "hcb_nolock") == 0)
327 return varnish_submit_derive(conf->instance, "hcb", "cache_operation",
328 "lookup_nolock", val);
329 else if (strcmp(name, "hcb_lock") == 0)
330 return varnish_submit_derive(conf->instance, "hcb", "cache_operation",
332 else if (strcmp(name, "hcb_insert") == 0)
333 return varnish_submit_derive(conf->instance, "hcb", "cache_operation",
337 if (conf->collect_objects) {
338 if (strcmp(name, "n_expired") == 0)
339 return varnish_submit_derive(conf->instance, "objects", "total_objects",
341 else if (strcmp(name, "n_lru_nuked") == 0)
342 return varnish_submit_derive(conf->instance, "objects", "total_objects",
344 else if (strcmp(name, "n_lru_saved") == 0)
345 return varnish_submit_derive(conf->instance, "objects", "total_objects",
347 else if (strcmp(name, "n_lru_moved") == 0)
348 return varnish_submit_derive(conf->instance, "objects", "total_objects",
350 else if (strcmp(name, "n_deathrow") == 0)
351 return varnish_submit_derive(conf->instance, "objects", "total_objects",
353 else if (strcmp(name, "losthdr") == 0)
354 return varnish_submit_derive(conf->instance, "objects", "total_objects",
355 "header_overflow", val);
356 else if (strcmp(name, "n_obj_purged") == 0)
357 return varnish_submit_derive(conf->instance, "objects", "total_objects",
359 else if (strcmp(name, "n_objsendfile") == 0)
360 return varnish_submit_derive(conf->instance, "objects", "total_objects",
361 "sent_sendfile", val);
362 else if (strcmp(name, "n_objwrite") == 0)
363 return varnish_submit_derive(conf->instance, "objects", "total_objects",
365 else if (strcmp(name, "n_objoverflow") == 0)
366 return varnish_submit_derive(conf->instance, "objects", "total_objects",
367 "workspace_overflow", val);
369 else if (strcmp(name, "exp_mailed") == 0)
370 return varnish_submit_gauge(conf->instance, "struct", "objects",
372 else if (strcmp(name, "exp_received") == 0)
373 return varnish_submit_gauge(conf->instance, "struct", "objects",
374 "exp_received", val);
379 if (conf->collect_ban) {
380 if (strcmp(name, "n_ban") == 0)
381 return varnish_submit_derive(conf->instance, "ban", "total_operations",
383 else if (strcmp(name, "n_ban_add") == 0)
384 return varnish_submit_derive(conf->instance, "ban", "total_operations",
386 else if (strcmp(name, "n_ban_retire") == 0)
387 return varnish_submit_derive(conf->instance, "ban", "total_operations",
389 else if (strcmp(name, "n_ban_obj_test") == 0)
390 return varnish_submit_derive(conf->instance, "ban", "total_operations",
391 "objects_tested", val);
392 else if (strcmp(name, "n_ban_re_test") == 0)
393 return varnish_submit_derive(conf->instance, "ban", "total_operations",
394 "regexps_tested", val);
395 else if (strcmp(name, "n_ban_dups") == 0)
396 return varnish_submit_derive(conf->instance, "ban", "total_operations",
401 if (conf->collect_ban) {
402 if (strcmp(name, "bans") == 0)
403 return varnish_submit_derive(conf->instance, "ban", "total_operations",
405 else if (strcmp(name, "bans_added") == 0)
406 return varnish_submit_derive(conf->instance, "ban", "total_operations",
408 else if (strcmp(name, "bans_obj") == 0)
409 return varnish_submit_derive(conf->instance, "ban", "total_operations",
411 else if (strcmp(name, "bans_req") == 0)
412 return varnish_submit_derive(conf->instance, "ban", "total_operations",
414 else if (strcmp(name, "bans_completed") == 0)
415 return varnish_submit_derive(conf->instance, "ban", "total_operations",
417 else if (strcmp(name, "bans_deleted") == 0)
418 return varnish_submit_derive(conf->instance, "ban", "total_operations",
420 else if (strcmp(name, "bans_tested") == 0)
421 return varnish_submit_derive(conf->instance, "ban", "total_operations",
423 else if (strcmp(name, "bans_dups") == 0)
424 return varnish_submit_derive(conf->instance, "ban", "total_operations",
426 else if (strcmp(name, "bans_tested") == 0)
427 return varnish_submit_derive(conf->instance, "ban", "total_operations",
429 else if (strcmp(name, "bans_lurker_contention") == 0)
430 return varnish_submit_derive(conf->instance, "ban", "total_operations",
431 "lurker_contention", val);
432 else if (strcmp(name, "bans_lurker_obj_killed") == 0)
433 return varnish_submit_derive(conf->instance, "ban", "total_operations",
434 "lurker_obj_killed", val);
435 else if (strcmp(name, "bans_lurker_tested") == 0)
436 return varnish_submit_derive(conf->instance, "ban", "total_operations",
437 "lurker_tested", val);
438 else if (strcmp(name, "bans_lurker_tests_tested") == 0)
439 return varnish_submit_derive(conf->instance, "ban", "total_operations",
440 "lurker_tests_tested", val);
441 else if (strcmp(name, "bans_obj_killed") == 0)
442 return varnish_submit_derive(conf->instance, "ban", "total_operations",
444 else if (strcmp(name, "bans_persisted_bytes") == 0)
445 return varnish_submit_derive(conf->instance, "ban", "total_bytes",
446 "persisted_bytes", val);
447 else if (strcmp(name, "bans_persisted_fragmentation") == 0)
448 return varnish_submit_derive(conf->instance, "ban", "total_bytes",
449 "persisted_fragmentation", val);
450 else if (strcmp(name, "bans_tests_tested") == 0)
451 return varnish_submit_derive(conf->instance, "ban", "total_operations",
452 "tests_tested", val);
457 if (conf->collect_session) {
458 if (strcmp(name, "sess_closed") == 0)
459 return varnish_submit_derive(conf->instance, "session",
460 "total_operations", "closed", val);
461 else if (strcmp(name, "sess_pipeline") == 0)
462 return varnish_submit_derive(conf->instance, "session",
463 "total_operations", "pipeline", val);
464 else if (strcmp(name, "sess_readahead") == 0)
465 return varnish_submit_derive(conf->instance, "session",
466 "total_operations", "readahead", val);
467 else if (strcmp(name, "sess_conn") == 0)
468 return varnish_submit_derive(conf->instance, "session",
469 "total_operations", "accepted", val);
470 else if (strcmp(name, "sess_drop") == 0)
471 return varnish_submit_derive(conf->instance, "session",
472 "total_operations", "dropped", val);
473 else if (strcmp(name, "sess_fail") == 0)
474 return varnish_submit_derive(conf->instance, "session",
475 "total_operations", "failed", val);
476 else if (strcmp(name, "sess_pipe_overflow") == 0)
477 return varnish_submit_derive(conf->instance, "session",
478 "total_operations", "overflow", val);
479 else if (strcmp(name, "sess_queued") == 0)
480 return varnish_submit_derive(conf->instance, "session",
481 "total_operations", "queued", val);
482 else if (strcmp(name, "sess_linger") == 0)
483 return varnish_submit_derive(conf->instance, "session",
484 "total_operations", "linger", val);
485 else if (strcmp(name, "sess_herd") == 0)
486 return varnish_submit_derive(conf->instance, "session",
487 "total_operations", "herd", val);
489 else if (strcmp(name, "sess_closed_err") == 0)
490 return varnish_submit_derive(conf->instance, "session",
491 "total_operations", "closed_err", val);
492 else if (strcmp(name, "sess_dropped") == 0)
493 return varnish_submit_derive(conf->instance, "session",
494 "total_operations", "dropped_for_thread", val);
498 if (conf->collect_shm) {
499 if (strcmp(name, "shm_records") == 0)
500 return varnish_submit_derive(conf->instance, "shm", "total_operations",
502 else if (strcmp(name, "shm_writes") == 0)
503 return varnish_submit_derive(conf->instance, "shm", "total_operations",
505 else if (strcmp(name, "shm_flushes") == 0)
506 return varnish_submit_derive(conf->instance, "shm", "total_operations",
508 else if (strcmp(name, "shm_cont") == 0)
509 return varnish_submit_derive(conf->instance, "shm", "total_operations",
511 else if (strcmp(name, "shm_cycles") == 0)
512 return varnish_submit_derive(conf->instance, "shm", "total_operations",
516 if (conf->collect_sms) {
517 if (strcmp(name, "sms_nreq") == 0)
518 return varnish_submit_derive(conf->instance, "sms", "total_requests",
520 else if (strcmp(name, "sms_nobj") == 0)
521 return varnish_submit_gauge(conf->instance, "sms", "requests",
523 else if (strcmp(name, "sms_nbytes") == 0)
524 return varnish_submit_gauge(conf->instance, "sms", "bytes", "outstanding",
526 else if (strcmp(name, "sms_balloc") == 0)
527 return varnish_submit_derive(conf->instance, "sms", "total_bytes",
529 else if (strcmp(name, "sms_bfree") == 0)
530 return varnish_submit_derive(conf->instance, "sms", "total_bytes", "free",
534 if (conf->collect_struct) {
535 if (strcmp(name, "n_sess_mem") == 0)
536 return varnish_submit_gauge(conf->instance, "struct", "current_sessions",
538 else if (strcmp(name, "n_sess") == 0)
539 return varnish_submit_gauge(conf->instance, "struct", "current_sessions",
541 else if (strcmp(name, "n_object") == 0)
542 return varnish_submit_gauge(conf->instance, "struct", "objects", "object",
544 else if (strcmp(name, "n_vampireobject") == 0)
545 return varnish_submit_gauge(conf->instance, "struct", "objects",
546 "vampireobject", val);
547 else if (strcmp(name, "n_objectcore") == 0)
548 return varnish_submit_gauge(conf->instance, "struct", "objects",
550 else if (strcmp(name, "n_waitinglist") == 0)
551 return varnish_submit_gauge(conf->instance, "struct", "objects",
553 else if (strcmp(name, "n_objecthead") == 0)
554 return varnish_submit_gauge(conf->instance, "struct", "objects",
556 else if (strcmp(name, "n_smf") == 0)
557 return varnish_submit_gauge(conf->instance, "struct", "objects", "smf",
559 else if (strcmp(name, "n_smf_frag") == 0)
560 return varnish_submit_gauge(conf->instance, "struct", "objects",
562 else if (strcmp(name, "n_smf_large") == 0)
563 return varnish_submit_gauge(conf->instance, "struct", "objects",
565 else if (strcmp(name, "n_vbe_conn") == 0)
566 return varnish_submit_gauge(conf->instance, "struct", "objects",
570 if (conf->collect_totals) {
571 if (strcmp(name, "s_sess") == 0)
572 return varnish_submit_derive(conf->instance, "totals", "total_sessions",
574 else if (strcmp(name, "s_req") == 0)
575 return varnish_submit_derive(conf->instance, "totals", "total_requests",
577 else if (strcmp(name, "s_pipe") == 0)
578 return varnish_submit_derive(conf->instance, "totals", "total_operations",
580 else if (strcmp(name, "s_pass") == 0)
581 return varnish_submit_derive(conf->instance, "totals", "total_operations",
583 else if (strcmp(name, "s_fetch") == 0)
584 return varnish_submit_derive(conf->instance, "totals", "total_operations",
586 else if (strcmp(name, "s_synth") == 0)
587 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
589 else if (strcmp(name, "s_req_hdrbytes") == 0)
590 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
592 else if (strcmp(name, "s_req_bodybytes") == 0)
593 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
595 else if (strcmp(name, "s_req_protobytes") == 0)
596 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
598 else if (strcmp(name, "s_resp_hdrbytes") == 0)
599 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
601 else if (strcmp(name, "s_resp_bodybytes") == 0)
602 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
604 else if (strcmp(name, "s_resp_protobytes") == 0)
605 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
607 else if (strcmp(name, "s_pipe_hdrbytes") == 0)
608 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
610 else if (strcmp(name, "s_pipe_in") == 0)
611 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
613 else if (strcmp(name, "s_pipe_out") == 0)
614 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
616 else if (strcmp(name, "n_purges") == 0)
617 return varnish_submit_derive(conf->instance, "totals", "total_operations",
619 else if (strcmp(name, "s_hdrbytes") == 0)
620 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
621 "header-bytes", val);
622 else if (strcmp(name, "s_bodybytes") == 0)
623 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
625 else if (strcmp(name, "n_gzip") == 0)
626 return varnish_submit_derive(conf->instance, "totals", "total_operations",
628 else if (strcmp(name, "n_gunzip") == 0)
629 return varnish_submit_derive(conf->instance, "totals", "total_operations",
633 if (conf->collect_uptime) {
634 if (strcmp(name, "uptime") == 0)
635 return varnish_submit_gauge(conf->instance, "uptime", "uptime",
636 "client_uptime", val);
639 if (conf->collect_vcl) {
640 if (strcmp(name, "n_vcl") == 0)
641 return varnish_submit_gauge(conf->instance, "vcl", "vcl", "total_vcl",
643 else if (strcmp(name, "n_vcl_avail") == 0)
644 return varnish_submit_gauge(conf->instance, "vcl", "vcl", "avail_vcl",
646 else if (strcmp(name, "n_vcl_discard") == 0)
647 return varnish_submit_gauge(conf->instance, "vcl", "vcl", "discarded_vcl",
649 else if (strcmp(name, "vmods") == 0)
650 return varnish_submit_gauge(conf->instance, "vcl", "objects", "vmod",
654 if (conf->collect_workers) {
655 if (strcmp(name, "threads") == 0)
656 return varnish_submit_gauge(conf->instance, "workers", "threads",
658 else if (strcmp(name, "threads_created") == 0)
659 return varnish_submit_derive(conf->instance, "workers", "total_threads",
661 else if (strcmp(name, "threads_failed") == 0)
662 return varnish_submit_derive(conf->instance, "workers", "total_threads",
664 else if (strcmp(name, "threads_limited") == 0)
665 return varnish_submit_derive(conf->instance, "workers", "total_threads",
667 else if (strcmp(name, "threads_destroyed") == 0)
668 return varnish_submit_derive(conf->instance, "workers", "total_threads",
670 else if (strcmp(name, "thread_queue_len") == 0)
671 return varnish_submit_gauge(conf->instance, "workers", "queue_length",
673 else if (strcmp(name, "n_wrk") == 0)
674 return varnish_submit_gauge(conf->instance, "workers", "threads",
676 else if (strcmp(name, "n_wrk_create") == 0)
677 return varnish_submit_derive(conf->instance, "workers", "total_threads",
679 else if (strcmp(name, "n_wrk_failed") == 0)
680 return varnish_submit_derive(conf->instance, "workers", "total_threads",
682 else if (strcmp(name, "n_wrk_max") == 0)
683 return varnish_submit_derive(conf->instance, "workers", "total_threads",
685 else if (strcmp(name, "n_wrk_drop") == 0)
686 return varnish_submit_derive(conf->instance, "workers", "total_threads",
688 else if (strcmp(name, "n_wrk_queue") == 0)
689 return varnish_submit_derive(conf->instance, "workers", "total_requests",
691 else if (strcmp(name, "n_wrk_overflow") == 0)
692 return varnish_submit_derive(conf->instance, "workers", "total_requests",
694 else if (strcmp(name, "n_wrk_queued") == 0)
695 return varnish_submit_derive(conf->instance, "workers", "total_requests",
697 else if (strcmp(name, "n_wrk_lqueue") == 0)
698 return varnish_submit_derive(conf->instance, "workers", "total_requests",
699 "queue_length", val);
701 else if (strcmp(name, "pools") == 0)
702 return varnish_submit_gauge(conf->instance, "workers", "pools",
704 else if (strcmp(name, "busy_killed") == 0)
705 return varnish_submit_derive(conf->instance, "workers", "http_requests",
711 if (conf->collect_vsm) {
712 if (strcmp(name, "vsm_free") == 0)
713 return varnish_submit_gauge(conf->instance, "vsm", "bytes", "free", val);
714 else if (strcmp(name, "vsm_used") == 0)
715 return varnish_submit_gauge(conf->instance, "vsm", "bytes", "used", val);
716 else if (strcmp(name, "vsm_cooling") == 0)
717 return varnish_submit_gauge(conf->instance, "vsm", "bytes", "cooling",
719 else if (strcmp(name, "vsm_overflow") == 0)
720 return varnish_submit_gauge(conf->instance, "vsm", "bytes", "overflow",
722 else if (strcmp(name, "vsm_overflowed") == 0)
723 return varnish_submit_derive(conf->instance, "vsm", "total_bytes",
727 if (conf->collect_vbe) {
728 /* @TODO figure out the collectd type for bitmap
729 if (strcmp(name, "happy") == 0)
730 return varnish_submit_derive(conf->instance, "vbe",
731 "bitmap", "happy_hprobes", val);
733 if (strcmp(name, "bereq_hdrbytes") == 0)
734 return varnish_submit_derive(conf->instance, "vbe",
735 "total_bytes", "bereq_hdrbytes", val);
736 else if (strcmp(name, "bereq_bodybytes") == 0)
737 return varnish_submit_derive(conf->instance, "vbe",
738 "total_bytes", "bereq_bodybytes", val);
739 else if (strcmp(name, "bereq_protobytes") == 0)
740 return varnish_submit_derive(conf->instance, "vbe",
741 "total_bytes", "bereq_protobytes", val);
742 else if (strcmp(name, "beresp_hdrbytes") == 0)
743 return varnish_submit_derive(conf->instance, "vbe",
744 "total_bytes", "beresp_hdrbytes", val);
745 else if (strcmp(name, "beresp_bodybytes") == 0)
746 return varnish_submit_derive(conf->instance, "vbe",
747 "total_bytes", "beresp_bodybytes", val);
748 else if (strcmp(name, "beresp_protobytes") == 0)
749 return varnish_submit_derive(conf->instance, "vbe",
750 "total_bytes", "beresp_protobytes", val);
751 else if (strcmp(name, "pipe_hdrbytes") == 0)
752 return varnish_submit_derive(conf->instance, "vbe",
753 "total_bytes", "pipe_hdrbytes", val);
754 else if (strcmp(name, "pipe_out") == 0)
755 return varnish_submit_derive(conf->instance, "vbe",
756 "total_bytes", "pipe_out", val);
757 else if (strcmp(name, "pipe_in") == 0)
758 return varnish_submit_derive(conf->instance, "vbe",
759 "total_bytes", "pipe_in", val);
760 else if (strcmp(name, "conn") == 0)
761 return varnish_submit_derive(conf->instance, "vbe", "connections",
763 else if (strcmp(name, "req") == 0)
764 return varnish_submit_derive(conf->instance, "vbe", "http_requests",
768 /* All Stevedores support these counters */
769 if (conf->collect_sma || conf->collect_smf || conf->collect_mse) {
772 if (conf->collect_sma)
773 strncpy(category, "sma", 4);
774 else if (conf->collect_smf)
775 strncpy(category, "smf", 4);
777 strncpy(category, "mse", 4);
779 if (strcmp(name, "c_req") == 0)
780 return varnish_submit_derive(conf->instance, category,
781 "total_operations", "alloc_req", val);
782 else if (strcmp(name, "c_fail") == 0)
783 return varnish_submit_derive(conf->instance, category,
784 "total_operations", "alloc_fail", val);
785 else if (strcmp(name, "c_bytes") == 0)
786 return varnish_submit_derive(conf->instance, category,
787 "total_bytes", "bytes_allocated", val);
788 else if (strcmp(name, "c_freed") == 0)
789 return varnish_submit_derive(conf->instance, category,
790 "total_bytes", "bytes_freed", val);
791 else if (strcmp(name, "g_alloc") == 0)
792 return varnish_submit_derive(conf->instance, category,
793 "total_operations", "alloc_outstanding", val);
794 else if (strcmp(name, "g_bytes") == 0)
795 return varnish_submit_gauge(conf->instance, category, "bytes",
796 "bytes_outstanding", val);
797 else if (strcmp(name, "g_space") == 0)
798 return varnish_submit_gauge(conf->instance, category, "bytes",
799 "bytes_available", val);
802 /* No SMA specific counters */
804 if (conf->collect_smf) {
805 if (strcmp(name, "g_smf") == 0)
806 return varnish_submit_gauge(conf->instance, "smf", "objects",
807 "n_struct_smf", val);
808 else if (strcmp(name, "g_smf_frag") == 0)
809 return varnish_submit_gauge(conf->instance, "smf", "objects",
810 "n_small_free_smf", val);
811 else if (strcmp(name, "g_smf_large") == 0)
812 return varnish_submit_gauge(conf->instance, "smf", "objects",
813 "n_large_free_smf", val);
816 if (conf->collect_mgt) {
817 if (strcmp(name, "uptime") == 0)
818 return varnish_submit_gauge(conf->instance, "mgt", "uptime",
819 "mgt_proc_uptime", val);
820 else if (strcmp(name, "child_start") == 0)
821 return varnish_submit_derive(conf->instance, "mgt",
822 "total_operations", "child_start", val);
823 else if (strcmp(name, "child_exit") == 0)
824 return varnish_submit_derive(conf->instance, "mgt",
825 "total_operations", "child_exit", val);
826 else if (strcmp(name, "child_stop") == 0)
827 return varnish_submit_derive(conf->instance, "mgt",
828 "total_operations", "child_stop", val);
829 else if (strcmp(name, "child_died") == 0)
830 return varnish_submit_derive(conf->instance, "mgt",
831 "total_operations", "child_died", val);
832 else if (strcmp(name, "child_dump") == 0)
833 return varnish_submit_derive(conf->instance, "mgt",
834 "total_operations", "child_dump", val);
835 else if (strcmp(name, "child_panic") == 0)
836 return varnish_submit_derive(conf->instance, "mgt",
837 "total_operations", "child_panic", val);
840 if (conf->collect_lck) {
841 if (strcmp(name, "creat") == 0)
842 return varnish_submit_gauge(conf->instance, "lck", "objects",
844 else if (strcmp(name, "destroy") == 0)
845 return varnish_submit_gauge(conf->instance, "lck", "objects",
847 else if (strcmp(name, "locks") == 0)
848 return varnish_submit_derive(conf->instance, "lck", "total_operations",
852 if (conf->collect_mempool) {
853 if (strcmp(name, "live") == 0)
854 return varnish_submit_gauge(conf->instance, "mempool", "objects",
856 else if (strcmp(name, "pool") == 0)
857 return varnish_submit_gauge(conf->instance, "mempool", "objects",
859 else if (strcmp(name, "sz_wanted") == 0)
860 return varnish_submit_gauge(conf->instance, "mempool", "bytes",
861 "size_requested", val);
862 else if (strcmp(name, "sz_actual") == 0)
863 return varnish_submit_gauge(conf->instance, "mempool", "bytes",
864 "size_allocated", val);
865 else if (strcmp(name, "allocs") == 0)
866 return varnish_submit_derive(conf->instance, "mempool",
867 "total_operations", "allocations", val);
868 else if (strcmp(name, "frees") == 0)
869 return varnish_submit_derive(conf->instance, "mempool",
870 "total_operations", "frees", val);
871 else if (strcmp(name, "recycle") == 0)
872 return varnish_submit_gauge(conf->instance, "mempool",
873 "objects", "recycled", val);
874 else if (strcmp(name, "timeout") == 0)
875 return varnish_submit_gauge(conf->instance, "mempool",
876 "objects", "timed_out", val);
877 else if (strcmp(name, "toosmall") == 0)
878 return varnish_submit_gauge(conf->instance, "mempool",
879 "objects", "too_small", val);
880 else if (strcmp(name, "surplus") == 0)
881 return varnish_submit_gauge(conf->instance, "mempool",
882 "objects", "surplus", val);
883 else if (strcmp(name, "randry") == 0)
884 return varnish_submit_gauge(conf->instance, "mempool",
885 "objects", "ran_dry", val);
888 if (conf->collect_mse) {
889 if (strcmp(name, "c_full") == 0)
890 return varnish_submit_derive(conf->instance, "mse",
891 "total_operations", "full_allocs", val);
892 else if (strcmp(name, "c_truncated") == 0)
893 return varnish_submit_derive(conf->instance, "mse",
894 "total_operations", "truncated_allocs", val);
895 else if (strcmp(name, "c_expanded") == 0)
896 return varnish_submit_derive(conf->instance, "mse",
897 "total_operations", "expanded_allocs", val);
898 else if (strcmp(name, "c_failed") == 0)
899 return varnish_submit_derive(conf->instance, "mse",
900 "total_operations", "failed_allocs", val);
901 else if (strcmp(name, "c_bytes") == 0)
902 return varnish_submit_derive(conf->instance, "mse",
903 "total_bytes", "bytes_allocated", val);
904 else if (strcmp(name, "c_freed") == 0)
905 return varnish_submit_derive(conf->instance, "mse",
906 "total_bytes", "bytes_freed", val);
907 else if (strcmp(name, "g_fo_alloc") == 0)
908 return varnish_submit_derive(conf->instance, "mse",
909 "total_operations", "fo_allocs_outstanding", val);
910 else if (strcmp(name, "g_fo_bytes") == 0)
911 return varnish_submit_gauge(conf->instance, "mse",
912 "bytes", "fo_bytes_outstanding", val);
913 else if (strcmp(name, "g_membuf_alloc") == 0)
914 return varnish_submit_gauge(conf->instance, "mse",
915 "objects", "membufs_allocated", val);
916 else if (strcmp(name, "g_membuf_inuse") == 0)
917 return varnish_submit_gauge(conf->instance, "mse",
918 "objects", "membufs_inuse", val);
919 else if (strcmp(name, "g_bans_bytes") == 0)
920 return varnish_submit_gauge(conf->instance, "mse",
921 "bytes", "persisted_banspace_used", val);
922 else if (strcmp(name, "g_bans_space") == 0)
923 return varnish_submit_gauge(conf->instance, "mse",
924 "bytes", "persisted_banspace_available", val);
925 else if (strcmp(name, "g_bans_persisted") == 0)
926 return varnish_submit_derive(conf->instance, "mse",
927 "total_operations", "bans_persisted", val);
928 else if (strcmp(name, "g_bans_lost") == 0)
929 return varnish_submit_derive(conf->instance, "mse",
930 "total_operations", "bans_lost", val);
933 else if (strcmp(name, "g_journal_bytes") == 0)
934 return varnish_submit_gauge(conf->instance, "mse_reg",
935 "bytes", "journal_bytes_used", val);
936 else if (strcmp(name, "g_journal_space") == 0)
937 return varnish_submit_gauge(conf->instance, "mse_reg",
938 "bytes", "journal_bytes_free", val);
941 else if (strcmp(name, "g_bigspace") == 0)
942 return varnish_submit_gauge(conf->instance, "mse_segagg",
943 "bytes", "big_extents_bytes_available", val);
944 else if (strcmp(name, "g_extfree") == 0)
945 return varnish_submit_gauge(conf->instance, "mse_segagg",
946 "objects", "free_extents", val);
947 else if (strcmp(name, "g_sparenode") == 0)
948 return varnish_submit_gauge(conf->instance, "mse_segagg",
949 "objects", "spare_nodes_available", val);
950 else if (strcmp(name, "g_objnode") == 0)
951 return varnish_submit_gauge(conf->instance, "mse_segagg",
952 "objects", "object_nodes_in_use", val);
953 else if (strcmp(name, "g_extnode") == 0)
954 return varnish_submit_gauge(conf->instance, "mse_segagg",
955 "objects", "extent_nodes_in_use", val);
956 else if (strcmp(name, "g_bigextfree") == 0)
957 return varnish_submit_gauge(conf->instance, "mse_segagg",
958 "objects", "free_big_extents", val);
959 else if (strcmp(name, "c_pruneloop") == 0)
960 return varnish_submit_derive(conf->instance, "mse_segagg",
961 "total_operations", "prune_loops", val);
962 else if (strcmp(name, "c_pruned") == 0)
963 return varnish_submit_derive(conf->instance, "mse_segagg",
964 "total_objects", "pruned_objects", val);
965 else if (strcmp(name, "c_spared") == 0)
966 return varnish_submit_derive(conf->instance, "mse_segagg",
967 "total_operations", "spared_objects", val);
968 else if (strcmp(name, "c_skipped") == 0)
969 return varnish_submit_derive(conf->instance, "mse_segagg",
970 "total_operations", "missed_objects", val);
971 else if (strcmp(name, "c_nuked") == 0)
972 return varnish_submit_derive(conf->instance, "mse_segagg",
973 "total_operations", "nuked_objects", val);
974 else if (strcmp(name, "c_sniped") == 0)
975 return varnish_submit_derive(conf->instance, "mse_segagg",
976 "total_operations", "sniped_objects", val);
984 } /* }}} static int varnish_monitor */
985 #else /* if HAVE_VARNISH_V2 */
986 static void varnish_monitor(const user_config_t *conf, /* {{{ */
987 const c_varnish_stats_t *stats) {
988 if (conf->collect_cache) {
990 varnish_submit_derive(conf->instance, "cache", "cache_result", "hit",
993 varnish_submit_derive(conf->instance, "cache", "cache_result", "miss",
995 /* Cache hits for pass */
996 varnish_submit_derive(conf->instance, "cache", "cache_result", "hitpass",
997 stats->cache_hitpass);
1000 if (conf->collect_connections) {
1001 /* Client connections accepted */
1002 varnish_submit_derive(conf->instance, "connections", "connections",
1003 "accepted", stats->client_conn);
1004 /* Connection dropped, no sess */
1005 varnish_submit_derive(conf->instance, "connections", "connections",
1006 "dropped", stats->client_drop);
1007 /* Client requests received */
1008 varnish_submit_derive(conf->instance, "connections", "connections",
1009 "received", stats->client_req);
1012 if (conf->collect_esi) {
1013 /* ESI parse errors (unlock) */
1014 varnish_submit_derive(conf->instance, "esi", "total_operations", "error",
1016 /* Objects ESI parsed (unlock) */
1017 varnish_submit_derive(conf->instance, "esi", "total_operations", "parsed",
1021 if (conf->collect_backend) {
1022 /* Backend conn. success */
1023 varnish_submit_derive(conf->instance, "backend", "connections", "success",
1024 stats->backend_conn);
1025 /* Backend conn. not attempted */
1026 varnish_submit_derive(conf->instance, "backend", "connections",
1027 "not-attempted", stats->backend_unhealthy);
1028 /* Backend conn. too many */
1029 varnish_submit_derive(conf->instance, "backend", "connections", "too-many",
1030 stats->backend_busy);
1031 /* Backend conn. failures */
1032 varnish_submit_derive(conf->instance, "backend", "connections", "failures",
1033 stats->backend_fail);
1034 /* Backend conn. reuses */
1035 varnish_submit_derive(conf->instance, "backend", "connections", "reuses",
1036 stats->backend_reuse);
1037 /* Backend conn. was closed */
1038 varnish_submit_derive(conf->instance, "backend", "connections",
1039 "was-closed", stats->backend_toolate);
1040 /* Backend conn. recycles */
1041 varnish_submit_derive(conf->instance, "backend", "connections", "recycled",
1042 stats->backend_recycle);
1043 /* Backend conn. unused */
1044 varnish_submit_derive(conf->instance, "backend", "connections", "unused",
1045 stats->backend_unused);
1046 /* Backend requests mades */
1047 varnish_submit_derive(conf->instance, "backend", "http_requests",
1048 "requests", stats->backend_req);
1050 varnish_submit_gauge(conf->instance, "backend", "backends", "n_backends",
1054 if (conf->collect_fetch) {
1056 varnish_submit_derive(conf->instance, "fetch", "http_requests", "head",
1058 /* Fetch with length */
1059 varnish_submit_derive(conf->instance, "fetch", "http_requests", "length",
1060 stats->fetch_length);
1062 varnish_submit_derive(conf->instance, "fetch", "http_requests", "chunked",
1063 stats->fetch_chunked);
1065 varnish_submit_derive(conf->instance, "fetch", "http_requests", "eof",
1067 /* Fetch bad headers */
1068 varnish_submit_derive(conf->instance, "fetch", "http_requests",
1069 "bad_headers", stats->fetch_bad);
1070 /* Fetch wanted close */
1071 varnish_submit_derive(conf->instance, "fetch", "http_requests", "close",
1072 stats->fetch_close);
1073 /* Fetch pre HTTP/1.1 closed */
1074 varnish_submit_derive(conf->instance, "fetch", "http_requests", "oldhttp",
1075 stats->fetch_oldhttp);
1076 /* Fetch zero len */
1077 varnish_submit_derive(conf->instance, "fetch", "http_requests", "zero",
1080 varnish_submit_derive(conf->instance, "fetch", "http_requests", "failed",
1081 stats->fetch_failed);
1084 if (conf->collect_hcb) {
1085 /* HCB Lookups without lock */
1086 varnish_submit_derive(conf->instance, "hcb", "cache_operation",
1087 "lookup_nolock", stats->hcb_nolock);
1088 /* HCB Lookups with lock */
1089 varnish_submit_derive(conf->instance, "hcb", "cache_operation",
1090 "lookup_lock", stats->hcb_lock);
1092 varnish_submit_derive(conf->instance, "hcb", "cache_operation", "insert",
1096 if (conf->collect_objects) {
1097 /* N expired objects */
1098 varnish_submit_derive(conf->instance, "objects", "total_objects", "expired",
1100 /* N LRU nuked objects */
1101 varnish_submit_derive(conf->instance, "objects", "total_objects",
1102 "lru_nuked", stats->n_lru_nuked);
1103 /* N LRU saved objects */
1104 varnish_submit_derive(conf->instance, "objects", "total_objects",
1105 "lru_saved", stats->n_lru_saved);
1106 /* N LRU moved objects */
1107 varnish_submit_derive(conf->instance, "objects", "total_objects",
1108 "lru_moved", stats->n_lru_moved);
1109 /* N objects on deathrow */
1110 varnish_submit_derive(conf->instance, "objects", "total_objects",
1111 "deathrow", stats->n_deathrow);
1112 /* HTTP header overflows */
1113 varnish_submit_derive(conf->instance, "objects", "total_objects",
1114 "header_overflow", stats->losthdr);
1115 /* Objects sent with sendfile */
1116 varnish_submit_derive(conf->instance, "objects", "total_objects",
1117 "sent_sendfile", stats->n_objsendfile);
1118 /* Objects sent with write */
1119 varnish_submit_derive(conf->instance, "objects", "total_objects",
1120 "sent_write", stats->n_objwrite);
1121 /* Objects overflowing workspace */
1122 varnish_submit_derive(conf->instance, "objects", "total_objects",
1123 "workspace_overflow", stats->n_objoverflow);
1126 if (conf->collect_purge) {
1127 /* N total active purges */
1128 varnish_submit_derive(conf->instance, "purge", "total_operations", "total",
1130 /* N new purges added */
1131 varnish_submit_derive(conf->instance, "purge", "total_operations", "added",
1132 stats->n_purge_add);
1133 /* N old purges deleted */
1134 varnish_submit_derive(conf->instance, "purge", "total_operations",
1135 "deleted", stats->n_purge_retire);
1136 /* N objects tested */
1137 varnish_submit_derive(conf->instance, "purge", "total_operations",
1138 "objects_tested", stats->n_purge_obj_test);
1139 /* N regexps tested against */
1140 varnish_submit_derive(conf->instance, "purge", "total_operations",
1141 "regexps_tested", stats->n_purge_re_test);
1142 /* N duplicate purges removed */
1143 varnish_submit_derive(conf->instance, "purge", "total_operations",
1144 "duplicate", stats->n_purge_dups);
1147 if (conf->collect_session) {
1148 /* Session Closed */
1149 varnish_submit_derive(conf->instance, "session", "total_operations",
1150 "closed", stats->sess_closed);
1151 /* Session Pipeline */
1152 varnish_submit_derive(conf->instance, "session", "total_operations",
1153 "pipeline", stats->sess_pipeline);
1154 /* Session Read Ahead */
1155 varnish_submit_derive(conf->instance, "session", "total_operations",
1156 "readahead", stats->sess_readahead);
1157 /* Session Linger */
1158 varnish_submit_derive(conf->instance, "session", "total_operations",
1159 "linger", stats->sess_linger);
1161 varnish_submit_derive(conf->instance, "session", "total_operations", "herd",
1165 if (conf->collect_shm) {
1167 varnish_submit_derive(conf->instance, "shm", "total_operations", "records",
1168 stats->shm_records);
1170 varnish_submit_derive(conf->instance, "shm", "total_operations", "writes",
1172 /* SHM flushes due to overflow */
1173 varnish_submit_derive(conf->instance, "shm", "total_operations", "flushes",
1174 stats->shm_flushes);
1175 /* SHM MTX contention */
1176 varnish_submit_derive(conf->instance, "shm", "total_operations",
1177 "contention", stats->shm_cont);
1178 /* SHM cycles through buffer */
1179 varnish_submit_derive(conf->instance, "shm", "total_operations", "cycles",
1183 if (conf->collect_sm) {
1184 /* allocator requests */
1185 varnish_submit_derive(conf->instance, "sm", "total_requests", "nreq",
1187 /* outstanding allocations */
1188 varnish_submit_gauge(conf->instance, "sm", "requests", "outstanding",
1190 /* bytes allocated */
1191 varnish_submit_derive(conf->instance, "sm", "total_bytes", "allocated",
1194 varnish_submit_derive(conf->instance, "sm", "total_bytes", "free",
1198 if (conf->collect_sma) {
1199 /* SMA allocator requests */
1200 varnish_submit_derive(conf->instance, "sma", "total_requests", "nreq",
1202 /* SMA outstanding allocations */
1203 varnish_submit_gauge(conf->instance, "sma", "requests", "outstanding",
1205 /* SMA outstanding bytes */
1206 varnish_submit_gauge(conf->instance, "sma", "bytes", "outstanding",
1208 /* SMA bytes allocated */
1209 varnish_submit_derive(conf->instance, "sma", "total_bytes", "allocated",
1211 /* SMA bytes free */
1212 varnish_submit_derive(conf->instance, "sma", "total_bytes", "free",
1216 if (conf->collect_sms) {
1217 /* SMS allocator requests */
1218 varnish_submit_derive(conf->instance, "sms", "total_requests", "allocator",
1220 /* SMS outstanding allocations */
1221 varnish_submit_gauge(conf->instance, "sms", "requests", "outstanding",
1223 /* SMS outstanding bytes */
1224 varnish_submit_gauge(conf->instance, "sms", "bytes", "outstanding",
1226 /* SMS bytes allocated */
1227 varnish_submit_derive(conf->instance, "sms", "total_bytes", "allocated",
1229 /* SMS bytes freed */
1230 varnish_submit_derive(conf->instance, "sms", "total_bytes", "free",
1234 if (conf->collect_struct) {
1235 /* N struct sess_mem */
1236 varnish_submit_gauge(conf->instance, "struct", "current_sessions",
1237 "sess_mem", stats->n_sess_mem);
1239 varnish_submit_gauge(conf->instance, "struct", "current_sessions", "sess",
1241 /* N struct object */
1242 varnish_submit_gauge(conf->instance, "struct", "objects", "object",
1244 /* N struct objecthead */
1245 varnish_submit_gauge(conf->instance, "struct", "objects", "objecthead",
1246 stats->n_objecthead);
1248 varnish_submit_gauge(conf->instance, "struct", "objects", "smf",
1250 /* N small free smf */
1251 varnish_submit_gauge(conf->instance, "struct", "objects", "smf_frag",
1253 /* N large free smf */
1254 varnish_submit_gauge(conf->instance, "struct", "objects", "smf_large",
1255 stats->n_smf_large);
1256 /* N struct vbe_conn */
1257 varnish_submit_gauge(conf->instance, "struct", "objects", "vbe_conn",
1261 if (conf->collect_totals) {
1262 /* Total Sessions */
1263 varnish_submit_derive(conf->instance, "totals", "total_sessions",
1264 "sessions", stats->s_sess);
1265 /* Total Requests */
1266 varnish_submit_derive(conf->instance, "totals", "total_requests",
1267 "requests", stats->s_req);
1269 varnish_submit_derive(conf->instance, "totals", "total_operations", "pipe",
1272 varnish_submit_derive(conf->instance, "totals", "total_operations", "pass",
1275 varnish_submit_derive(conf->instance, "totals", "total_operations",
1276 "fetches", stats->s_fetch);
1277 /* Total header bytes */
1278 varnish_submit_derive(conf->instance, "totals", "total_bytes",
1279 "header-bytes", stats->s_hdrbytes);
1280 /* Total body byte */
1281 varnish_submit_derive(conf->instance, "totals", "total_bytes", "body-bytes",
1282 stats->s_bodybytes);
1285 if (conf->collect_vcl) {
1287 varnish_submit_gauge(conf->instance, "vcl", "vcl", "total_vcl",
1289 /* N vcl available */
1290 varnish_submit_gauge(conf->instance, "vcl", "vcl", "avail_vcl",
1291 stats->n_vcl_avail);
1292 /* N vcl discarded */
1293 varnish_submit_gauge(conf->instance, "vcl", "vcl", "discarded_vcl",
1294 stats->n_vcl_discard);
1297 if (conf->collect_workers) {
1298 /* worker threads */
1299 varnish_submit_gauge(conf->instance, "workers", "threads", "worker",
1301 /* worker threads created */
1302 varnish_submit_derive(conf->instance, "workers", "total_threads", "created",
1303 stats->n_wrk_create);
1304 /* worker threads not created */
1305 varnish_submit_derive(conf->instance, "workers", "total_threads", "failed",
1306 stats->n_wrk_failed);
1307 /* worker threads limited */
1308 varnish_submit_derive(conf->instance, "workers", "total_threads", "limited",
1310 /* dropped work requests */
1311 varnish_submit_derive(conf->instance, "workers", "total_threads", "dropped",
1313 /* queued work requests */
1314 varnish_submit_derive(conf->instance, "workers", "total_requests", "queued",
1315 stats->n_wrk_queue);
1316 /* overflowed work requests */
1317 varnish_submit_derive(conf->instance, "workers", "total_requests",
1318 "overflowed", stats->n_wrk_overflow);
1321 } /* }}} void varnish_monitor */
1324 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
1325 static int varnish_read(user_data_t *ud) /* {{{ */
1327 struct VSM_data *vd;
1328 const c_varnish_stats_t *stats;
1331 user_config_t *conf;
1333 if ((ud == NULL) || (ud->data == NULL))
1343 if (conf->instance != NULL) {
1346 status = VSM_n_Arg(vd, conf->instance);
1349 ERROR("varnish plugin: VSM_n_Arg (\"%s\") failed "
1351 conf->instance, status);
1357 ok = (VSC_Open(vd, /* diag = */ 1) == 0);
1358 #else /* if HAVE_VARNISH_V4 */
1359 ok = (VSM_Open(vd) == 0);
1363 ERROR("varnish plugin: Unable to open connection.");
1369 stats = VSC_Main(vd);
1370 #else /* if HAVE_VARNISH_V4 */
1371 stats = VSC_Main(vd, NULL);
1375 ERROR("varnish plugin: Unable to get statistics.");
1381 VSC_Iter(vd, varnish_monitor, conf);
1382 #else /* if HAVE_VARNISH_V4 */
1383 VSC_Iter(vd, NULL, varnish_monitor, conf);
1389 #else /* if HAVE_VARNISH_V2 */
1390 static int varnish_read(user_data_t *ud) /* {{{ */
1392 const c_varnish_stats_t *stats;
1394 user_config_t *conf;
1396 if ((ud == NULL) || (ud->data == NULL))
1401 stats = VSL_OpenStats(conf->instance);
1402 if (stats == NULL) {
1403 ERROR("Varnish plugin : unable to load statistics");
1408 varnish_monitor(conf, stats);
1414 static void varnish_config_free(void *ptr) /* {{{ */
1416 user_config_t *conf = ptr;
1421 sfree(conf->instance);
1425 static int varnish_config_apply_default(user_config_t *conf) /* {{{ */
1430 conf->collect_backend = 1;
1431 conf->collect_cache = 1;
1432 conf->collect_connections = 1;
1433 #ifdef HAVE_VARNISH_V3
1434 conf->collect_dirdns = 0;
1436 conf->collect_esi = 0;
1437 conf->collect_fetch = 0;
1438 conf->collect_hcb = 0;
1439 conf->collect_objects = 0;
1441 conf->collect_purge = 0;
1443 conf->collect_ban = 0;
1445 conf->collect_session = 0;
1446 conf->collect_shm = 1;
1448 conf->collect_sm = 0;
1450 #if HAVE_VARNISH_V2 || HAVE_VARNISH_V4
1451 conf->collect_sma = 0;
1453 conf->collect_sms = 0;
1454 conf->collect_struct = 0;
1455 conf->collect_totals = 0;
1456 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
1457 conf->collect_uptime = 0;
1459 conf->collect_vcl = 0;
1460 conf->collect_workers = 0;
1462 conf->collect_vsm = 0;
1463 conf->collect_lck = 0;
1464 conf->collect_mempool = 0;
1465 conf->collect_mgt = 0;
1466 conf->collect_smf = 0;
1467 conf->collect_vbe = 0;
1468 conf->collect_mse = 0;
1472 } /* }}} int varnish_config_apply_default */
1474 static int varnish_init(void) /* {{{ */
1476 user_config_t *conf;
1481 conf = calloc(1, sizeof(*conf));
1485 /* Default settings: */
1486 conf->instance = NULL;
1488 varnish_config_apply_default(conf);
1490 plugin_register_complex_read(
1491 /* group = */ "varnish",
1492 /* name = */ "varnish/localhost",
1493 /* callback = */ varnish_read,
1496 .data = conf, .free_func = varnish_config_free,
1500 } /* }}} int varnish_init */
1502 static int varnish_config_instance(const oconfig_item_t *ci) /* {{{ */
1504 user_config_t *conf;
1505 char callback_name[DATA_MAX_NAME_LEN];
1507 conf = calloc(1, sizeof(*conf));
1510 conf->instance = NULL;
1512 varnish_config_apply_default(conf);
1514 if (ci->values_num == 1) {
1517 status = cf_util_get_string(ci, &conf->instance);
1522 assert(conf->instance != NULL);
1524 if (strcmp("localhost", conf->instance) == 0) {
1525 sfree(conf->instance);
1526 conf->instance = NULL;
1528 } else if (ci->values_num > 1) {
1529 WARNING("Varnish plugin: \"Instance\" blocks accept only "
1535 for (int i = 0; i < ci->children_num; i++) {
1536 oconfig_item_t *child = ci->children + i;
1538 if (strcasecmp("CollectCache", child->key) == 0)
1539 cf_util_get_boolean(child, &conf->collect_cache);
1540 else if (strcasecmp("CollectConnections", child->key) == 0)
1541 cf_util_get_boolean(child, &conf->collect_connections);
1542 else if (strcasecmp("CollectESI", child->key) == 0)
1543 cf_util_get_boolean(child, &conf->collect_esi);
1544 else if (strcasecmp("CollectDirectorDNS", child->key) == 0)
1545 #ifdef HAVE_VARNISH_V3
1546 cf_util_get_boolean(child, &conf->collect_dirdns);
1548 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1551 else if (strcasecmp("CollectBackend", child->key) == 0)
1552 cf_util_get_boolean(child, &conf->collect_backend);
1553 else if (strcasecmp("CollectFetch", child->key) == 0)
1554 cf_util_get_boolean(child, &conf->collect_fetch);
1555 else if (strcasecmp("CollectHCB", child->key) == 0)
1556 cf_util_get_boolean(child, &conf->collect_hcb);
1557 else if (strcasecmp("CollectObjects", child->key) == 0)
1558 cf_util_get_boolean(child, &conf->collect_objects);
1559 else if (strcasecmp("CollectPurge", child->key) == 0)
1561 cf_util_get_boolean(child, &conf->collect_purge);
1563 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1566 else if (strcasecmp("CollectBan", child->key) == 0)
1568 WARNING("Varnish plugin: \"%s\" is not available for Varnish %s.",
1571 cf_util_get_boolean(child, &conf->collect_ban);
1573 else if (strcasecmp("CollectSession", child->key) == 0)
1574 cf_util_get_boolean(child, &conf->collect_session);
1575 else if (strcasecmp("CollectSHM", child->key) == 0)
1576 cf_util_get_boolean(child, &conf->collect_shm);
1577 else if (strcasecmp("CollectSMS", child->key) == 0)
1578 cf_util_get_boolean(child, &conf->collect_sms);
1579 else if (strcasecmp("CollectSMA", child->key) == 0)
1580 #if HAVE_VARNISH_V2 || HAVE_VARNISH_V4
1581 cf_util_get_boolean(child, &conf->collect_sma);
1583 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1584 child->key, "v2 and v4");
1586 else if (strcasecmp("CollectSM", child->key) == 0)
1588 cf_util_get_boolean(child, &conf->collect_sm);
1590 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1593 else if (strcasecmp("CollectStruct", child->key) == 0)
1594 cf_util_get_boolean(child, &conf->collect_struct);
1595 else if (strcasecmp("CollectTotals", child->key) == 0)
1596 cf_util_get_boolean(child, &conf->collect_totals);
1597 else if (strcasecmp("CollectUptime", child->key) == 0)
1598 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
1599 cf_util_get_boolean(child, &conf->collect_uptime);
1601 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1602 child->key, "v3 and v4");
1604 else if (strcasecmp("CollectVCL", child->key) == 0)
1605 cf_util_get_boolean(child, &conf->collect_vcl);
1606 else if (strcasecmp("CollectWorkers", child->key) == 0)
1607 cf_util_get_boolean(child, &conf->collect_workers);
1608 else if (strcasecmp("CollectVSM", child->key) == 0)
1610 cf_util_get_boolean(child, &conf->collect_vsm);
1612 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1615 else if (strcasecmp("CollectLock", child->key) == 0)
1617 cf_util_get_boolean(child, &conf->collect_lck);
1619 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1622 else if (strcasecmp("CollectMempool", child->key) == 0)
1624 cf_util_get_boolean(child, &conf->collect_mempool);
1626 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1629 else if (strcasecmp("CollectManagement", child->key) == 0)
1631 cf_util_get_boolean(child, &conf->collect_mgt);
1633 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1636 else if (strcasecmp("CollectSMF", child->key) == 0)
1638 cf_util_get_boolean(child, &conf->collect_smf);
1640 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1643 else if (strcasecmp("CollectSMF", child->key) == 0)
1645 cf_util_get_boolean(child, &conf->collect_smf);
1647 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1650 else if (strcasecmp("CollectVBE", child->key) == 0)
1652 cf_util_get_boolean(child, &conf->collect_vbe);
1654 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1657 else if (strcasecmp("CollectMSE", child->key) == 0)
1659 cf_util_get_boolean(child, &conf->collect_mse);
1661 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1662 child->key, "Plus v4");
1665 WARNING("Varnish plugin: Ignoring unknown "
1666 "configuration option: \"%s\". Did "
1667 "you forget to add an <Instance /> "
1668 "block around the configuration?",
1673 if (!conf->collect_cache && !conf->collect_connections &&
1674 !conf->collect_esi && !conf->collect_backend
1675 #ifdef HAVE_VARNISH_V3
1676 && !conf->collect_dirdns
1678 && !conf->collect_fetch && !conf->collect_hcb && !conf->collect_objects
1680 && !conf->collect_purge
1682 && !conf->collect_ban
1684 && !conf->collect_session && !conf->collect_shm && !conf->collect_sms
1686 && !conf->collect_sm
1688 #if HAVE_VARNISH_V2 || HAVE_VARNISH_V4
1689 && !conf->collect_sma
1691 && !conf->collect_struct && !conf->collect_totals
1692 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
1693 && !conf->collect_uptime
1695 && !conf->collect_vcl && !conf->collect_workers
1697 && !conf->collect_vsm && !conf->collect_vbe && !conf->collect_smf
1698 && !conf->collect_mgt && !conf->collect_lck && !conf->collect_mempool
1699 && !conf->collect_mse
1702 WARNING("Varnish plugin: No metric has been configured for "
1703 "instance \"%s\". Disabling this instance.",
1704 (conf->instance == NULL) ? "localhost" : conf->instance);
1709 snprintf(callback_name, sizeof(callback_name), "varnish/%s",
1710 (conf->instance == NULL) ? "localhost" : conf->instance);
1712 plugin_register_complex_read(
1713 /* group = */ "varnish",
1714 /* name = */ callback_name,
1715 /* callback = */ varnish_read,
1718 .data = conf, .free_func = varnish_config_free,
1724 } /* }}} int varnish_config_instance */
1726 static int varnish_config(oconfig_item_t *ci) /* {{{ */
1728 for (int i = 0; i < ci->children_num; i++) {
1729 oconfig_item_t *child = ci->children + i;
1731 if (strcasecmp("Instance", child->key) == 0)
1732 varnish_config_instance(child);
1734 WARNING("Varnish plugin: Ignoring unknown "
1735 "configuration option: \"%s\"",
1741 } /* }}} int varnish_config */
1743 void module_register(void) /* {{{ */
1745 plugin_register_complex_config("varnish", varnish_config);
1746 plugin_register_init("varnish", varnish_init);