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;
159 c = rindex(pt->name, '.');
160 strcpy(namebuff, c + 1);
165 #elif HAVE_VARNISH_V4
166 class = pt->section->fantom->type;
167 name = pt->desc->name;
169 if (strcmp(class, "MAIN") != 0)
172 #elif HAVE_VARNISH_V3
176 if (strcmp(class, "") != 0)
180 val = *(const volatile uint64_t *)pt->ptr;
182 if (conf->collect_cache) {
183 if (strcmp(name, "cache_hit") == 0)
184 return varnish_submit_derive(conf->instance, "cache", "cache_result",
186 else if (strcmp(name, "cache_miss") == 0)
187 return varnish_submit_derive(conf->instance, "cache", "cache_result",
189 else if (strcmp(name, "cache_hitpass") == 0)
190 return varnish_submit_derive(conf->instance, "cache", "cache_result",
194 if (conf->collect_connections) {
195 if (strcmp(name, "client_conn") == 0)
196 return varnish_submit_derive(conf->instance, "connections", "connections",
198 else if (strcmp(name, "client_drop") == 0)
199 return varnish_submit_derive(conf->instance, "connections", "connections",
201 else if (strcmp(name, "client_req") == 0)
202 return varnish_submit_derive(conf->instance, "connections", "connections",
204 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
205 else if (strcmp(name, "client_req_400") == 0)
206 return varnish_submit_derive(conf->instance, "connections", "connections",
208 else if (strcmp(name, "client_req_417") == 0)
209 return varnish_submit_derive(conf->instance, "connections", "connections",
214 #ifdef HAVE_VARNISH_V3
215 if (conf->collect_dirdns) {
216 if (strcmp(name, "dir_dns_lookups") == 0)
217 return varnish_submit_derive(conf->instance, "dirdns", "cache_operation",
219 else if (strcmp(name, "dir_dns_failed") == 0)
220 return varnish_submit_derive(conf->instance, "dirdns", "cache_result",
222 else if (strcmp(name, "dir_dns_hit") == 0)
223 return varnish_submit_derive(conf->instance, "dirdns", "cache_result",
225 else if (strcmp(name, "dir_dns_cache_full") == 0)
226 return varnish_submit_derive(conf->instance, "dirdns", "cache_result",
231 if (conf->collect_esi) {
232 if (strcmp(name, "esi_errors") == 0)
233 return varnish_submit_derive(conf->instance, "esi", "total_operations",
235 else if (strcmp(name, "esi_parse") == 0)
236 return varnish_submit_derive(conf->instance, "esi", "total_operations",
238 else if (strcmp(name, "esi_warnings") == 0)
239 return varnish_submit_derive(conf->instance, "esi", "total_operations",
241 else if (strcmp(name, "esi_maxdepth") == 0)
242 return varnish_submit_derive(conf->instance, "esi", "total_operations",
246 if (conf->collect_backend) {
247 if (strcmp(name, "backend_conn") == 0)
248 return varnish_submit_derive(conf->instance, "backend", "connections",
250 else if (strcmp(name, "backend_unhealthy") == 0)
251 return varnish_submit_derive(conf->instance, "backend", "connections",
252 "not-attempted", val);
253 else if (strcmp(name, "backend_busy") == 0)
254 return varnish_submit_derive(conf->instance, "backend", "connections",
256 else if (strcmp(name, "backend_fail") == 0)
257 return varnish_submit_derive(conf->instance, "backend", "connections",
259 else if (strcmp(name, "backend_reuse") == 0)
260 return varnish_submit_derive(conf->instance, "backend", "connections",
262 else if (strcmp(name, "backend_toolate") == 0)
263 return varnish_submit_derive(conf->instance, "backend", "connections",
265 else if (strcmp(name, "backend_recycle") == 0)
266 return varnish_submit_derive(conf->instance, "backend", "connections",
268 else if (strcmp(name, "backend_unused") == 0)
269 return varnish_submit_derive(conf->instance, "backend", "connections",
271 else if (strcmp(name, "backend_retry") == 0)
272 return varnish_submit_derive(conf->instance, "backend", "connections",
274 else if (strcmp(name, "backend_req") == 0)
275 return varnish_submit_derive(conf->instance, "backend", "http_requests",
277 else if (strcmp(name, "n_backend") == 0)
278 return varnish_submit_gauge(conf->instance, "backend", "backends",
282 if (conf->collect_fetch) {
283 if (strcmp(name, "fetch_head") == 0)
284 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
286 else if (strcmp(name, "fetch_length") == 0)
287 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
289 else if (strcmp(name, "fetch_chunked") == 0)
290 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
292 else if (strcmp(name, "fetch_eof") == 0)
293 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
295 else if (strcmp(name, "fetch_bad") == 0)
296 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
298 else if (strcmp(name, "fetch_close") == 0)
299 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
301 else if (strcmp(name, "fetch_oldhttp") == 0)
302 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
304 else if (strcmp(name, "fetch_zero") == 0)
305 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
307 else if (strcmp(name, "fetch_failed") == 0)
308 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
310 else if (strcmp(name, "fetch_1xx") == 0)
311 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
313 else if (strcmp(name, "fetch_204") == 0)
314 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
316 else if (strcmp(name, "fetch_304") == 0)
317 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
319 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
320 else if (strcmp(name, "fetch_no_thread") == 0)
321 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
323 else if (strcmp(name, "fetch_none") == 0)
324 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
326 else if (strcmp(name, "busy_sleep") == 0)
327 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
329 else if (strcmp(name, "busy_wakeup") == 0)
330 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
335 if (conf->collect_hcb) {
336 if (strcmp(name, "hcb_nolock") == 0)
337 return varnish_submit_derive(conf->instance, "hcb", "cache_operation",
338 "lookup_nolock", val);
339 else if (strcmp(name, "hcb_lock") == 0)
340 return varnish_submit_derive(conf->instance, "hcb", "cache_operation",
342 else if (strcmp(name, "hcb_insert") == 0)
343 return varnish_submit_derive(conf->instance, "hcb", "cache_operation",
347 if (conf->collect_objects) {
348 if (strcmp(name, "n_expired") == 0)
349 return varnish_submit_derive(conf->instance, "objects", "total_objects",
351 else if (strcmp(name, "n_lru_nuked") == 0)
352 return varnish_submit_derive(conf->instance, "objects", "total_objects",
354 else if (strcmp(name, "n_lru_saved") == 0)
355 return varnish_submit_derive(conf->instance, "objects", "total_objects",
357 else if (strcmp(name, "n_lru_moved") == 0)
358 return varnish_submit_derive(conf->instance, "objects", "total_objects",
360 else if (strcmp(name, "n_deathrow") == 0)
361 return varnish_submit_derive(conf->instance, "objects", "total_objects",
363 else if (strcmp(name, "losthdr") == 0)
364 return varnish_submit_derive(conf->instance, "objects", "total_objects",
365 "header_overflow", val);
366 else if (strcmp(name, "n_obj_purged") == 0)
367 return varnish_submit_derive(conf->instance, "objects", "total_objects",
369 else if (strcmp(name, "n_objsendfile") == 0)
370 return varnish_submit_derive(conf->instance, "objects", "total_objects",
371 "sent_sendfile", val);
372 else if (strcmp(name, "n_objwrite") == 0)
373 return varnish_submit_derive(conf->instance, "objects", "total_objects",
375 else if (strcmp(name, "n_objoverflow") == 0)
376 return varnish_submit_derive(conf->instance, "objects", "total_objects",
377 "workspace_overflow", val);
378 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
379 else if (strcmp(name, "exp_mailed") == 0)
380 return varnish_submit_gauge(conf->instance, "struct", "objects",
382 else if (strcmp(name, "exp_received") == 0)
383 return varnish_submit_gauge(conf->instance, "struct", "objects",
384 "exp_received", val);
389 if (conf->collect_ban) {
390 if (strcmp(name, "n_ban") == 0)
391 return varnish_submit_derive(conf->instance, "ban", "total_operations",
393 else if (strcmp(name, "n_ban_add") == 0)
394 return varnish_submit_derive(conf->instance, "ban", "total_operations",
396 else if (strcmp(name, "n_ban_retire") == 0)
397 return varnish_submit_derive(conf->instance, "ban", "total_operations",
399 else if (strcmp(name, "n_ban_obj_test") == 0)
400 return varnish_submit_derive(conf->instance, "ban", "total_operations",
401 "objects_tested", val);
402 else if (strcmp(name, "n_ban_re_test") == 0)
403 return varnish_submit_derive(conf->instance, "ban", "total_operations",
404 "regexps_tested", val);
405 else if (strcmp(name, "n_ban_dups") == 0)
406 return varnish_submit_derive(conf->instance, "ban", "total_operations",
410 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
411 if (conf->collect_ban) {
412 if (strcmp(name, "bans") == 0)
413 return varnish_submit_derive(conf->instance, "ban", "total_operations",
415 else if (strcmp(name, "bans_added") == 0)
416 return varnish_submit_derive(conf->instance, "ban", "total_operations",
418 else if (strcmp(name, "bans_obj") == 0)
419 return varnish_submit_derive(conf->instance, "ban", "total_operations",
421 else if (strcmp(name, "bans_req") == 0)
422 return varnish_submit_derive(conf->instance, "ban", "total_operations",
424 else if (strcmp(name, "bans_completed") == 0)
425 return varnish_submit_derive(conf->instance, "ban", "total_operations",
427 else if (strcmp(name, "bans_deleted") == 0)
428 return varnish_submit_derive(conf->instance, "ban", "total_operations",
430 else if (strcmp(name, "bans_tested") == 0)
431 return varnish_submit_derive(conf->instance, "ban", "total_operations",
433 else if (strcmp(name, "bans_dups") == 0)
434 return varnish_submit_derive(conf->instance, "ban", "total_operations",
436 else if (strcmp(name, "bans_tested") == 0)
437 return varnish_submit_derive(conf->instance, "ban", "total_operations",
439 else if (strcmp(name, "bans_lurker_contention") == 0)
440 return varnish_submit_derive(conf->instance, "ban", "total_operations",
441 "lurker_contention", val);
442 else if (strcmp(name, "bans_lurker_obj_killed") == 0)
443 return varnish_submit_derive(conf->instance, "ban", "total_operations",
444 "lurker_obj_killed", val);
445 else if (strcmp(name, "bans_lurker_tested") == 0)
446 return varnish_submit_derive(conf->instance, "ban", "total_operations",
447 "lurker_tested", val);
448 else if (strcmp(name, "bans_lurker_tests_tested") == 0)
449 return varnish_submit_derive(conf->instance, "ban", "total_operations",
450 "lurker_tests_tested", val);
451 else if (strcmp(name, "bans_obj_killed") == 0)
452 return varnish_submit_derive(conf->instance, "ban", "total_operations",
454 else if (strcmp(name, "bans_persisted_bytes") == 0)
455 return varnish_submit_derive(conf->instance, "ban", "total_bytes",
456 "persisted_bytes", val);
457 else if (strcmp(name, "bans_persisted_fragmentation") == 0)
458 return varnish_submit_derive(conf->instance, "ban", "total_bytes",
459 "persisted_fragmentation", val);
460 else if (strcmp(name, "bans_tests_tested") == 0)
461 return varnish_submit_derive(conf->instance, "ban", "total_operations",
462 "tests_tested", val);
466 if (conf->collect_session) {
467 if (strcmp(name, "sess_closed") == 0)
468 return varnish_submit_derive(conf->instance, "session",
469 "total_operations", "closed", val);
470 else if (strcmp(name, "sess_pipeline") == 0)
471 return varnish_submit_derive(conf->instance, "session",
472 "total_operations", "pipeline", val);
473 else if (strcmp(name, "sess_readahead") == 0)
474 return varnish_submit_derive(conf->instance, "session",
475 "total_operations", "readahead", val);
476 else if (strcmp(name, "sess_conn") == 0)
477 return varnish_submit_derive(conf->instance, "session",
478 "total_operations", "accepted", val);
479 else if (strcmp(name, "sess_drop") == 0)
480 return varnish_submit_derive(conf->instance, "session",
481 "total_operations", "dropped", val);
482 else if (strcmp(name, "sess_fail") == 0)
483 return varnish_submit_derive(conf->instance, "session",
484 "total_operations", "failed", val);
485 else if (strcmp(name, "sess_pipe_overflow") == 0)
486 return varnish_submit_derive(conf->instance, "session",
487 "total_operations", "overflow", val);
488 else if (strcmp(name, "sess_queued") == 0)
489 return varnish_submit_derive(conf->instance, "session",
490 "total_operations", "queued", val);
491 else if (strcmp(name, "sess_linger") == 0)
492 return varnish_submit_derive(conf->instance, "session",
493 "total_operations", "linger", val);
494 else if (strcmp(name, "sess_herd") == 0)
495 return varnish_submit_derive(conf->instance, "session",
496 "total_operations", "herd", val);
497 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
498 else if (strcmp(name, "sess_closed_err") == 0)
499 return varnish_submit_derive(conf->instance, "session",
500 "total_operations", "closed_err", val);
501 else if (strcmp(name, "sess_dropped") == 0)
502 return varnish_submit_derive(conf->instance, "session",
503 "total_operations", "dropped_for_thread",
508 if (conf->collect_shm) {
509 if (strcmp(name, "shm_records") == 0)
510 return varnish_submit_derive(conf->instance, "shm", "total_operations",
512 else if (strcmp(name, "shm_writes") == 0)
513 return varnish_submit_derive(conf->instance, "shm", "total_operations",
515 else if (strcmp(name, "shm_flushes") == 0)
516 return varnish_submit_derive(conf->instance, "shm", "total_operations",
518 else if (strcmp(name, "shm_cont") == 0)
519 return varnish_submit_derive(conf->instance, "shm", "total_operations",
521 else if (strcmp(name, "shm_cycles") == 0)
522 return varnish_submit_derive(conf->instance, "shm", "total_operations",
526 if (conf->collect_sms) {
527 if (strcmp(name, "sms_nreq") == 0)
528 return varnish_submit_derive(conf->instance, "sms", "total_requests",
530 else if (strcmp(name, "sms_nobj") == 0)
531 return varnish_submit_gauge(conf->instance, "sms", "requests",
533 else if (strcmp(name, "sms_nbytes") == 0)
534 return varnish_submit_gauge(conf->instance, "sms", "bytes", "outstanding",
536 else if (strcmp(name, "sms_balloc") == 0)
537 return varnish_submit_derive(conf->instance, "sms", "total_bytes",
539 else if (strcmp(name, "sms_bfree") == 0)
540 return varnish_submit_derive(conf->instance, "sms", "total_bytes", "free",
544 if (conf->collect_struct) {
545 if (strcmp(name, "n_sess_mem") == 0)
546 return varnish_submit_gauge(conf->instance, "struct", "current_sessions",
548 else if (strcmp(name, "n_sess") == 0)
549 return varnish_submit_gauge(conf->instance, "struct", "current_sessions",
551 else if (strcmp(name, "n_object") == 0)
552 return varnish_submit_gauge(conf->instance, "struct", "objects", "object",
554 else if (strcmp(name, "n_vampireobject") == 0)
555 return varnish_submit_gauge(conf->instance, "struct", "objects",
556 "vampireobject", val);
557 else if (strcmp(name, "n_objectcore") == 0)
558 return varnish_submit_gauge(conf->instance, "struct", "objects",
560 else if (strcmp(name, "n_waitinglist") == 0)
561 return varnish_submit_gauge(conf->instance, "struct", "objects",
563 else if (strcmp(name, "n_objecthead") == 0)
564 return varnish_submit_gauge(conf->instance, "struct", "objects",
566 else if (strcmp(name, "n_smf") == 0)
567 return varnish_submit_gauge(conf->instance, "struct", "objects", "smf",
569 else if (strcmp(name, "n_smf_frag") == 0)
570 return varnish_submit_gauge(conf->instance, "struct", "objects",
572 else if (strcmp(name, "n_smf_large") == 0)
573 return varnish_submit_gauge(conf->instance, "struct", "objects",
575 else if (strcmp(name, "n_vbe_conn") == 0)
576 return varnish_submit_gauge(conf->instance, "struct", "objects",
580 if (conf->collect_totals) {
581 if (strcmp(name, "s_sess") == 0)
582 return varnish_submit_derive(conf->instance, "totals", "total_sessions",
584 else if (strcmp(name, "s_req") == 0)
585 return varnish_submit_derive(conf->instance, "totals", "total_requests",
587 else if (strcmp(name, "s_pipe") == 0)
588 return varnish_submit_derive(conf->instance, "totals", "total_operations",
590 else if (strcmp(name, "s_pass") == 0)
591 return varnish_submit_derive(conf->instance, "totals", "total_operations",
593 else if (strcmp(name, "s_fetch") == 0)
594 return varnish_submit_derive(conf->instance, "totals", "total_operations",
596 else if (strcmp(name, "s_synth") == 0)
597 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
599 else if (strcmp(name, "s_req_hdrbytes") == 0)
600 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
602 else if (strcmp(name, "s_req_bodybytes") == 0)
603 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
605 else if (strcmp(name, "s_req_protobytes") == 0)
606 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
608 else if (strcmp(name, "s_resp_hdrbytes") == 0)
609 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
611 else if (strcmp(name, "s_resp_bodybytes") == 0)
612 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
614 else if (strcmp(name, "s_resp_protobytes") == 0)
615 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
617 else if (strcmp(name, "s_pipe_hdrbytes") == 0)
618 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
620 else if (strcmp(name, "s_pipe_in") == 0)
621 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
623 else if (strcmp(name, "s_pipe_out") == 0)
624 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
626 else if (strcmp(name, "n_purges") == 0)
627 return varnish_submit_derive(conf->instance, "totals", "total_operations",
629 else if (strcmp(name, "s_hdrbytes") == 0)
630 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
631 "header-bytes", val);
632 else if (strcmp(name, "s_bodybytes") == 0)
633 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
635 else if (strcmp(name, "n_gzip") == 0)
636 return varnish_submit_derive(conf->instance, "totals", "total_operations",
638 else if (strcmp(name, "n_gunzip") == 0)
639 return varnish_submit_derive(conf->instance, "totals", "total_operations",
643 if (conf->collect_uptime) {
644 if (strcmp(name, "uptime") == 0)
645 return varnish_submit_gauge(conf->instance, "uptime", "uptime",
646 "client_uptime", val);
649 if (conf->collect_vcl) {
650 if (strcmp(name, "n_vcl") == 0)
651 return varnish_submit_gauge(conf->instance, "vcl", "vcl", "total_vcl",
653 else if (strcmp(name, "n_vcl_avail") == 0)
654 return varnish_submit_gauge(conf->instance, "vcl", "vcl", "avail_vcl",
656 else if (strcmp(name, "n_vcl_discard") == 0)
657 return varnish_submit_gauge(conf->instance, "vcl", "vcl", "discarded_vcl",
659 else if (strcmp(name, "vmods") == 0)
660 return varnish_submit_gauge(conf->instance, "vcl", "objects", "vmod",
664 if (conf->collect_workers) {
665 if (strcmp(name, "threads") == 0)
666 return varnish_submit_gauge(conf->instance, "workers", "threads",
668 else if (strcmp(name, "threads_created") == 0)
669 return varnish_submit_derive(conf->instance, "workers", "total_threads",
671 else if (strcmp(name, "threads_failed") == 0)
672 return varnish_submit_derive(conf->instance, "workers", "total_threads",
674 else if (strcmp(name, "threads_limited") == 0)
675 return varnish_submit_derive(conf->instance, "workers", "total_threads",
677 else if (strcmp(name, "threads_destroyed") == 0)
678 return varnish_submit_derive(conf->instance, "workers", "total_threads",
680 else if (strcmp(name, "thread_queue_len") == 0)
681 return varnish_submit_gauge(conf->instance, "workers", "queue_length",
683 else if (strcmp(name, "n_wrk") == 0)
684 return varnish_submit_gauge(conf->instance, "workers", "threads",
686 else if (strcmp(name, "n_wrk_create") == 0)
687 return varnish_submit_derive(conf->instance, "workers", "total_threads",
689 else if (strcmp(name, "n_wrk_failed") == 0)
690 return varnish_submit_derive(conf->instance, "workers", "total_threads",
692 else if (strcmp(name, "n_wrk_max") == 0)
693 return varnish_submit_derive(conf->instance, "workers", "total_threads",
695 else if (strcmp(name, "n_wrk_drop") == 0)
696 return varnish_submit_derive(conf->instance, "workers", "total_threads",
698 else if (strcmp(name, "n_wrk_queue") == 0)
699 return varnish_submit_derive(conf->instance, "workers", "total_requests",
701 else if (strcmp(name, "n_wrk_overflow") == 0)
702 return varnish_submit_derive(conf->instance, "workers", "total_requests",
704 else if (strcmp(name, "n_wrk_queued") == 0)
705 return varnish_submit_derive(conf->instance, "workers", "total_requests",
707 else if (strcmp(name, "n_wrk_lqueue") == 0)
708 return varnish_submit_derive(conf->instance, "workers", "total_requests",
709 "queue_length", val);
710 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
711 else if (strcmp(name, "pools") == 0)
712 return varnish_submit_gauge(conf->instance, "workers", "pools", "pools",
714 else if (strcmp(name, "busy_killed") == 0)
715 return varnish_submit_derive(conf->instance, "workers", "http_requests",
720 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
721 if (conf->collect_vsm) {
722 if (strcmp(name, "vsm_free") == 0)
723 return varnish_submit_gauge(conf->instance, "vsm", "bytes", "free", val);
724 else if (strcmp(name, "vsm_used") == 0)
725 return varnish_submit_gauge(conf->instance, "vsm", "bytes", "used", val);
726 else if (strcmp(name, "vsm_cooling") == 0)
727 return varnish_submit_gauge(conf->instance, "vsm", "bytes", "cooling",
729 else if (strcmp(name, "vsm_overflow") == 0)
730 return varnish_submit_gauge(conf->instance, "vsm", "bytes", "overflow",
732 else if (strcmp(name, "vsm_overflowed") == 0)
733 return varnish_submit_derive(conf->instance, "vsm", "total_bytes",
737 if (conf->collect_vbe) {
738 /* @TODO figure out the collectd type for bitmap
739 if (strcmp(name, "happy") == 0)
740 return varnish_submit_derive(conf->instance, "vbe",
741 "bitmap", "happy_hprobes", val);
743 if (strcmp(name, "bereq_hdrbytes") == 0)
744 return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
745 "bereq_hdrbytes", val);
746 else if (strcmp(name, "bereq_bodybytes") == 0)
747 return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
748 "bereq_bodybytes", val);
749 else if (strcmp(name, "bereq_protobytes") == 0)
750 return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
751 "bereq_protobytes", val);
752 else if (strcmp(name, "beresp_hdrbytes") == 0)
753 return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
754 "beresp_hdrbytes", val);
755 else if (strcmp(name, "beresp_bodybytes") == 0)
756 return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
757 "beresp_bodybytes", val);
758 else if (strcmp(name, "beresp_protobytes") == 0)
759 return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
760 "beresp_protobytes", val);
761 else if (strcmp(name, "pipe_hdrbytes") == 0)
762 return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
763 "pipe_hdrbytes", val);
764 else if (strcmp(name, "pipe_out") == 0)
765 return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
767 else if (strcmp(name, "pipe_in") == 0)
768 return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
770 else if (strcmp(name, "conn") == 0)
771 return varnish_submit_derive(conf->instance, "vbe", "connections",
773 else if (strcmp(name, "req") == 0)
774 return varnish_submit_derive(conf->instance, "vbe", "http_requests",
778 /* All Stevedores support these counters */
779 if (conf->collect_sma || conf->collect_smf || conf->collect_mse) {
782 if (conf->collect_sma)
783 strncpy(category, "sma", 4);
784 else if (conf->collect_smf)
785 strncpy(category, "smf", 4);
787 strncpy(category, "mse", 4);
789 if (strcmp(name, "c_req") == 0)
790 return varnish_submit_derive(conf->instance, category, "total_operations",
792 else if (strcmp(name, "c_fail") == 0)
793 return varnish_submit_derive(conf->instance, category, "total_operations",
795 else if (strcmp(name, "c_bytes") == 0)
796 return varnish_submit_derive(conf->instance, category, "total_bytes",
797 "bytes_allocated", val);
798 else if (strcmp(name, "c_freed") == 0)
799 return varnish_submit_derive(conf->instance, category, "total_bytes",
801 else if (strcmp(name, "g_alloc") == 0)
802 return varnish_submit_derive(conf->instance, category, "total_operations",
803 "alloc_outstanding", val);
804 else if (strcmp(name, "g_bytes") == 0)
805 return varnish_submit_gauge(conf->instance, category, "bytes",
806 "bytes_outstanding", val);
807 else if (strcmp(name, "g_space") == 0)
808 return varnish_submit_gauge(conf->instance, category, "bytes",
809 "bytes_available", val);
812 /* No SMA specific counters */
814 if (conf->collect_smf) {
815 if (strcmp(name, "g_smf") == 0)
816 return varnish_submit_gauge(conf->instance, "smf", "objects",
817 "n_struct_smf", val);
818 else if (strcmp(name, "g_smf_frag") == 0)
819 return varnish_submit_gauge(conf->instance, "smf", "objects",
820 "n_small_free_smf", val);
821 else if (strcmp(name, "g_smf_large") == 0)
822 return varnish_submit_gauge(conf->instance, "smf", "objects",
823 "n_large_free_smf", val);
826 if (conf->collect_mgt) {
827 if (strcmp(name, "uptime") == 0)
828 return varnish_submit_gauge(conf->instance, "mgt", "uptime",
829 "mgt_proc_uptime", val);
830 else if (strcmp(name, "child_start") == 0)
831 return varnish_submit_derive(conf->instance, "mgt", "total_operations",
833 else if (strcmp(name, "child_exit") == 0)
834 return varnish_submit_derive(conf->instance, "mgt", "total_operations",
836 else if (strcmp(name, "child_stop") == 0)
837 return varnish_submit_derive(conf->instance, "mgt", "total_operations",
839 else if (strcmp(name, "child_died") == 0)
840 return varnish_submit_derive(conf->instance, "mgt", "total_operations",
842 else if (strcmp(name, "child_dump") == 0)
843 return varnish_submit_derive(conf->instance, "mgt", "total_operations",
845 else if (strcmp(name, "child_panic") == 0)
846 return varnish_submit_derive(conf->instance, "mgt", "total_operations",
850 if (conf->collect_lck) {
851 if (strcmp(name, "creat") == 0)
852 return varnish_submit_gauge(conf->instance, "lck", "objects", "created",
854 else if (strcmp(name, "destroy") == 0)
855 return varnish_submit_gauge(conf->instance, "lck", "objects", "destroyed",
857 else if (strcmp(name, "locks") == 0)
858 return varnish_submit_derive(conf->instance, "lck", "total_operations",
862 if (conf->collect_mempool) {
863 if (strcmp(name, "live") == 0)
864 return varnish_submit_gauge(conf->instance, "mempool", "objects",
866 else if (strcmp(name, "pool") == 0)
867 return varnish_submit_gauge(conf->instance, "mempool", "objects",
869 else if (strcmp(name, "sz_wanted") == 0)
870 return varnish_submit_gauge(conf->instance, "mempool", "bytes",
871 "size_requested", val);
872 else if (strcmp(name, "sz_actual") == 0)
873 return varnish_submit_gauge(conf->instance, "mempool", "bytes",
874 "size_allocated", val);
875 else if (strcmp(name, "allocs") == 0)
876 return varnish_submit_derive(conf->instance, "mempool",
877 "total_operations", "allocations", val);
878 else if (strcmp(name, "frees") == 0)
879 return varnish_submit_derive(conf->instance, "mempool",
880 "total_operations", "frees", val);
881 else if (strcmp(name, "recycle") == 0)
882 return varnish_submit_gauge(conf->instance, "mempool", "objects",
884 else if (strcmp(name, "timeout") == 0)
885 return varnish_submit_gauge(conf->instance, "mempool", "objects",
887 else if (strcmp(name, "toosmall") == 0)
888 return varnish_submit_gauge(conf->instance, "mempool", "objects",
890 else if (strcmp(name, "surplus") == 0)
891 return varnish_submit_gauge(conf->instance, "mempool", "objects",
893 else if (strcmp(name, "randry") == 0)
894 return varnish_submit_gauge(conf->instance, "mempool", "objects",
898 if (conf->collect_mse) {
899 if (strcmp(name, "c_full") == 0)
900 return varnish_submit_derive(conf->instance, "mse", "total_operations",
902 else if (strcmp(name, "c_truncated") == 0)
903 return varnish_submit_derive(conf->instance, "mse", "total_operations",
904 "truncated_allocs", val);
905 else if (strcmp(name, "c_expanded") == 0)
906 return varnish_submit_derive(conf->instance, "mse", "total_operations",
907 "expanded_allocs", val);
908 else if (strcmp(name, "c_failed") == 0)
909 return varnish_submit_derive(conf->instance, "mse", "total_operations",
910 "failed_allocs", val);
911 else if (strcmp(name, "c_bytes") == 0)
912 return varnish_submit_derive(conf->instance, "mse", "total_bytes",
913 "bytes_allocated", val);
914 else if (strcmp(name, "c_freed") == 0)
915 return varnish_submit_derive(conf->instance, "mse", "total_bytes",
917 else if (strcmp(name, "g_fo_alloc") == 0)
918 return varnish_submit_derive(conf->instance, "mse", "total_operations",
919 "fo_allocs_outstanding", val);
920 else if (strcmp(name, "g_fo_bytes") == 0)
921 return varnish_submit_gauge(conf->instance, "mse", "bytes",
922 "fo_bytes_outstanding", val);
923 else if (strcmp(name, "g_membuf_alloc") == 0)
924 return varnish_submit_gauge(conf->instance, "mse", "objects",
925 "membufs_allocated", val);
926 else if (strcmp(name, "g_membuf_inuse") == 0)
927 return varnish_submit_gauge(conf->instance, "mse", "objects",
928 "membufs_inuse", val);
929 else if (strcmp(name, "g_bans_bytes") == 0)
930 return varnish_submit_gauge(conf->instance, "mse", "bytes",
931 "persisted_banspace_used", val);
932 else if (strcmp(name, "g_bans_space") == 0)
933 return varnish_submit_gauge(conf->instance, "mse", "bytes",
934 "persisted_banspace_available", val);
935 else if (strcmp(name, "g_bans_persisted") == 0)
936 return varnish_submit_derive(conf->instance, "mse", "total_operations",
937 "bans_persisted", val);
938 else if (strcmp(name, "g_bans_lost") == 0)
939 return varnish_submit_derive(conf->instance, "mse", "total_operations",
943 else if (strcmp(name, "g_journal_bytes") == 0)
944 return varnish_submit_gauge(conf->instance, "mse_reg", "bytes",
945 "journal_bytes_used", val);
946 else if (strcmp(name, "g_journal_space") == 0)
947 return varnish_submit_gauge(conf->instance, "mse_reg", "bytes",
948 "journal_bytes_free", val);
951 else if (strcmp(name, "g_bigspace") == 0)
952 return varnish_submit_gauge(conf->instance, "mse_segagg", "bytes",
953 "big_extents_bytes_available", val);
954 else if (strcmp(name, "g_extfree") == 0)
955 return varnish_submit_gauge(conf->instance, "mse_segagg", "objects",
956 "free_extents", val);
957 else if (strcmp(name, "g_sparenode") == 0)
958 return varnish_submit_gauge(conf->instance, "mse_segagg", "objects",
959 "spare_nodes_available", val);
960 else if (strcmp(name, "g_objnode") == 0)
961 return varnish_submit_gauge(conf->instance, "mse_segagg", "objects",
962 "object_nodes_in_use", val);
963 else if (strcmp(name, "g_extnode") == 0)
964 return varnish_submit_gauge(conf->instance, "mse_segagg", "objects",
965 "extent_nodes_in_use", val);
966 else if (strcmp(name, "g_bigextfree") == 0)
967 return varnish_submit_gauge(conf->instance, "mse_segagg", "objects",
968 "free_big_extents", val);
969 else if (strcmp(name, "c_pruneloop") == 0)
970 return varnish_submit_derive(conf->instance, "mse_segagg",
971 "total_operations", "prune_loops", val);
972 else if (strcmp(name, "c_pruned") == 0)
973 return varnish_submit_derive(conf->instance, "mse_segagg",
974 "total_objects", "pruned_objects", val);
975 else if (strcmp(name, "c_spared") == 0)
976 return varnish_submit_derive(conf->instance, "mse_segagg",
977 "total_operations", "spared_objects", val);
978 else if (strcmp(name, "c_skipped") == 0)
979 return varnish_submit_derive(conf->instance, "mse_segagg",
980 "total_operations", "missed_objects", val);
981 else if (strcmp(name, "c_nuked") == 0)
982 return varnish_submit_derive(conf->instance, "mse_segagg",
983 "total_operations", "nuked_objects", val);
984 else if (strcmp(name, "c_sniped") == 0)
985 return varnish_submit_derive(conf->instance, "mse_segagg",
986 "total_operations", "sniped_objects", val);
993 } /* }}} static int varnish_monitor */
994 #else /* if HAVE_VARNISH_V2 */
995 static void varnish_monitor(const user_config_t *conf, /* {{{ */
996 const c_varnish_stats_t *stats) {
997 if (conf->collect_cache) {
999 varnish_submit_derive(conf->instance, "cache", "cache_result", "hit",
1002 varnish_submit_derive(conf->instance, "cache", "cache_result", "miss",
1004 /* Cache hits for pass */
1005 varnish_submit_derive(conf->instance, "cache", "cache_result", "hitpass",
1006 stats->cache_hitpass);
1009 if (conf->collect_connections) {
1010 /* Client connections accepted */
1011 varnish_submit_derive(conf->instance, "connections", "connections",
1012 "accepted", stats->client_conn);
1013 /* Connection dropped, no sess */
1014 varnish_submit_derive(conf->instance, "connections", "connections",
1015 "dropped", stats->client_drop);
1016 /* Client requests received */
1017 varnish_submit_derive(conf->instance, "connections", "connections",
1018 "received", stats->client_req);
1021 if (conf->collect_esi) {
1022 /* ESI parse errors (unlock) */
1023 varnish_submit_derive(conf->instance, "esi", "total_operations", "error",
1025 /* Objects ESI parsed (unlock) */
1026 varnish_submit_derive(conf->instance, "esi", "total_operations", "parsed",
1030 if (conf->collect_backend) {
1031 /* Backend conn. success */
1032 varnish_submit_derive(conf->instance, "backend", "connections", "success",
1033 stats->backend_conn);
1034 /* Backend conn. not attempted */
1035 varnish_submit_derive(conf->instance, "backend", "connections",
1036 "not-attempted", stats->backend_unhealthy);
1037 /* Backend conn. too many */
1038 varnish_submit_derive(conf->instance, "backend", "connections", "too-many",
1039 stats->backend_busy);
1040 /* Backend conn. failures */
1041 varnish_submit_derive(conf->instance, "backend", "connections", "failures",
1042 stats->backend_fail);
1043 /* Backend conn. reuses */
1044 varnish_submit_derive(conf->instance, "backend", "connections", "reuses",
1045 stats->backend_reuse);
1046 /* Backend conn. was closed */
1047 varnish_submit_derive(conf->instance, "backend", "connections",
1048 "was-closed", stats->backend_toolate);
1049 /* Backend conn. recycles */
1050 varnish_submit_derive(conf->instance, "backend", "connections", "recycled",
1051 stats->backend_recycle);
1052 /* Backend conn. unused */
1053 varnish_submit_derive(conf->instance, "backend", "connections", "unused",
1054 stats->backend_unused);
1055 /* Backend requests mades */
1056 varnish_submit_derive(conf->instance, "backend", "http_requests",
1057 "requests", stats->backend_req);
1059 varnish_submit_gauge(conf->instance, "backend", "backends", "n_backends",
1063 if (conf->collect_fetch) {
1065 varnish_submit_derive(conf->instance, "fetch", "http_requests", "head",
1067 /* Fetch with length */
1068 varnish_submit_derive(conf->instance, "fetch", "http_requests", "length",
1069 stats->fetch_length);
1071 varnish_submit_derive(conf->instance, "fetch", "http_requests", "chunked",
1072 stats->fetch_chunked);
1074 varnish_submit_derive(conf->instance, "fetch", "http_requests", "eof",
1076 /* Fetch bad headers */
1077 varnish_submit_derive(conf->instance, "fetch", "http_requests",
1078 "bad_headers", stats->fetch_bad);
1079 /* Fetch wanted close */
1080 varnish_submit_derive(conf->instance, "fetch", "http_requests", "close",
1081 stats->fetch_close);
1082 /* Fetch pre HTTP/1.1 closed */
1083 varnish_submit_derive(conf->instance, "fetch", "http_requests", "oldhttp",
1084 stats->fetch_oldhttp);
1085 /* Fetch zero len */
1086 varnish_submit_derive(conf->instance, "fetch", "http_requests", "zero",
1089 varnish_submit_derive(conf->instance, "fetch", "http_requests", "failed",
1090 stats->fetch_failed);
1093 if (conf->collect_hcb) {
1094 /* HCB Lookups without lock */
1095 varnish_submit_derive(conf->instance, "hcb", "cache_operation",
1096 "lookup_nolock", stats->hcb_nolock);
1097 /* HCB Lookups with lock */
1098 varnish_submit_derive(conf->instance, "hcb", "cache_operation",
1099 "lookup_lock", stats->hcb_lock);
1101 varnish_submit_derive(conf->instance, "hcb", "cache_operation", "insert",
1105 if (conf->collect_objects) {
1106 /* N expired objects */
1107 varnish_submit_derive(conf->instance, "objects", "total_objects", "expired",
1109 /* N LRU nuked objects */
1110 varnish_submit_derive(conf->instance, "objects", "total_objects",
1111 "lru_nuked", stats->n_lru_nuked);
1112 /* N LRU saved objects */
1113 varnish_submit_derive(conf->instance, "objects", "total_objects",
1114 "lru_saved", stats->n_lru_saved);
1115 /* N LRU moved objects */
1116 varnish_submit_derive(conf->instance, "objects", "total_objects",
1117 "lru_moved", stats->n_lru_moved);
1118 /* N objects on deathrow */
1119 varnish_submit_derive(conf->instance, "objects", "total_objects",
1120 "deathrow", stats->n_deathrow);
1121 /* HTTP header overflows */
1122 varnish_submit_derive(conf->instance, "objects", "total_objects",
1123 "header_overflow", stats->losthdr);
1124 /* Objects sent with sendfile */
1125 varnish_submit_derive(conf->instance, "objects", "total_objects",
1126 "sent_sendfile", stats->n_objsendfile);
1127 /* Objects sent with write */
1128 varnish_submit_derive(conf->instance, "objects", "total_objects",
1129 "sent_write", stats->n_objwrite);
1130 /* Objects overflowing workspace */
1131 varnish_submit_derive(conf->instance, "objects", "total_objects",
1132 "workspace_overflow", stats->n_objoverflow);
1135 if (conf->collect_purge) {
1136 /* N total active purges */
1137 varnish_submit_derive(conf->instance, "purge", "total_operations", "total",
1139 /* N new purges added */
1140 varnish_submit_derive(conf->instance, "purge", "total_operations", "added",
1141 stats->n_purge_add);
1142 /* N old purges deleted */
1143 varnish_submit_derive(conf->instance, "purge", "total_operations",
1144 "deleted", stats->n_purge_retire);
1145 /* N objects tested */
1146 varnish_submit_derive(conf->instance, "purge", "total_operations",
1147 "objects_tested", stats->n_purge_obj_test);
1148 /* N regexps tested against */
1149 varnish_submit_derive(conf->instance, "purge", "total_operations",
1150 "regexps_tested", stats->n_purge_re_test);
1151 /* N duplicate purges removed */
1152 varnish_submit_derive(conf->instance, "purge", "total_operations",
1153 "duplicate", stats->n_purge_dups);
1156 if (conf->collect_session) {
1157 /* Session Closed */
1158 varnish_submit_derive(conf->instance, "session", "total_operations",
1159 "closed", stats->sess_closed);
1160 /* Session Pipeline */
1161 varnish_submit_derive(conf->instance, "session", "total_operations",
1162 "pipeline", stats->sess_pipeline);
1163 /* Session Read Ahead */
1164 varnish_submit_derive(conf->instance, "session", "total_operations",
1165 "readahead", stats->sess_readahead);
1166 /* Session Linger */
1167 varnish_submit_derive(conf->instance, "session", "total_operations",
1168 "linger", stats->sess_linger);
1170 varnish_submit_derive(conf->instance, "session", "total_operations", "herd",
1174 if (conf->collect_shm) {
1176 varnish_submit_derive(conf->instance, "shm", "total_operations", "records",
1177 stats->shm_records);
1179 varnish_submit_derive(conf->instance, "shm", "total_operations", "writes",
1181 /* SHM flushes due to overflow */
1182 varnish_submit_derive(conf->instance, "shm", "total_operations", "flushes",
1183 stats->shm_flushes);
1184 /* SHM MTX contention */
1185 varnish_submit_derive(conf->instance, "shm", "total_operations",
1186 "contention", stats->shm_cont);
1187 /* SHM cycles through buffer */
1188 varnish_submit_derive(conf->instance, "shm", "total_operations", "cycles",
1192 if (conf->collect_sm) {
1193 /* allocator requests */
1194 varnish_submit_derive(conf->instance, "sm", "total_requests", "nreq",
1196 /* outstanding allocations */
1197 varnish_submit_gauge(conf->instance, "sm", "requests", "outstanding",
1199 /* bytes allocated */
1200 varnish_submit_derive(conf->instance, "sm", "total_bytes", "allocated",
1203 varnish_submit_derive(conf->instance, "sm", "total_bytes", "free",
1207 if (conf->collect_sma) {
1208 /* SMA allocator requests */
1209 varnish_submit_derive(conf->instance, "sma", "total_requests", "nreq",
1211 /* SMA outstanding allocations */
1212 varnish_submit_gauge(conf->instance, "sma", "requests", "outstanding",
1214 /* SMA outstanding bytes */
1215 varnish_submit_gauge(conf->instance, "sma", "bytes", "outstanding",
1217 /* SMA bytes allocated */
1218 varnish_submit_derive(conf->instance, "sma", "total_bytes", "allocated",
1220 /* SMA bytes free */
1221 varnish_submit_derive(conf->instance, "sma", "total_bytes", "free",
1225 if (conf->collect_sms) {
1226 /* SMS allocator requests */
1227 varnish_submit_derive(conf->instance, "sms", "total_requests", "allocator",
1229 /* SMS outstanding allocations */
1230 varnish_submit_gauge(conf->instance, "sms", "requests", "outstanding",
1232 /* SMS outstanding bytes */
1233 varnish_submit_gauge(conf->instance, "sms", "bytes", "outstanding",
1235 /* SMS bytes allocated */
1236 varnish_submit_derive(conf->instance, "sms", "total_bytes", "allocated",
1238 /* SMS bytes freed */
1239 varnish_submit_derive(conf->instance, "sms", "total_bytes", "free",
1243 if (conf->collect_struct) {
1244 /* N struct sess_mem */
1245 varnish_submit_gauge(conf->instance, "struct", "current_sessions",
1246 "sess_mem", stats->n_sess_mem);
1248 varnish_submit_gauge(conf->instance, "struct", "current_sessions", "sess",
1250 /* N struct object */
1251 varnish_submit_gauge(conf->instance, "struct", "objects", "object",
1253 /* N struct objecthead */
1254 varnish_submit_gauge(conf->instance, "struct", "objects", "objecthead",
1255 stats->n_objecthead);
1257 varnish_submit_gauge(conf->instance, "struct", "objects", "smf",
1259 /* N small free smf */
1260 varnish_submit_gauge(conf->instance, "struct", "objects", "smf_frag",
1262 /* N large free smf */
1263 varnish_submit_gauge(conf->instance, "struct", "objects", "smf_large",
1264 stats->n_smf_large);
1265 /* N struct vbe_conn */
1266 varnish_submit_gauge(conf->instance, "struct", "objects", "vbe_conn",
1270 if (conf->collect_totals) {
1271 /* Total Sessions */
1272 varnish_submit_derive(conf->instance, "totals", "total_sessions",
1273 "sessions", stats->s_sess);
1274 /* Total Requests */
1275 varnish_submit_derive(conf->instance, "totals", "total_requests",
1276 "requests", stats->s_req);
1278 varnish_submit_derive(conf->instance, "totals", "total_operations", "pipe",
1281 varnish_submit_derive(conf->instance, "totals", "total_operations", "pass",
1284 varnish_submit_derive(conf->instance, "totals", "total_operations",
1285 "fetches", stats->s_fetch);
1286 /* Total header bytes */
1287 varnish_submit_derive(conf->instance, "totals", "total_bytes",
1288 "header-bytes", stats->s_hdrbytes);
1289 /* Total body byte */
1290 varnish_submit_derive(conf->instance, "totals", "total_bytes", "body-bytes",
1291 stats->s_bodybytes);
1294 if (conf->collect_vcl) {
1296 varnish_submit_gauge(conf->instance, "vcl", "vcl", "total_vcl",
1298 /* N vcl available */
1299 varnish_submit_gauge(conf->instance, "vcl", "vcl", "avail_vcl",
1300 stats->n_vcl_avail);
1301 /* N vcl discarded */
1302 varnish_submit_gauge(conf->instance, "vcl", "vcl", "discarded_vcl",
1303 stats->n_vcl_discard);
1306 if (conf->collect_workers) {
1307 /* worker threads */
1308 varnish_submit_gauge(conf->instance, "workers", "threads", "worker",
1310 /* worker threads created */
1311 varnish_submit_derive(conf->instance, "workers", "total_threads", "created",
1312 stats->n_wrk_create);
1313 /* worker threads not created */
1314 varnish_submit_derive(conf->instance, "workers", "total_threads", "failed",
1315 stats->n_wrk_failed);
1316 /* worker threads limited */
1317 varnish_submit_derive(conf->instance, "workers", "total_threads", "limited",
1319 /* dropped work requests */
1320 varnish_submit_derive(conf->instance, "workers", "total_threads", "dropped",
1322 /* queued work requests */
1323 varnish_submit_derive(conf->instance, "workers", "total_requests", "queued",
1324 stats->n_wrk_queue);
1325 /* overflowed work requests */
1326 varnish_submit_derive(conf->instance, "workers", "total_requests",
1327 "overflowed", stats->n_wrk_overflow);
1330 } /* }}} void varnish_monitor */
1333 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1334 static int varnish_read(user_data_t *ud) /* {{{ */
1336 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
1337 struct VSM_data *vd;
1339 const c_varnish_stats_t *stats;
1340 #elif HAVE_VARNISH_V5
1346 user_config_t *conf;
1348 if ((ud == NULL) || (ud->data == NULL))
1363 if (conf->instance != NULL) {
1366 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
1367 status = VSM_n_Arg(vd, conf->instance);
1368 #elif HAVE_VARNISH_V5
1369 status = VSM_Arg(vd, 'n', conf->instance);
1373 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
1375 #elif HAVE_VARNISH_V5
1376 VSC_Destroy(&vsc, vd);
1379 ERROR("varnish plugin: VSM_Arg (\"%s\") failed "
1381 conf->instance, status);
1387 ok = (VSC_Open(vd, /* diag = */ 1) == 0);
1388 #elif HAVE_VARNISH_V4
1389 ok = (VSM_Open(vd) == 0);
1391 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
1394 ERROR("varnish plugin: Unable to open connection.");
1400 stats = VSC_Main(vd);
1401 #elif HAVE_VARNISH_V4
1402 stats = VSC_Main(vd, NULL);
1404 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
1407 ERROR("varnish plugin: Unable to get statistics.");
1413 if (VSM_Attach(vd, STDERR_FILENO)) {
1414 ERROR("varnish plugin: Cannot attach to varnish. %s", VSM_Error(vd));
1415 VSC_Destroy(&vsc, vd);
1420 vsm_status = VSM_Status(vd);
1421 if (vsm_status & ~(VSM_MGT_RUNNING | VSM_WRK_RUNNING)) {
1422 ERROR("varnish plugin: Unable to get statistics.");
1423 VSC_Destroy(&vsc, vd);
1430 VSC_Iter(vd, varnish_monitor, conf);
1431 #elif HAVE_VARNISH_V4
1432 VSC_Iter(vd, NULL, varnish_monitor, conf);
1433 #elif HAVE_VARNISH_V5
1434 VSC_Iter(vsc, vd, varnish_monitor, conf);
1437 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
1439 #elif HAVE_VARNISH_V5
1440 VSC_Destroy(&vsc, vd);
1446 #else /* if HAVE_VARNISH_V2 */
1447 static int varnish_read(user_data_t *ud) /* {{{ */
1449 const c_varnish_stats_t *stats;
1451 user_config_t *conf;
1453 if ((ud == NULL) || (ud->data == NULL))
1458 stats = VSL_OpenStats(conf->instance);
1459 if (stats == NULL) {
1460 ERROR("Varnish plugin : unable to load statistics");
1465 varnish_monitor(conf, stats);
1471 static void varnish_config_free(void *ptr) /* {{{ */
1473 user_config_t *conf = ptr;
1478 sfree(conf->instance);
1482 static int varnish_config_apply_default(user_config_t *conf) /* {{{ */
1487 conf->collect_backend = 1;
1488 conf->collect_cache = 1;
1489 conf->collect_connections = 1;
1490 #ifdef HAVE_VARNISH_V3
1491 conf->collect_dirdns = 0;
1493 conf->collect_esi = 0;
1494 conf->collect_fetch = 0;
1495 conf->collect_hcb = 0;
1496 conf->collect_objects = 0;
1498 conf->collect_purge = 0;
1500 conf->collect_ban = 0;
1502 conf->collect_session = 0;
1503 conf->collect_shm = 1;
1505 conf->collect_sm = 0;
1507 #if HAVE_VARNISH_V2 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1508 conf->collect_sma = 0;
1510 conf->collect_sms = 0;
1511 conf->collect_struct = 0;
1512 conf->collect_totals = 0;
1513 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1514 conf->collect_uptime = 0;
1516 conf->collect_vcl = 0;
1517 conf->collect_workers = 0;
1518 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1519 conf->collect_vsm = 0;
1520 conf->collect_lck = 0;
1521 conf->collect_mempool = 0;
1522 conf->collect_mgt = 0;
1523 conf->collect_smf = 0;
1524 conf->collect_vbe = 0;
1525 conf->collect_mse = 0;
1529 } /* }}} int varnish_config_apply_default */
1531 static int varnish_init(void) /* {{{ */
1533 user_config_t *conf;
1538 conf = calloc(1, sizeof(*conf));
1542 /* Default settings: */
1543 conf->instance = NULL;
1545 varnish_config_apply_default(conf);
1547 plugin_register_complex_read(
1548 /* group = */ "varnish",
1549 /* name = */ "varnish/localhost",
1550 /* callback = */ varnish_read,
1553 .data = conf, .free_func = varnish_config_free,
1557 } /* }}} int varnish_init */
1559 static int varnish_config_instance(const oconfig_item_t *ci) /* {{{ */
1561 user_config_t *conf;
1562 char callback_name[DATA_MAX_NAME_LEN];
1564 conf = calloc(1, sizeof(*conf));
1567 conf->instance = NULL;
1569 varnish_config_apply_default(conf);
1571 if (ci->values_num == 1) {
1574 status = cf_util_get_string(ci, &conf->instance);
1579 assert(conf->instance != NULL);
1581 if (strcmp("localhost", conf->instance) == 0) {
1582 sfree(conf->instance);
1583 conf->instance = NULL;
1585 } else if (ci->values_num > 1) {
1586 WARNING("Varnish plugin: \"Instance\" blocks accept only "
1592 for (int i = 0; i < ci->children_num; i++) {
1593 oconfig_item_t *child = ci->children + i;
1595 if (strcasecmp("CollectCache", child->key) == 0)
1596 cf_util_get_boolean(child, &conf->collect_cache);
1597 else if (strcasecmp("CollectConnections", child->key) == 0)
1598 cf_util_get_boolean(child, &conf->collect_connections);
1599 else if (strcasecmp("CollectESI", child->key) == 0)
1600 cf_util_get_boolean(child, &conf->collect_esi);
1601 else if (strcasecmp("CollectDirectorDNS", child->key) == 0)
1602 #ifdef HAVE_VARNISH_V3
1603 cf_util_get_boolean(child, &conf->collect_dirdns);
1605 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1608 else if (strcasecmp("CollectBackend", child->key) == 0)
1609 cf_util_get_boolean(child, &conf->collect_backend);
1610 else if (strcasecmp("CollectFetch", child->key) == 0)
1611 cf_util_get_boolean(child, &conf->collect_fetch);
1612 else if (strcasecmp("CollectHCB", child->key) == 0)
1613 cf_util_get_boolean(child, &conf->collect_hcb);
1614 else if (strcasecmp("CollectObjects", child->key) == 0)
1615 cf_util_get_boolean(child, &conf->collect_objects);
1616 else if (strcasecmp("CollectPurge", child->key) == 0)
1618 cf_util_get_boolean(child, &conf->collect_purge);
1620 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1623 else if (strcasecmp("CollectBan", child->key) == 0)
1625 WARNING("Varnish plugin: \"%s\" is not available for Varnish %s.",
1628 cf_util_get_boolean(child, &conf->collect_ban);
1630 else if (strcasecmp("CollectSession", child->key) == 0)
1631 cf_util_get_boolean(child, &conf->collect_session);
1632 else if (strcasecmp("CollectSHM", child->key) == 0)
1633 cf_util_get_boolean(child, &conf->collect_shm);
1634 else if (strcasecmp("CollectSMS", child->key) == 0)
1635 cf_util_get_boolean(child, &conf->collect_sms);
1636 else if (strcasecmp("CollectSMA", child->key) == 0)
1637 #if HAVE_VARNISH_V2 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1638 cf_util_get_boolean(child, &conf->collect_sma);
1640 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1641 child->key, "v2 and v4");
1643 else if (strcasecmp("CollectSM", child->key) == 0)
1645 cf_util_get_boolean(child, &conf->collect_sm);
1647 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1650 else if (strcasecmp("CollectStruct", child->key) == 0)
1651 cf_util_get_boolean(child, &conf->collect_struct);
1652 else if (strcasecmp("CollectTotals", child->key) == 0)
1653 cf_util_get_boolean(child, &conf->collect_totals);
1654 else if (strcasecmp("CollectUptime", child->key) == 0)
1655 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1656 cf_util_get_boolean(child, &conf->collect_uptime);
1658 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1659 child->key, "v3 and v4");
1661 else if (strcasecmp("CollectVCL", child->key) == 0)
1662 cf_util_get_boolean(child, &conf->collect_vcl);
1663 else if (strcasecmp("CollectWorkers", child->key) == 0)
1664 cf_util_get_boolean(child, &conf->collect_workers);
1665 else if (strcasecmp("CollectVSM", child->key) == 0)
1666 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1667 cf_util_get_boolean(child, &conf->collect_vsm);
1669 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1672 else if (strcasecmp("CollectLock", child->key) == 0)
1673 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1674 cf_util_get_boolean(child, &conf->collect_lck);
1676 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1679 else if (strcasecmp("CollectMempool", child->key) == 0)
1680 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1681 cf_util_get_boolean(child, &conf->collect_mempool);
1683 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1686 else if (strcasecmp("CollectManagement", child->key) == 0)
1687 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1688 cf_util_get_boolean(child, &conf->collect_mgt);
1690 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1693 else if (strcasecmp("CollectSMF", child->key) == 0)
1694 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1695 cf_util_get_boolean(child, &conf->collect_smf);
1697 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1700 else if (strcasecmp("CollectSMF", child->key) == 0)
1701 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1702 cf_util_get_boolean(child, &conf->collect_smf);
1704 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1707 else if (strcasecmp("CollectVBE", child->key) == 0)
1708 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1709 cf_util_get_boolean(child, &conf->collect_vbe);
1711 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1714 else if (strcasecmp("CollectMSE", child->key) == 0)
1715 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1716 cf_util_get_boolean(child, &conf->collect_mse);
1718 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1719 child->key, "Plus v4");
1722 WARNING("Varnish plugin: Ignoring unknown "
1723 "configuration option: \"%s\". Did "
1724 "you forget to add an <Instance /> "
1725 "block around the configuration?",
1730 if (!conf->collect_cache && !conf->collect_connections &&
1731 !conf->collect_esi && !conf->collect_backend
1732 #ifdef HAVE_VARNISH_V3
1733 && !conf->collect_dirdns
1735 && !conf->collect_fetch && !conf->collect_hcb && !conf->collect_objects
1737 && !conf->collect_purge
1739 && !conf->collect_ban
1741 && !conf->collect_session && !conf->collect_shm && !conf->collect_sms
1743 && !conf->collect_sm
1745 #if HAVE_VARNISH_V2 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1746 && !conf->collect_sma
1748 && !conf->collect_struct && !conf->collect_totals
1749 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1750 && !conf->collect_uptime
1752 && !conf->collect_vcl && !conf->collect_workers
1753 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1754 && !conf->collect_vsm && !conf->collect_vbe && !conf->collect_smf &&
1755 !conf->collect_mgt && !conf->collect_lck && !conf->collect_mempool &&
1759 WARNING("Varnish plugin: No metric has been configured for "
1760 "instance \"%s\". Disabling this instance.",
1761 (conf->instance == NULL) ? "localhost" : conf->instance);
1766 snprintf(callback_name, sizeof(callback_name), "varnish/%s",
1767 (conf->instance == NULL) ? "localhost" : conf->instance);
1769 plugin_register_complex_read(
1770 /* group = */ "varnish",
1771 /* name = */ callback_name,
1772 /* callback = */ varnish_read,
1775 .data = conf, .free_func = varnish_config_free,
1781 } /* }}} int varnish_config_instance */
1783 static int varnish_config(oconfig_item_t *ci) /* {{{ */
1785 for (int i = 0; i < ci->children_num; i++) {
1786 oconfig_item_t *child = ci->children + i;
1788 if (strcasecmp("Instance", child->key) == 0)
1789 varnish_config_instance(child);
1791 WARNING("Varnish plugin: Ignoring unknown "
1792 "configuration option: \"%s\"",
1798 } /* }}} int varnish_config */
1800 void module_register(void) /* {{{ */
1802 plugin_register_complex_config("varnish", varnish_config);
1803 plugin_register_init("varnish", varnish_init);