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>
32 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
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 || HAVE_VARNISH_V5
79 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
83 _Bool collect_workers;
84 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
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 || HAVE_VARNISH_V5
142 static int varnish_monitor(void *priv,
143 const struct VSC_point *const pt) /* {{{ */
146 const user_config_t *conf;
155 char namebuff[DATA_MAX_NAME_LEN];
157 char const *c = strrchr(pt->name, '.');
161 sstrncpy(namebuff, c + 1, sizeof(namebuff));
164 #elif HAVE_VARNISH_V4
165 if (strcmp(pt->section->fantom->type, "MAIN") != 0)
168 name = pt->desc->name;
169 #elif HAVE_VARNISH_V3
170 if (strcmp(pt->class, "") != 0)
176 val = *(const volatile uint64_t *)pt->ptr;
178 if (conf->collect_cache) {
179 if (strcmp(name, "cache_hit") == 0)
180 return varnish_submit_derive(conf->instance, "cache", "cache_result",
182 else if (strcmp(name, "cache_miss") == 0)
183 return varnish_submit_derive(conf->instance, "cache", "cache_result",
185 else if (strcmp(name, "cache_hitpass") == 0)
186 return varnish_submit_derive(conf->instance, "cache", "cache_result",
190 if (conf->collect_connections) {
191 if (strcmp(name, "client_conn") == 0)
192 return varnish_submit_derive(conf->instance, "connections", "connections",
194 else if (strcmp(name, "client_drop") == 0)
195 return varnish_submit_derive(conf->instance, "connections", "connections",
197 else if (strcmp(name, "client_req") == 0)
198 return varnish_submit_derive(conf->instance, "connections", "connections",
200 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
201 else if (strcmp(name, "client_req_400") == 0)
202 return varnish_submit_derive(conf->instance, "connections", "connections",
204 else if (strcmp(name, "client_req_417") == 0)
205 return varnish_submit_derive(conf->instance, "connections", "connections",
210 #ifdef HAVE_VARNISH_V3
211 if (conf->collect_dirdns) {
212 if (strcmp(name, "dir_dns_lookups") == 0)
213 return varnish_submit_derive(conf->instance, "dirdns", "cache_operation",
215 else if (strcmp(name, "dir_dns_failed") == 0)
216 return varnish_submit_derive(conf->instance, "dirdns", "cache_result",
218 else if (strcmp(name, "dir_dns_hit") == 0)
219 return varnish_submit_derive(conf->instance, "dirdns", "cache_result",
221 else if (strcmp(name, "dir_dns_cache_full") == 0)
222 return varnish_submit_derive(conf->instance, "dirdns", "cache_result",
227 if (conf->collect_esi) {
228 if (strcmp(name, "esi_errors") == 0)
229 return varnish_submit_derive(conf->instance, "esi", "total_operations",
231 else if (strcmp(name, "esi_parse") == 0)
232 return varnish_submit_derive(conf->instance, "esi", "total_operations",
234 else if (strcmp(name, "esi_warnings") == 0)
235 return varnish_submit_derive(conf->instance, "esi", "total_operations",
237 else if (strcmp(name, "esi_maxdepth") == 0)
238 return varnish_submit_derive(conf->instance, "esi", "total_operations",
242 if (conf->collect_backend) {
243 if (strcmp(name, "backend_conn") == 0)
244 return varnish_submit_derive(conf->instance, "backend", "connections",
246 else if (strcmp(name, "backend_unhealthy") == 0)
247 return varnish_submit_derive(conf->instance, "backend", "connections",
248 "not-attempted", val);
249 else if (strcmp(name, "backend_busy") == 0)
250 return varnish_submit_derive(conf->instance, "backend", "connections",
252 else if (strcmp(name, "backend_fail") == 0)
253 return varnish_submit_derive(conf->instance, "backend", "connections",
255 else if (strcmp(name, "backend_reuse") == 0)
256 return varnish_submit_derive(conf->instance, "backend", "connections",
258 else if (strcmp(name, "backend_toolate") == 0)
259 return varnish_submit_derive(conf->instance, "backend", "connections",
261 else if (strcmp(name, "backend_recycle") == 0)
262 return varnish_submit_derive(conf->instance, "backend", "connections",
264 else if (strcmp(name, "backend_unused") == 0)
265 return varnish_submit_derive(conf->instance, "backend", "connections",
267 else if (strcmp(name, "backend_retry") == 0)
268 return varnish_submit_derive(conf->instance, "backend", "connections",
270 else if (strcmp(name, "backend_req") == 0)
271 return varnish_submit_derive(conf->instance, "backend", "http_requests",
273 else if (strcmp(name, "n_backend") == 0)
274 return varnish_submit_gauge(conf->instance, "backend", "backends",
278 if (conf->collect_fetch) {
279 if (strcmp(name, "fetch_head") == 0)
280 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
282 else if (strcmp(name, "fetch_length") == 0)
283 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
285 else if (strcmp(name, "fetch_chunked") == 0)
286 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
288 else if (strcmp(name, "fetch_eof") == 0)
289 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
291 else if (strcmp(name, "fetch_bad") == 0)
292 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
294 else if (strcmp(name, "fetch_close") == 0)
295 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
297 else if (strcmp(name, "fetch_oldhttp") == 0)
298 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
300 else if (strcmp(name, "fetch_zero") == 0)
301 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
303 else if (strcmp(name, "fetch_failed") == 0)
304 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
306 else if (strcmp(name, "fetch_1xx") == 0)
307 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
309 else if (strcmp(name, "fetch_204") == 0)
310 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
312 else if (strcmp(name, "fetch_304") == 0)
313 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
315 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
316 else if (strcmp(name, "fetch_no_thread") == 0)
317 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
319 else if (strcmp(name, "fetch_none") == 0)
320 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
322 else if (strcmp(name, "busy_sleep") == 0)
323 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
325 else if (strcmp(name, "busy_wakeup") == 0)
326 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
331 if (conf->collect_hcb) {
332 if (strcmp(name, "hcb_nolock") == 0)
333 return varnish_submit_derive(conf->instance, "hcb", "cache_operation",
334 "lookup_nolock", val);
335 else if (strcmp(name, "hcb_lock") == 0)
336 return varnish_submit_derive(conf->instance, "hcb", "cache_operation",
338 else if (strcmp(name, "hcb_insert") == 0)
339 return varnish_submit_derive(conf->instance, "hcb", "cache_operation",
343 if (conf->collect_objects) {
344 if (strcmp(name, "n_expired") == 0)
345 return varnish_submit_derive(conf->instance, "objects", "total_objects",
347 else if (strcmp(name, "n_lru_nuked") == 0)
348 return varnish_submit_derive(conf->instance, "objects", "total_objects",
350 else if (strcmp(name, "n_lru_saved") == 0)
351 return varnish_submit_derive(conf->instance, "objects", "total_objects",
353 else if (strcmp(name, "n_lru_moved") == 0)
354 return varnish_submit_derive(conf->instance, "objects", "total_objects",
356 else if (strcmp(name, "n_deathrow") == 0)
357 return varnish_submit_derive(conf->instance, "objects", "total_objects",
359 else if (strcmp(name, "losthdr") == 0)
360 return varnish_submit_derive(conf->instance, "objects", "total_objects",
361 "header_overflow", val);
362 else if (strcmp(name, "n_obj_purged") == 0)
363 return varnish_submit_derive(conf->instance, "objects", "total_objects",
365 else if (strcmp(name, "n_objsendfile") == 0)
366 return varnish_submit_derive(conf->instance, "objects", "total_objects",
367 "sent_sendfile", val);
368 else if (strcmp(name, "n_objwrite") == 0)
369 return varnish_submit_derive(conf->instance, "objects", "total_objects",
371 else if (strcmp(name, "n_objoverflow") == 0)
372 return varnish_submit_derive(conf->instance, "objects", "total_objects",
373 "workspace_overflow", val);
374 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
375 else if (strcmp(name, "exp_mailed") == 0)
376 return varnish_submit_gauge(conf->instance, "struct", "objects",
378 else if (strcmp(name, "exp_received") == 0)
379 return varnish_submit_gauge(conf->instance, "struct", "objects",
380 "exp_received", val);
385 if (conf->collect_ban) {
386 if (strcmp(name, "n_ban") == 0)
387 return varnish_submit_derive(conf->instance, "ban", "total_operations",
389 else if (strcmp(name, "n_ban_add") == 0)
390 return varnish_submit_derive(conf->instance, "ban", "total_operations",
392 else if (strcmp(name, "n_ban_retire") == 0)
393 return varnish_submit_derive(conf->instance, "ban", "total_operations",
395 else if (strcmp(name, "n_ban_obj_test") == 0)
396 return varnish_submit_derive(conf->instance, "ban", "total_operations",
397 "objects_tested", val);
398 else if (strcmp(name, "n_ban_re_test") == 0)
399 return varnish_submit_derive(conf->instance, "ban", "total_operations",
400 "regexps_tested", val);
401 else if (strcmp(name, "n_ban_dups") == 0)
402 return varnish_submit_derive(conf->instance, "ban", "total_operations",
406 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
407 if (conf->collect_ban) {
408 if (strcmp(name, "bans") == 0)
409 return varnish_submit_derive(conf->instance, "ban", "total_operations",
411 else if (strcmp(name, "bans_added") == 0)
412 return varnish_submit_derive(conf->instance, "ban", "total_operations",
414 else if (strcmp(name, "bans_obj") == 0)
415 return varnish_submit_derive(conf->instance, "ban", "total_operations",
417 else if (strcmp(name, "bans_req") == 0)
418 return varnish_submit_derive(conf->instance, "ban", "total_operations",
420 else if (strcmp(name, "bans_completed") == 0)
421 return varnish_submit_derive(conf->instance, "ban", "total_operations",
423 else if (strcmp(name, "bans_deleted") == 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_dups") == 0)
430 return varnish_submit_derive(conf->instance, "ban", "total_operations",
432 else if (strcmp(name, "bans_tested") == 0)
433 return varnish_submit_derive(conf->instance, "ban", "total_operations",
435 else if (strcmp(name, "bans_lurker_contention") == 0)
436 return varnish_submit_derive(conf->instance, "ban", "total_operations",
437 "lurker_contention", val);
438 else if (strcmp(name, "bans_lurker_obj_killed") == 0)
439 return varnish_submit_derive(conf->instance, "ban", "total_operations",
440 "lurker_obj_killed", val);
441 else if (strcmp(name, "bans_lurker_tested") == 0)
442 return varnish_submit_derive(conf->instance, "ban", "total_operations",
443 "lurker_tested", val);
444 else if (strcmp(name, "bans_lurker_tests_tested") == 0)
445 return varnish_submit_derive(conf->instance, "ban", "total_operations",
446 "lurker_tests_tested", val);
447 else if (strcmp(name, "bans_obj_killed") == 0)
448 return varnish_submit_derive(conf->instance, "ban", "total_operations",
450 else if (strcmp(name, "bans_persisted_bytes") == 0)
451 return varnish_submit_derive(conf->instance, "ban", "total_bytes",
452 "persisted_bytes", val);
453 else if (strcmp(name, "bans_persisted_fragmentation") == 0)
454 return varnish_submit_derive(conf->instance, "ban", "total_bytes",
455 "persisted_fragmentation", val);
456 else if (strcmp(name, "bans_tests_tested") == 0)
457 return varnish_submit_derive(conf->instance, "ban", "total_operations",
458 "tests_tested", val);
462 if (conf->collect_session) {
463 if (strcmp(name, "sess_closed") == 0)
464 return varnish_submit_derive(conf->instance, "session",
465 "total_operations", "closed", val);
466 else if (strcmp(name, "sess_pipeline") == 0)
467 return varnish_submit_derive(conf->instance, "session",
468 "total_operations", "pipeline", val);
469 else if (strcmp(name, "sess_readahead") == 0)
470 return varnish_submit_derive(conf->instance, "session",
471 "total_operations", "readahead", val);
472 else if (strcmp(name, "sess_conn") == 0)
473 return varnish_submit_derive(conf->instance, "session",
474 "total_operations", "accepted", val);
475 else if (strcmp(name, "sess_drop") == 0)
476 return varnish_submit_derive(conf->instance, "session",
477 "total_operations", "dropped", val);
478 else if (strcmp(name, "sess_fail") == 0)
479 return varnish_submit_derive(conf->instance, "session",
480 "total_operations", "failed", val);
481 else if (strcmp(name, "sess_pipe_overflow") == 0)
482 return varnish_submit_derive(conf->instance, "session",
483 "total_operations", "overflow", val);
484 else if (strcmp(name, "sess_queued") == 0)
485 return varnish_submit_derive(conf->instance, "session",
486 "total_operations", "queued", val);
487 else if (strcmp(name, "sess_linger") == 0)
488 return varnish_submit_derive(conf->instance, "session",
489 "total_operations", "linger", val);
490 else if (strcmp(name, "sess_herd") == 0)
491 return varnish_submit_derive(conf->instance, "session",
492 "total_operations", "herd", val);
493 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
494 else if (strcmp(name, "sess_closed_err") == 0)
495 return varnish_submit_derive(conf->instance, "session",
496 "total_operations", "closed_err", val);
497 else if (strcmp(name, "sess_dropped") == 0)
498 return varnish_submit_derive(conf->instance, "session",
499 "total_operations", "dropped_for_thread",
504 if (conf->collect_shm) {
505 if (strcmp(name, "shm_records") == 0)
506 return varnish_submit_derive(conf->instance, "shm", "total_operations",
508 else if (strcmp(name, "shm_writes") == 0)
509 return varnish_submit_derive(conf->instance, "shm", "total_operations",
511 else if (strcmp(name, "shm_flushes") == 0)
512 return varnish_submit_derive(conf->instance, "shm", "total_operations",
514 else if (strcmp(name, "shm_cont") == 0)
515 return varnish_submit_derive(conf->instance, "shm", "total_operations",
517 else if (strcmp(name, "shm_cycles") == 0)
518 return varnish_submit_derive(conf->instance, "shm", "total_operations",
522 if (conf->collect_sms) {
523 if (strcmp(name, "sms_nreq") == 0)
524 return varnish_submit_derive(conf->instance, "sms", "total_requests",
526 else if (strcmp(name, "sms_nobj") == 0)
527 return varnish_submit_gauge(conf->instance, "sms", "requests",
529 else if (strcmp(name, "sms_nbytes") == 0)
530 return varnish_submit_gauge(conf->instance, "sms", "bytes", "outstanding",
532 else if (strcmp(name, "sms_balloc") == 0)
533 return varnish_submit_derive(conf->instance, "sms", "total_bytes",
535 else if (strcmp(name, "sms_bfree") == 0)
536 return varnish_submit_derive(conf->instance, "sms", "total_bytes", "free",
540 if (conf->collect_struct) {
541 if (strcmp(name, "n_sess_mem") == 0)
542 return varnish_submit_gauge(conf->instance, "struct", "current_sessions",
544 else if (strcmp(name, "n_sess") == 0)
545 return varnish_submit_gauge(conf->instance, "struct", "current_sessions",
547 else if (strcmp(name, "n_object") == 0)
548 return varnish_submit_gauge(conf->instance, "struct", "objects", "object",
550 else if (strcmp(name, "n_vampireobject") == 0)
551 return varnish_submit_gauge(conf->instance, "struct", "objects",
552 "vampireobject", val);
553 else if (strcmp(name, "n_objectcore") == 0)
554 return varnish_submit_gauge(conf->instance, "struct", "objects",
556 else if (strcmp(name, "n_waitinglist") == 0)
557 return varnish_submit_gauge(conf->instance, "struct", "objects",
559 else if (strcmp(name, "n_objecthead") == 0)
560 return varnish_submit_gauge(conf->instance, "struct", "objects",
562 else if (strcmp(name, "n_smf") == 0)
563 return varnish_submit_gauge(conf->instance, "struct", "objects", "smf",
565 else if (strcmp(name, "n_smf_frag") == 0)
566 return varnish_submit_gauge(conf->instance, "struct", "objects",
568 else if (strcmp(name, "n_smf_large") == 0)
569 return varnish_submit_gauge(conf->instance, "struct", "objects",
571 else if (strcmp(name, "n_vbe_conn") == 0)
572 return varnish_submit_gauge(conf->instance, "struct", "objects",
576 if (conf->collect_totals) {
577 if (strcmp(name, "s_sess") == 0)
578 return varnish_submit_derive(conf->instance, "totals", "total_sessions",
580 else if (strcmp(name, "s_req") == 0)
581 return varnish_submit_derive(conf->instance, "totals", "total_requests",
583 else if (strcmp(name, "s_pipe") == 0)
584 return varnish_submit_derive(conf->instance, "totals", "total_operations",
586 else if (strcmp(name, "s_pass") == 0)
587 return varnish_submit_derive(conf->instance, "totals", "total_operations",
589 else if (strcmp(name, "s_fetch") == 0)
590 return varnish_submit_derive(conf->instance, "totals", "total_operations",
592 else if (strcmp(name, "s_synth") == 0)
593 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
595 else if (strcmp(name, "s_req_hdrbytes") == 0)
596 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
598 else if (strcmp(name, "s_req_bodybytes") == 0)
599 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
601 else if (strcmp(name, "s_req_protobytes") == 0)
602 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
604 else if (strcmp(name, "s_resp_hdrbytes") == 0)
605 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
607 else if (strcmp(name, "s_resp_bodybytes") == 0)
608 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
610 else if (strcmp(name, "s_resp_protobytes") == 0)
611 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
613 else if (strcmp(name, "s_pipe_hdrbytes") == 0)
614 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
616 else if (strcmp(name, "s_pipe_in") == 0)
617 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
619 else if (strcmp(name, "s_pipe_out") == 0)
620 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
622 else if (strcmp(name, "n_purges") == 0)
623 return varnish_submit_derive(conf->instance, "totals", "total_operations",
625 else if (strcmp(name, "s_hdrbytes") == 0)
626 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
627 "header-bytes", val);
628 else if (strcmp(name, "s_bodybytes") == 0)
629 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
631 else if (strcmp(name, "n_gzip") == 0)
632 return varnish_submit_derive(conf->instance, "totals", "total_operations",
634 else if (strcmp(name, "n_gunzip") == 0)
635 return varnish_submit_derive(conf->instance, "totals", "total_operations",
639 if (conf->collect_uptime) {
640 if (strcmp(name, "uptime") == 0)
641 return varnish_submit_gauge(conf->instance, "uptime", "uptime",
642 "client_uptime", val);
645 if (conf->collect_vcl) {
646 if (strcmp(name, "n_vcl") == 0)
647 return varnish_submit_gauge(conf->instance, "vcl", "vcl", "total_vcl",
649 else if (strcmp(name, "n_vcl_avail") == 0)
650 return varnish_submit_gauge(conf->instance, "vcl", "vcl", "avail_vcl",
652 else if (strcmp(name, "n_vcl_discard") == 0)
653 return varnish_submit_gauge(conf->instance, "vcl", "vcl", "discarded_vcl",
655 else if (strcmp(name, "vmods") == 0)
656 return varnish_submit_gauge(conf->instance, "vcl", "objects", "vmod",
660 if (conf->collect_workers) {
661 if (strcmp(name, "threads") == 0)
662 return varnish_submit_gauge(conf->instance, "workers", "threads",
664 else if (strcmp(name, "threads_created") == 0)
665 return varnish_submit_derive(conf->instance, "workers", "total_threads",
667 else if (strcmp(name, "threads_failed") == 0)
668 return varnish_submit_derive(conf->instance, "workers", "total_threads",
670 else if (strcmp(name, "threads_limited") == 0)
671 return varnish_submit_derive(conf->instance, "workers", "total_threads",
673 else if (strcmp(name, "threads_destroyed") == 0)
674 return varnish_submit_derive(conf->instance, "workers", "total_threads",
676 else if (strcmp(name, "thread_queue_len") == 0)
677 return varnish_submit_gauge(conf->instance, "workers", "queue_length",
679 else if (strcmp(name, "n_wrk") == 0)
680 return varnish_submit_gauge(conf->instance, "workers", "threads",
682 else if (strcmp(name, "n_wrk_create") == 0)
683 return varnish_submit_derive(conf->instance, "workers", "total_threads",
685 else if (strcmp(name, "n_wrk_failed") == 0)
686 return varnish_submit_derive(conf->instance, "workers", "total_threads",
688 else if (strcmp(name, "n_wrk_max") == 0)
689 return varnish_submit_derive(conf->instance, "workers", "total_threads",
691 else if (strcmp(name, "n_wrk_drop") == 0)
692 return varnish_submit_derive(conf->instance, "workers", "total_threads",
694 else if (strcmp(name, "n_wrk_queue") == 0)
695 return varnish_submit_derive(conf->instance, "workers", "total_requests",
697 else if (strcmp(name, "n_wrk_overflow") == 0)
698 return varnish_submit_derive(conf->instance, "workers", "total_requests",
700 else if (strcmp(name, "n_wrk_queued") == 0)
701 return varnish_submit_derive(conf->instance, "workers", "total_requests",
703 else if (strcmp(name, "n_wrk_lqueue") == 0)
704 return varnish_submit_derive(conf->instance, "workers", "total_requests",
705 "queue_length", val);
706 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
707 else if (strcmp(name, "pools") == 0)
708 return varnish_submit_gauge(conf->instance, "workers", "pools", "pools",
710 else if (strcmp(name, "busy_killed") == 0)
711 return varnish_submit_derive(conf->instance, "workers", "http_requests",
716 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
717 if (conf->collect_vsm) {
718 if (strcmp(name, "vsm_free") == 0)
719 return varnish_submit_gauge(conf->instance, "vsm", "bytes", "free", val);
720 else if (strcmp(name, "vsm_used") == 0)
721 return varnish_submit_gauge(conf->instance, "vsm", "bytes", "used", val);
722 else if (strcmp(name, "vsm_cooling") == 0)
723 return varnish_submit_gauge(conf->instance, "vsm", "bytes", "cooling",
725 else if (strcmp(name, "vsm_overflow") == 0)
726 return varnish_submit_gauge(conf->instance, "vsm", "bytes", "overflow",
728 else if (strcmp(name, "vsm_overflowed") == 0)
729 return varnish_submit_derive(conf->instance, "vsm", "total_bytes",
733 if (conf->collect_vbe) {
734 /* @TODO figure out the collectd type for bitmap
735 if (strcmp(name, "happy") == 0)
736 return varnish_submit_derive(conf->instance, "vbe",
737 "bitmap", "happy_hprobes", val);
739 if (strcmp(name, "bereq_hdrbytes") == 0)
740 return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
741 "bereq_hdrbytes", val);
742 else if (strcmp(name, "bereq_bodybytes") == 0)
743 return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
744 "bereq_bodybytes", val);
745 else if (strcmp(name, "bereq_protobytes") == 0)
746 return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
747 "bereq_protobytes", val);
748 else if (strcmp(name, "beresp_hdrbytes") == 0)
749 return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
750 "beresp_hdrbytes", val);
751 else if (strcmp(name, "beresp_bodybytes") == 0)
752 return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
753 "beresp_bodybytes", val);
754 else if (strcmp(name, "beresp_protobytes") == 0)
755 return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
756 "beresp_protobytes", val);
757 else if (strcmp(name, "pipe_hdrbytes") == 0)
758 return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
759 "pipe_hdrbytes", val);
760 else if (strcmp(name, "pipe_out") == 0)
761 return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
763 else if (strcmp(name, "pipe_in") == 0)
764 return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
766 else if (strcmp(name, "conn") == 0)
767 return varnish_submit_derive(conf->instance, "vbe", "connections",
769 else if (strcmp(name, "req") == 0)
770 return varnish_submit_derive(conf->instance, "vbe", "http_requests",
774 /* All Stevedores support these counters */
775 if (conf->collect_sma || conf->collect_smf || conf->collect_mse) {
778 if (conf->collect_sma)
779 strncpy(category, "sma", 4);
780 else if (conf->collect_smf)
781 strncpy(category, "smf", 4);
783 strncpy(category, "mse", 4);
785 if (strcmp(name, "c_req") == 0)
786 return varnish_submit_derive(conf->instance, category, "total_operations",
788 else if (strcmp(name, "c_fail") == 0)
789 return varnish_submit_derive(conf->instance, category, "total_operations",
791 else if (strcmp(name, "c_bytes") == 0)
792 return varnish_submit_derive(conf->instance, category, "total_bytes",
793 "bytes_allocated", val);
794 else if (strcmp(name, "c_freed") == 0)
795 return varnish_submit_derive(conf->instance, category, "total_bytes",
797 else if (strcmp(name, "g_alloc") == 0)
798 return varnish_submit_derive(conf->instance, category, "total_operations",
799 "alloc_outstanding", val);
800 else if (strcmp(name, "g_bytes") == 0)
801 return varnish_submit_gauge(conf->instance, category, "bytes",
802 "bytes_outstanding", val);
803 else if (strcmp(name, "g_space") == 0)
804 return varnish_submit_gauge(conf->instance, category, "bytes",
805 "bytes_available", val);
808 /* No SMA specific counters */
810 if (conf->collect_smf) {
811 if (strcmp(name, "g_smf") == 0)
812 return varnish_submit_gauge(conf->instance, "smf", "objects",
813 "n_struct_smf", val);
814 else if (strcmp(name, "g_smf_frag") == 0)
815 return varnish_submit_gauge(conf->instance, "smf", "objects",
816 "n_small_free_smf", val);
817 else if (strcmp(name, "g_smf_large") == 0)
818 return varnish_submit_gauge(conf->instance, "smf", "objects",
819 "n_large_free_smf", val);
822 if (conf->collect_mgt) {
823 if (strcmp(name, "uptime") == 0)
824 return varnish_submit_gauge(conf->instance, "mgt", "uptime",
825 "mgt_proc_uptime", val);
826 else if (strcmp(name, "child_start") == 0)
827 return varnish_submit_derive(conf->instance, "mgt", "total_operations",
829 else if (strcmp(name, "child_exit") == 0)
830 return varnish_submit_derive(conf->instance, "mgt", "total_operations",
832 else if (strcmp(name, "child_stop") == 0)
833 return varnish_submit_derive(conf->instance, "mgt", "total_operations",
835 else if (strcmp(name, "child_died") == 0)
836 return varnish_submit_derive(conf->instance, "mgt", "total_operations",
838 else if (strcmp(name, "child_dump") == 0)
839 return varnish_submit_derive(conf->instance, "mgt", "total_operations",
841 else if (strcmp(name, "child_panic") == 0)
842 return varnish_submit_derive(conf->instance, "mgt", "total_operations",
846 if (conf->collect_lck) {
847 if (strcmp(name, "creat") == 0)
848 return varnish_submit_gauge(conf->instance, "lck", "objects", "created",
850 else if (strcmp(name, "destroy") == 0)
851 return varnish_submit_gauge(conf->instance, "lck", "objects", "destroyed",
853 else if (strcmp(name, "locks") == 0)
854 return varnish_submit_derive(conf->instance, "lck", "total_operations",
858 if (conf->collect_mempool) {
859 if (strcmp(name, "live") == 0)
860 return varnish_submit_gauge(conf->instance, "mempool", "objects",
862 else if (strcmp(name, "pool") == 0)
863 return varnish_submit_gauge(conf->instance, "mempool", "objects",
865 else if (strcmp(name, "sz_wanted") == 0)
866 return varnish_submit_gauge(conf->instance, "mempool", "bytes",
867 "size_requested", val);
868 else if (strcmp(name, "sz_actual") == 0)
869 return varnish_submit_gauge(conf->instance, "mempool", "bytes",
870 "size_allocated", val);
871 else if (strcmp(name, "allocs") == 0)
872 return varnish_submit_derive(conf->instance, "mempool",
873 "total_operations", "allocations", val);
874 else if (strcmp(name, "frees") == 0)
875 return varnish_submit_derive(conf->instance, "mempool",
876 "total_operations", "frees", val);
877 else if (strcmp(name, "recycle") == 0)
878 return varnish_submit_gauge(conf->instance, "mempool", "objects",
880 else if (strcmp(name, "timeout") == 0)
881 return varnish_submit_gauge(conf->instance, "mempool", "objects",
883 else if (strcmp(name, "toosmall") == 0)
884 return varnish_submit_gauge(conf->instance, "mempool", "objects",
886 else if (strcmp(name, "surplus") == 0)
887 return varnish_submit_gauge(conf->instance, "mempool", "objects",
889 else if (strcmp(name, "randry") == 0)
890 return varnish_submit_gauge(conf->instance, "mempool", "objects",
894 if (conf->collect_mse) {
895 if (strcmp(name, "c_full") == 0)
896 return varnish_submit_derive(conf->instance, "mse", "total_operations",
898 else if (strcmp(name, "c_truncated") == 0)
899 return varnish_submit_derive(conf->instance, "mse", "total_operations",
900 "truncated_allocs", val);
901 else if (strcmp(name, "c_expanded") == 0)
902 return varnish_submit_derive(conf->instance, "mse", "total_operations",
903 "expanded_allocs", val);
904 else if (strcmp(name, "c_failed") == 0)
905 return varnish_submit_derive(conf->instance, "mse", "total_operations",
906 "failed_allocs", val);
907 else if (strcmp(name, "c_bytes") == 0)
908 return varnish_submit_derive(conf->instance, "mse", "total_bytes",
909 "bytes_allocated", val);
910 else if (strcmp(name, "c_freed") == 0)
911 return varnish_submit_derive(conf->instance, "mse", "total_bytes",
913 else if (strcmp(name, "g_fo_alloc") == 0)
914 return varnish_submit_derive(conf->instance, "mse", "total_operations",
915 "fo_allocs_outstanding", val);
916 else if (strcmp(name, "g_fo_bytes") == 0)
917 return varnish_submit_gauge(conf->instance, "mse", "bytes",
918 "fo_bytes_outstanding", val);
919 else if (strcmp(name, "g_membuf_alloc") == 0)
920 return varnish_submit_gauge(conf->instance, "mse", "objects",
921 "membufs_allocated", val);
922 else if (strcmp(name, "g_membuf_inuse") == 0)
923 return varnish_submit_gauge(conf->instance, "mse", "objects",
924 "membufs_inuse", val);
925 else if (strcmp(name, "g_bans_bytes") == 0)
926 return varnish_submit_gauge(conf->instance, "mse", "bytes",
927 "persisted_banspace_used", val);
928 else if (strcmp(name, "g_bans_space") == 0)
929 return varnish_submit_gauge(conf->instance, "mse", "bytes",
930 "persisted_banspace_available", val);
931 else if (strcmp(name, "g_bans_persisted") == 0)
932 return varnish_submit_derive(conf->instance, "mse", "total_operations",
933 "bans_persisted", val);
934 else if (strcmp(name, "g_bans_lost") == 0)
935 return varnish_submit_derive(conf->instance, "mse", "total_operations",
939 else if (strcmp(name, "g_journal_bytes") == 0)
940 return varnish_submit_gauge(conf->instance, "mse_reg", "bytes",
941 "journal_bytes_used", val);
942 else if (strcmp(name, "g_journal_space") == 0)
943 return varnish_submit_gauge(conf->instance, "mse_reg", "bytes",
944 "journal_bytes_free", val);
947 else if (strcmp(name, "g_bigspace") == 0)
948 return varnish_submit_gauge(conf->instance, "mse_segagg", "bytes",
949 "big_extents_bytes_available", val);
950 else if (strcmp(name, "g_extfree") == 0)
951 return varnish_submit_gauge(conf->instance, "mse_segagg", "objects",
952 "free_extents", val);
953 else if (strcmp(name, "g_sparenode") == 0)
954 return varnish_submit_gauge(conf->instance, "mse_segagg", "objects",
955 "spare_nodes_available", val);
956 else if (strcmp(name, "g_objnode") == 0)
957 return varnish_submit_gauge(conf->instance, "mse_segagg", "objects",
958 "object_nodes_in_use", val);
959 else if (strcmp(name, "g_extnode") == 0)
960 return varnish_submit_gauge(conf->instance, "mse_segagg", "objects",
961 "extent_nodes_in_use", val);
962 else if (strcmp(name, "g_bigextfree") == 0)
963 return varnish_submit_gauge(conf->instance, "mse_segagg", "objects",
964 "free_big_extents", val);
965 else if (strcmp(name, "c_pruneloop") == 0)
966 return varnish_submit_derive(conf->instance, "mse_segagg",
967 "total_operations", "prune_loops", val);
968 else if (strcmp(name, "c_pruned") == 0)
969 return varnish_submit_derive(conf->instance, "mse_segagg",
970 "total_objects", "pruned_objects", val);
971 else if (strcmp(name, "c_spared") == 0)
972 return varnish_submit_derive(conf->instance, "mse_segagg",
973 "total_operations", "spared_objects", val);
974 else if (strcmp(name, "c_skipped") == 0)
975 return varnish_submit_derive(conf->instance, "mse_segagg",
976 "total_operations", "missed_objects", val);
977 else if (strcmp(name, "c_nuked") == 0)
978 return varnish_submit_derive(conf->instance, "mse_segagg",
979 "total_operations", "nuked_objects", val);
980 else if (strcmp(name, "c_sniped") == 0)
981 return varnish_submit_derive(conf->instance, "mse_segagg",
982 "total_operations", "sniped_objects", val);
989 } /* }}} static int varnish_monitor */
990 #else /* if HAVE_VARNISH_V2 */
991 static void varnish_monitor(const user_config_t *conf, /* {{{ */
992 const c_varnish_stats_t *stats) {
993 if (conf->collect_cache) {
995 varnish_submit_derive(conf->instance, "cache", "cache_result", "hit",
998 varnish_submit_derive(conf->instance, "cache", "cache_result", "miss",
1000 /* Cache hits for pass */
1001 varnish_submit_derive(conf->instance, "cache", "cache_result", "hitpass",
1002 stats->cache_hitpass);
1005 if (conf->collect_connections) {
1006 /* Client connections accepted */
1007 varnish_submit_derive(conf->instance, "connections", "connections",
1008 "accepted", stats->client_conn);
1009 /* Connection dropped, no sess */
1010 varnish_submit_derive(conf->instance, "connections", "connections",
1011 "dropped", stats->client_drop);
1012 /* Client requests received */
1013 varnish_submit_derive(conf->instance, "connections", "connections",
1014 "received", stats->client_req);
1017 if (conf->collect_esi) {
1018 /* ESI parse errors (unlock) */
1019 varnish_submit_derive(conf->instance, "esi", "total_operations", "error",
1021 /* Objects ESI parsed (unlock) */
1022 varnish_submit_derive(conf->instance, "esi", "total_operations", "parsed",
1026 if (conf->collect_backend) {
1027 /* Backend conn. success */
1028 varnish_submit_derive(conf->instance, "backend", "connections", "success",
1029 stats->backend_conn);
1030 /* Backend conn. not attempted */
1031 varnish_submit_derive(conf->instance, "backend", "connections",
1032 "not-attempted", stats->backend_unhealthy);
1033 /* Backend conn. too many */
1034 varnish_submit_derive(conf->instance, "backend", "connections", "too-many",
1035 stats->backend_busy);
1036 /* Backend conn. failures */
1037 varnish_submit_derive(conf->instance, "backend", "connections", "failures",
1038 stats->backend_fail);
1039 /* Backend conn. reuses */
1040 varnish_submit_derive(conf->instance, "backend", "connections", "reuses",
1041 stats->backend_reuse);
1042 /* Backend conn. was closed */
1043 varnish_submit_derive(conf->instance, "backend", "connections",
1044 "was-closed", stats->backend_toolate);
1045 /* Backend conn. recycles */
1046 varnish_submit_derive(conf->instance, "backend", "connections", "recycled",
1047 stats->backend_recycle);
1048 /* Backend conn. unused */
1049 varnish_submit_derive(conf->instance, "backend", "connections", "unused",
1050 stats->backend_unused);
1051 /* Backend requests mades */
1052 varnish_submit_derive(conf->instance, "backend", "http_requests",
1053 "requests", stats->backend_req);
1055 varnish_submit_gauge(conf->instance, "backend", "backends", "n_backends",
1059 if (conf->collect_fetch) {
1061 varnish_submit_derive(conf->instance, "fetch", "http_requests", "head",
1063 /* Fetch with length */
1064 varnish_submit_derive(conf->instance, "fetch", "http_requests", "length",
1065 stats->fetch_length);
1067 varnish_submit_derive(conf->instance, "fetch", "http_requests", "chunked",
1068 stats->fetch_chunked);
1070 varnish_submit_derive(conf->instance, "fetch", "http_requests", "eof",
1072 /* Fetch bad headers */
1073 varnish_submit_derive(conf->instance, "fetch", "http_requests",
1074 "bad_headers", stats->fetch_bad);
1075 /* Fetch wanted close */
1076 varnish_submit_derive(conf->instance, "fetch", "http_requests", "close",
1077 stats->fetch_close);
1078 /* Fetch pre HTTP/1.1 closed */
1079 varnish_submit_derive(conf->instance, "fetch", "http_requests", "oldhttp",
1080 stats->fetch_oldhttp);
1081 /* Fetch zero len */
1082 varnish_submit_derive(conf->instance, "fetch", "http_requests", "zero",
1085 varnish_submit_derive(conf->instance, "fetch", "http_requests", "failed",
1086 stats->fetch_failed);
1089 if (conf->collect_hcb) {
1090 /* HCB Lookups without lock */
1091 varnish_submit_derive(conf->instance, "hcb", "cache_operation",
1092 "lookup_nolock", stats->hcb_nolock);
1093 /* HCB Lookups with lock */
1094 varnish_submit_derive(conf->instance, "hcb", "cache_operation",
1095 "lookup_lock", stats->hcb_lock);
1097 varnish_submit_derive(conf->instance, "hcb", "cache_operation", "insert",
1101 if (conf->collect_objects) {
1102 /* N expired objects */
1103 varnish_submit_derive(conf->instance, "objects", "total_objects", "expired",
1105 /* N LRU nuked objects */
1106 varnish_submit_derive(conf->instance, "objects", "total_objects",
1107 "lru_nuked", stats->n_lru_nuked);
1108 /* N LRU saved objects */
1109 varnish_submit_derive(conf->instance, "objects", "total_objects",
1110 "lru_saved", stats->n_lru_saved);
1111 /* N LRU moved objects */
1112 varnish_submit_derive(conf->instance, "objects", "total_objects",
1113 "lru_moved", stats->n_lru_moved);
1114 /* N objects on deathrow */
1115 varnish_submit_derive(conf->instance, "objects", "total_objects",
1116 "deathrow", stats->n_deathrow);
1117 /* HTTP header overflows */
1118 varnish_submit_derive(conf->instance, "objects", "total_objects",
1119 "header_overflow", stats->losthdr);
1120 /* Objects sent with sendfile */
1121 varnish_submit_derive(conf->instance, "objects", "total_objects",
1122 "sent_sendfile", stats->n_objsendfile);
1123 /* Objects sent with write */
1124 varnish_submit_derive(conf->instance, "objects", "total_objects",
1125 "sent_write", stats->n_objwrite);
1126 /* Objects overflowing workspace */
1127 varnish_submit_derive(conf->instance, "objects", "total_objects",
1128 "workspace_overflow", stats->n_objoverflow);
1131 if (conf->collect_purge) {
1132 /* N total active purges */
1133 varnish_submit_derive(conf->instance, "purge", "total_operations", "total",
1135 /* N new purges added */
1136 varnish_submit_derive(conf->instance, "purge", "total_operations", "added",
1137 stats->n_purge_add);
1138 /* N old purges deleted */
1139 varnish_submit_derive(conf->instance, "purge", "total_operations",
1140 "deleted", stats->n_purge_retire);
1141 /* N objects tested */
1142 varnish_submit_derive(conf->instance, "purge", "total_operations",
1143 "objects_tested", stats->n_purge_obj_test);
1144 /* N regexps tested against */
1145 varnish_submit_derive(conf->instance, "purge", "total_operations",
1146 "regexps_tested", stats->n_purge_re_test);
1147 /* N duplicate purges removed */
1148 varnish_submit_derive(conf->instance, "purge", "total_operations",
1149 "duplicate", stats->n_purge_dups);
1152 if (conf->collect_session) {
1153 /* Session Closed */
1154 varnish_submit_derive(conf->instance, "session", "total_operations",
1155 "closed", stats->sess_closed);
1156 /* Session Pipeline */
1157 varnish_submit_derive(conf->instance, "session", "total_operations",
1158 "pipeline", stats->sess_pipeline);
1159 /* Session Read Ahead */
1160 varnish_submit_derive(conf->instance, "session", "total_operations",
1161 "readahead", stats->sess_readahead);
1162 /* Session Linger */
1163 varnish_submit_derive(conf->instance, "session", "total_operations",
1164 "linger", stats->sess_linger);
1166 varnish_submit_derive(conf->instance, "session", "total_operations", "herd",
1170 if (conf->collect_shm) {
1172 varnish_submit_derive(conf->instance, "shm", "total_operations", "records",
1173 stats->shm_records);
1175 varnish_submit_derive(conf->instance, "shm", "total_operations", "writes",
1177 /* SHM flushes due to overflow */
1178 varnish_submit_derive(conf->instance, "shm", "total_operations", "flushes",
1179 stats->shm_flushes);
1180 /* SHM MTX contention */
1181 varnish_submit_derive(conf->instance, "shm", "total_operations",
1182 "contention", stats->shm_cont);
1183 /* SHM cycles through buffer */
1184 varnish_submit_derive(conf->instance, "shm", "total_operations", "cycles",
1188 if (conf->collect_sm) {
1189 /* allocator requests */
1190 varnish_submit_derive(conf->instance, "sm", "total_requests", "nreq",
1192 /* outstanding allocations */
1193 varnish_submit_gauge(conf->instance, "sm", "requests", "outstanding",
1195 /* bytes allocated */
1196 varnish_submit_derive(conf->instance, "sm", "total_bytes", "allocated",
1199 varnish_submit_derive(conf->instance, "sm", "total_bytes", "free",
1203 if (conf->collect_sma) {
1204 /* SMA allocator requests */
1205 varnish_submit_derive(conf->instance, "sma", "total_requests", "nreq",
1207 /* SMA outstanding allocations */
1208 varnish_submit_gauge(conf->instance, "sma", "requests", "outstanding",
1210 /* SMA outstanding bytes */
1211 varnish_submit_gauge(conf->instance, "sma", "bytes", "outstanding",
1213 /* SMA bytes allocated */
1214 varnish_submit_derive(conf->instance, "sma", "total_bytes", "allocated",
1216 /* SMA bytes free */
1217 varnish_submit_derive(conf->instance, "sma", "total_bytes", "free",
1221 if (conf->collect_sms) {
1222 /* SMS allocator requests */
1223 varnish_submit_derive(conf->instance, "sms", "total_requests", "allocator",
1225 /* SMS outstanding allocations */
1226 varnish_submit_gauge(conf->instance, "sms", "requests", "outstanding",
1228 /* SMS outstanding bytes */
1229 varnish_submit_gauge(conf->instance, "sms", "bytes", "outstanding",
1231 /* SMS bytes allocated */
1232 varnish_submit_derive(conf->instance, "sms", "total_bytes", "allocated",
1234 /* SMS bytes freed */
1235 varnish_submit_derive(conf->instance, "sms", "total_bytes", "free",
1239 if (conf->collect_struct) {
1240 /* N struct sess_mem */
1241 varnish_submit_gauge(conf->instance, "struct", "current_sessions",
1242 "sess_mem", stats->n_sess_mem);
1244 varnish_submit_gauge(conf->instance, "struct", "current_sessions", "sess",
1246 /* N struct object */
1247 varnish_submit_gauge(conf->instance, "struct", "objects", "object",
1249 /* N struct objecthead */
1250 varnish_submit_gauge(conf->instance, "struct", "objects", "objecthead",
1251 stats->n_objecthead);
1253 varnish_submit_gauge(conf->instance, "struct", "objects", "smf",
1255 /* N small free smf */
1256 varnish_submit_gauge(conf->instance, "struct", "objects", "smf_frag",
1258 /* N large free smf */
1259 varnish_submit_gauge(conf->instance, "struct", "objects", "smf_large",
1260 stats->n_smf_large);
1261 /* N struct vbe_conn */
1262 varnish_submit_gauge(conf->instance, "struct", "objects", "vbe_conn",
1266 if (conf->collect_totals) {
1267 /* Total Sessions */
1268 varnish_submit_derive(conf->instance, "totals", "total_sessions",
1269 "sessions", stats->s_sess);
1270 /* Total Requests */
1271 varnish_submit_derive(conf->instance, "totals", "total_requests",
1272 "requests", stats->s_req);
1274 varnish_submit_derive(conf->instance, "totals", "total_operations", "pipe",
1277 varnish_submit_derive(conf->instance, "totals", "total_operations", "pass",
1280 varnish_submit_derive(conf->instance, "totals", "total_operations",
1281 "fetches", stats->s_fetch);
1282 /* Total header bytes */
1283 varnish_submit_derive(conf->instance, "totals", "total_bytes",
1284 "header-bytes", stats->s_hdrbytes);
1285 /* Total body byte */
1286 varnish_submit_derive(conf->instance, "totals", "total_bytes", "body-bytes",
1287 stats->s_bodybytes);
1290 if (conf->collect_vcl) {
1292 varnish_submit_gauge(conf->instance, "vcl", "vcl", "total_vcl",
1294 /* N vcl available */
1295 varnish_submit_gauge(conf->instance, "vcl", "vcl", "avail_vcl",
1296 stats->n_vcl_avail);
1297 /* N vcl discarded */
1298 varnish_submit_gauge(conf->instance, "vcl", "vcl", "discarded_vcl",
1299 stats->n_vcl_discard);
1302 if (conf->collect_workers) {
1303 /* worker threads */
1304 varnish_submit_gauge(conf->instance, "workers", "threads", "worker",
1306 /* worker threads created */
1307 varnish_submit_derive(conf->instance, "workers", "total_threads", "created",
1308 stats->n_wrk_create);
1309 /* worker threads not created */
1310 varnish_submit_derive(conf->instance, "workers", "total_threads", "failed",
1311 stats->n_wrk_failed);
1312 /* worker threads limited */
1313 varnish_submit_derive(conf->instance, "workers", "total_threads", "limited",
1315 /* dropped work requests */
1316 varnish_submit_derive(conf->instance, "workers", "total_threads", "dropped",
1318 /* queued work requests */
1319 varnish_submit_derive(conf->instance, "workers", "total_requests", "queued",
1320 stats->n_wrk_queue);
1321 /* overflowed work requests */
1322 varnish_submit_derive(conf->instance, "workers", "total_requests",
1323 "overflowed", stats->n_wrk_overflow);
1326 } /* }}} void varnish_monitor */
1329 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1330 static int varnish_read(user_data_t *ud) /* {{{ */
1332 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
1333 struct VSM_data *vd;
1335 const c_varnish_stats_t *stats;
1336 #elif HAVE_VARNISH_V5
1342 user_config_t *conf;
1344 if ((ud == NULL) || (ud->data == NULL))
1359 if (conf->instance != NULL) {
1362 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
1363 status = VSM_n_Arg(vd, conf->instance);
1364 #elif HAVE_VARNISH_V5
1365 status = VSM_Arg(vd, 'n', conf->instance);
1369 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
1371 #elif HAVE_VARNISH_V5
1372 VSC_Destroy(&vsc, vd);
1375 ERROR("varnish plugin: VSM_Arg (\"%s\") failed "
1377 conf->instance, status);
1383 ok = (VSC_Open(vd, /* diag = */ 1) == 0);
1384 #elif HAVE_VARNISH_V4
1385 ok = (VSM_Open(vd) == 0);
1387 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
1390 ERROR("varnish plugin: Unable to open connection.");
1396 stats = VSC_Main(vd);
1397 #elif HAVE_VARNISH_V4
1398 stats = VSC_Main(vd, NULL);
1400 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
1403 ERROR("varnish plugin: Unable to get statistics.");
1409 if (VSM_Attach(vd, STDERR_FILENO)) {
1410 ERROR("varnish plugin: Cannot attach to varnish. %s", VSM_Error(vd));
1411 VSC_Destroy(&vsc, vd);
1416 vsm_status = VSM_Status(vd);
1417 if (vsm_status & ~(VSM_MGT_RUNNING | VSM_WRK_RUNNING)) {
1418 ERROR("varnish plugin: Unable to get statistics.");
1419 VSC_Destroy(&vsc, vd);
1426 VSC_Iter(vd, varnish_monitor, conf);
1427 #elif HAVE_VARNISH_V4
1428 VSC_Iter(vd, NULL, varnish_monitor, conf);
1429 #elif HAVE_VARNISH_V5
1430 VSC_Iter(vsc, vd, varnish_monitor, conf);
1433 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
1435 #elif HAVE_VARNISH_V5
1436 VSC_Destroy(&vsc, vd);
1442 #else /* if HAVE_VARNISH_V2 */
1443 static int varnish_read(user_data_t *ud) /* {{{ */
1445 const c_varnish_stats_t *stats;
1447 user_config_t *conf;
1449 if ((ud == NULL) || (ud->data == NULL))
1454 stats = VSL_OpenStats(conf->instance);
1455 if (stats == NULL) {
1456 ERROR("Varnish plugin : unable to load statistics");
1461 varnish_monitor(conf, stats);
1467 static void varnish_config_free(void *ptr) /* {{{ */
1469 user_config_t *conf = ptr;
1474 sfree(conf->instance);
1478 static int varnish_config_apply_default(user_config_t *conf) /* {{{ */
1483 conf->collect_backend = 1;
1484 conf->collect_cache = 1;
1485 conf->collect_connections = 1;
1486 #ifdef HAVE_VARNISH_V3
1487 conf->collect_dirdns = 0;
1489 conf->collect_esi = 0;
1490 conf->collect_fetch = 0;
1491 conf->collect_hcb = 0;
1492 conf->collect_objects = 0;
1494 conf->collect_purge = 0;
1496 conf->collect_ban = 0;
1498 conf->collect_session = 0;
1499 conf->collect_shm = 1;
1501 conf->collect_sm = 0;
1503 #if HAVE_VARNISH_V2 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1504 conf->collect_sma = 0;
1506 conf->collect_sms = 0;
1507 conf->collect_struct = 0;
1508 conf->collect_totals = 0;
1509 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1510 conf->collect_uptime = 0;
1512 conf->collect_vcl = 0;
1513 conf->collect_workers = 0;
1514 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1515 conf->collect_vsm = 0;
1516 conf->collect_lck = 0;
1517 conf->collect_mempool = 0;
1518 conf->collect_mgt = 0;
1519 conf->collect_smf = 0;
1520 conf->collect_vbe = 0;
1521 conf->collect_mse = 0;
1525 } /* }}} int varnish_config_apply_default */
1527 static int varnish_init(void) /* {{{ */
1529 user_config_t *conf;
1534 conf = calloc(1, sizeof(*conf));
1538 /* Default settings: */
1539 conf->instance = NULL;
1541 varnish_config_apply_default(conf);
1543 plugin_register_complex_read(
1544 /* group = */ "varnish",
1545 /* name = */ "varnish/localhost",
1546 /* callback = */ varnish_read,
1549 .data = conf, .free_func = varnish_config_free,
1553 } /* }}} int varnish_init */
1555 static int varnish_config_instance(const oconfig_item_t *ci) /* {{{ */
1557 user_config_t *conf;
1558 char callback_name[DATA_MAX_NAME_LEN];
1560 conf = calloc(1, sizeof(*conf));
1563 conf->instance = NULL;
1565 varnish_config_apply_default(conf);
1567 if (ci->values_num == 1) {
1570 status = cf_util_get_string(ci, &conf->instance);
1575 assert(conf->instance != NULL);
1577 if (strcmp("localhost", conf->instance) == 0) {
1578 sfree(conf->instance);
1579 conf->instance = NULL;
1581 } else if (ci->values_num > 1) {
1582 WARNING("Varnish plugin: \"Instance\" blocks accept only "
1588 for (int i = 0; i < ci->children_num; i++) {
1589 oconfig_item_t *child = ci->children + i;
1591 if (strcasecmp("CollectCache", child->key) == 0)
1592 cf_util_get_boolean(child, &conf->collect_cache);
1593 else if (strcasecmp("CollectConnections", child->key) == 0)
1594 cf_util_get_boolean(child, &conf->collect_connections);
1595 else if (strcasecmp("CollectESI", child->key) == 0)
1596 cf_util_get_boolean(child, &conf->collect_esi);
1597 else if (strcasecmp("CollectDirectorDNS", child->key) == 0)
1598 #ifdef HAVE_VARNISH_V3
1599 cf_util_get_boolean(child, &conf->collect_dirdns);
1601 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1604 else if (strcasecmp("CollectBackend", child->key) == 0)
1605 cf_util_get_boolean(child, &conf->collect_backend);
1606 else if (strcasecmp("CollectFetch", child->key) == 0)
1607 cf_util_get_boolean(child, &conf->collect_fetch);
1608 else if (strcasecmp("CollectHCB", child->key) == 0)
1609 cf_util_get_boolean(child, &conf->collect_hcb);
1610 else if (strcasecmp("CollectObjects", child->key) == 0)
1611 cf_util_get_boolean(child, &conf->collect_objects);
1612 else if (strcasecmp("CollectPurge", child->key) == 0)
1614 cf_util_get_boolean(child, &conf->collect_purge);
1616 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1619 else if (strcasecmp("CollectBan", child->key) == 0)
1621 WARNING("Varnish plugin: \"%s\" is not available for Varnish %s.",
1624 cf_util_get_boolean(child, &conf->collect_ban);
1626 else if (strcasecmp("CollectSession", child->key) == 0)
1627 cf_util_get_boolean(child, &conf->collect_session);
1628 else if (strcasecmp("CollectSHM", child->key) == 0)
1629 cf_util_get_boolean(child, &conf->collect_shm);
1630 else if (strcasecmp("CollectSMS", child->key) == 0)
1631 cf_util_get_boolean(child, &conf->collect_sms);
1632 else if (strcasecmp("CollectSMA", child->key) == 0)
1633 #if HAVE_VARNISH_V2 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1634 cf_util_get_boolean(child, &conf->collect_sma);
1636 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1637 child->key, "v2 and v4");
1639 else if (strcasecmp("CollectSM", child->key) == 0)
1641 cf_util_get_boolean(child, &conf->collect_sm);
1643 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1646 else if (strcasecmp("CollectStruct", child->key) == 0)
1647 cf_util_get_boolean(child, &conf->collect_struct);
1648 else if (strcasecmp("CollectTotals", child->key) == 0)
1649 cf_util_get_boolean(child, &conf->collect_totals);
1650 else if (strcasecmp("CollectUptime", child->key) == 0)
1651 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1652 cf_util_get_boolean(child, &conf->collect_uptime);
1654 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1655 child->key, "v3 and v4");
1657 else if (strcasecmp("CollectVCL", child->key) == 0)
1658 cf_util_get_boolean(child, &conf->collect_vcl);
1659 else if (strcasecmp("CollectWorkers", child->key) == 0)
1660 cf_util_get_boolean(child, &conf->collect_workers);
1661 else if (strcasecmp("CollectVSM", child->key) == 0)
1662 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1663 cf_util_get_boolean(child, &conf->collect_vsm);
1665 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1668 else if (strcasecmp("CollectLock", child->key) == 0)
1669 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1670 cf_util_get_boolean(child, &conf->collect_lck);
1672 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1675 else if (strcasecmp("CollectMempool", child->key) == 0)
1676 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1677 cf_util_get_boolean(child, &conf->collect_mempool);
1679 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1682 else if (strcasecmp("CollectManagement", child->key) == 0)
1683 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1684 cf_util_get_boolean(child, &conf->collect_mgt);
1686 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1689 else if (strcasecmp("CollectSMF", child->key) == 0)
1690 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1691 cf_util_get_boolean(child, &conf->collect_smf);
1693 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1696 else if (strcasecmp("CollectSMF", child->key) == 0)
1697 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1698 cf_util_get_boolean(child, &conf->collect_smf);
1700 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1703 else if (strcasecmp("CollectVBE", child->key) == 0)
1704 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1705 cf_util_get_boolean(child, &conf->collect_vbe);
1707 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1710 else if (strcasecmp("CollectMSE", child->key) == 0)
1711 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1712 cf_util_get_boolean(child, &conf->collect_mse);
1714 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1715 child->key, "Plus v4");
1718 WARNING("Varnish plugin: Ignoring unknown "
1719 "configuration option: \"%s\". Did "
1720 "you forget to add an <Instance /> "
1721 "block around the configuration?",
1726 if (!conf->collect_cache && !conf->collect_connections &&
1727 !conf->collect_esi && !conf->collect_backend
1728 #ifdef HAVE_VARNISH_V3
1729 && !conf->collect_dirdns
1731 && !conf->collect_fetch && !conf->collect_hcb && !conf->collect_objects
1733 && !conf->collect_purge
1735 && !conf->collect_ban
1737 && !conf->collect_session && !conf->collect_shm && !conf->collect_sms
1739 && !conf->collect_sm
1741 #if HAVE_VARNISH_V2 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1742 && !conf->collect_sma
1744 && !conf->collect_struct && !conf->collect_totals
1745 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1746 && !conf->collect_uptime
1748 && !conf->collect_vcl && !conf->collect_workers
1749 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1750 && !conf->collect_vsm && !conf->collect_vbe && !conf->collect_smf &&
1751 !conf->collect_mgt && !conf->collect_lck && !conf->collect_mempool &&
1755 WARNING("Varnish plugin: No metric has been configured for "
1756 "instance \"%s\". Disabling this instance.",
1757 (conf->instance == NULL) ? "localhost" : conf->instance);
1762 snprintf(callback_name, sizeof(callback_name), "varnish/%s",
1763 (conf->instance == NULL) ? "localhost" : conf->instance);
1765 plugin_register_complex_read(
1766 /* group = */ "varnish",
1767 /* name = */ callback_name,
1768 /* callback = */ varnish_read,
1771 .data = conf, .free_func = varnish_config_free,
1777 } /* }}} int varnish_config_instance */
1779 static int varnish_config(oconfig_item_t *ci) /* {{{ */
1781 for (int i = 0; i < ci->children_num; i++) {
1782 oconfig_item_t *child = ci->children + i;
1784 if (strcasecmp("Instance", child->key) == 0)
1785 varnish_config_instance(child);
1787 WARNING("Varnish plugin: Ignoring unknown "
1788 "configuration option: \"%s\"",
1794 } /* }}} int varnish_config */
1796 void module_register(void) /* {{{ */
1798 plugin_register_complex_config("varnish", varnish_config);
1799 plugin_register_init("varnish", varnish_init);