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);
467 if (conf->collect_session) {
468 if (strcmp(name, "sess_closed") == 0)
469 return varnish_submit_derive(conf->instance, "session",
470 "total_operations", "closed", val);
471 else if (strcmp(name, "sess_pipeline") == 0)
472 return varnish_submit_derive(conf->instance, "session",
473 "total_operations", "pipeline", val);
474 else if (strcmp(name, "sess_readahead") == 0)
475 return varnish_submit_derive(conf->instance, "session",
476 "total_operations", "readahead", val);
477 else if (strcmp(name, "sess_conn") == 0)
478 return varnish_submit_derive(conf->instance, "session",
479 "total_operations", "accepted", val);
480 else if (strcmp(name, "sess_drop") == 0)
481 return varnish_submit_derive(conf->instance, "session",
482 "total_operations", "dropped", val);
483 else if (strcmp(name, "sess_fail") == 0)
484 return varnish_submit_derive(conf->instance, "session",
485 "total_operations", "failed", val);
486 else if (strcmp(name, "sess_pipe_overflow") == 0)
487 return varnish_submit_derive(conf->instance, "session",
488 "total_operations", "overflow", val);
489 else if (strcmp(name, "sess_queued") == 0)
490 return varnish_submit_derive(conf->instance, "session",
491 "total_operations", "queued", val);
492 else if (strcmp(name, "sess_linger") == 0)
493 return varnish_submit_derive(conf->instance, "session",
494 "total_operations", "linger", val);
495 else if (strcmp(name, "sess_herd") == 0)
496 return varnish_submit_derive(conf->instance, "session",
497 "total_operations", "herd", val);
498 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
499 else if (strcmp(name, "sess_closed_err") == 0)
500 return varnish_submit_derive(conf->instance, "session",
501 "total_operations", "closed_err", val);
502 else if (strcmp(name, "sess_dropped") == 0)
503 return varnish_submit_derive(conf->instance, "session",
504 "total_operations", "dropped_for_thread", val);
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",
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",
745 "total_bytes", "bereq_hdrbytes", val);
746 else if (strcmp(name, "bereq_bodybytes") == 0)
747 return varnish_submit_derive(conf->instance, "vbe",
748 "total_bytes", "bereq_bodybytes", val);
749 else if (strcmp(name, "bereq_protobytes") == 0)
750 return varnish_submit_derive(conf->instance, "vbe",
751 "total_bytes", "bereq_protobytes", val);
752 else if (strcmp(name, "beresp_hdrbytes") == 0)
753 return varnish_submit_derive(conf->instance, "vbe",
754 "total_bytes", "beresp_hdrbytes", val);
755 else if (strcmp(name, "beresp_bodybytes") == 0)
756 return varnish_submit_derive(conf->instance, "vbe",
757 "total_bytes", "beresp_bodybytes", val);
758 else if (strcmp(name, "beresp_protobytes") == 0)
759 return varnish_submit_derive(conf->instance, "vbe",
760 "total_bytes", "beresp_protobytes", val);
761 else if (strcmp(name, "pipe_hdrbytes") == 0)
762 return varnish_submit_derive(conf->instance, "vbe",
763 "total_bytes", "pipe_hdrbytes", val);
764 else if (strcmp(name, "pipe_out") == 0)
765 return varnish_submit_derive(conf->instance, "vbe",
766 "total_bytes", "pipe_out", val);
767 else if (strcmp(name, "pipe_in") == 0)
768 return varnish_submit_derive(conf->instance, "vbe",
769 "total_bytes", "pipe_in", val);
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,
791 "total_operations", "alloc_req", val);
792 else if (strcmp(name, "c_fail") == 0)
793 return varnish_submit_derive(conf->instance, category,
794 "total_operations", "alloc_fail", val);
795 else if (strcmp(name, "c_bytes") == 0)
796 return varnish_submit_derive(conf->instance, category,
797 "total_bytes", "bytes_allocated", val);
798 else if (strcmp(name, "c_freed") == 0)
799 return varnish_submit_derive(conf->instance, category,
800 "total_bytes", "bytes_freed", val);
801 else if (strcmp(name, "g_alloc") == 0)
802 return varnish_submit_derive(conf->instance, category,
803 "total_operations", "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",
832 "total_operations", "child_start", val);
833 else if (strcmp(name, "child_exit") == 0)
834 return varnish_submit_derive(conf->instance, "mgt",
835 "total_operations", "child_exit", val);
836 else if (strcmp(name, "child_stop") == 0)
837 return varnish_submit_derive(conf->instance, "mgt",
838 "total_operations", "child_stop", val);
839 else if (strcmp(name, "child_died") == 0)
840 return varnish_submit_derive(conf->instance, "mgt",
841 "total_operations", "child_died", val);
842 else if (strcmp(name, "child_dump") == 0)
843 return varnish_submit_derive(conf->instance, "mgt",
844 "total_operations", "child_dump", val);
845 else if (strcmp(name, "child_panic") == 0)
846 return varnish_submit_derive(conf->instance, "mgt",
847 "total_operations", "child_panic", val);
850 if (conf->collect_lck) {
851 if (strcmp(name, "creat") == 0)
852 return varnish_submit_gauge(conf->instance, "lck", "objects",
854 else if (strcmp(name, "destroy") == 0)
855 return varnish_submit_gauge(conf->instance, "lck", "objects",
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",
883 "objects", "recycled", val);
884 else if (strcmp(name, "timeout") == 0)
885 return varnish_submit_gauge(conf->instance, "mempool",
886 "objects", "timed_out", val);
887 else if (strcmp(name, "toosmall") == 0)
888 return varnish_submit_gauge(conf->instance, "mempool",
889 "objects", "too_small", val);
890 else if (strcmp(name, "surplus") == 0)
891 return varnish_submit_gauge(conf->instance, "mempool",
892 "objects", "surplus", val);
893 else if (strcmp(name, "randry") == 0)
894 return varnish_submit_gauge(conf->instance, "mempool",
895 "objects", "ran_dry", val);
898 if (conf->collect_mse) {
899 if (strcmp(name, "c_full") == 0)
900 return varnish_submit_derive(conf->instance, "mse",
901 "total_operations", "full_allocs", val);
902 else if (strcmp(name, "c_truncated") == 0)
903 return varnish_submit_derive(conf->instance, "mse",
904 "total_operations", "truncated_allocs", val);
905 else if (strcmp(name, "c_expanded") == 0)
906 return varnish_submit_derive(conf->instance, "mse",
907 "total_operations", "expanded_allocs", val);
908 else if (strcmp(name, "c_failed") == 0)
909 return varnish_submit_derive(conf->instance, "mse",
910 "total_operations", "failed_allocs", val);
911 else if (strcmp(name, "c_bytes") == 0)
912 return varnish_submit_derive(conf->instance, "mse",
913 "total_bytes", "bytes_allocated", val);
914 else if (strcmp(name, "c_freed") == 0)
915 return varnish_submit_derive(conf->instance, "mse",
916 "total_bytes", "bytes_freed", val);
917 else if (strcmp(name, "g_fo_alloc") == 0)
918 return varnish_submit_derive(conf->instance, "mse",
919 "total_operations", "fo_allocs_outstanding", val);
920 else if (strcmp(name, "g_fo_bytes") == 0)
921 return varnish_submit_gauge(conf->instance, "mse",
922 "bytes", "fo_bytes_outstanding", val);
923 else if (strcmp(name, "g_membuf_alloc") == 0)
924 return varnish_submit_gauge(conf->instance, "mse",
925 "objects", "membufs_allocated", val);
926 else if (strcmp(name, "g_membuf_inuse") == 0)
927 return varnish_submit_gauge(conf->instance, "mse",
928 "objects", "membufs_inuse", val);
929 else if (strcmp(name, "g_bans_bytes") == 0)
930 return varnish_submit_gauge(conf->instance, "mse",
931 "bytes", "persisted_banspace_used", val);
932 else if (strcmp(name, "g_bans_space") == 0)
933 return varnish_submit_gauge(conf->instance, "mse",
934 "bytes", "persisted_banspace_available", val);
935 else if (strcmp(name, "g_bans_persisted") == 0)
936 return varnish_submit_derive(conf->instance, "mse",
937 "total_operations", "bans_persisted", val);
938 else if (strcmp(name, "g_bans_lost") == 0)
939 return varnish_submit_derive(conf->instance, "mse",
940 "total_operations", "bans_lost", val);
943 else if (strcmp(name, "g_journal_bytes") == 0)
944 return varnish_submit_gauge(conf->instance, "mse_reg",
945 "bytes", "journal_bytes_used", val);
946 else if (strcmp(name, "g_journal_space") == 0)
947 return varnish_submit_gauge(conf->instance, "mse_reg",
948 "bytes", "journal_bytes_free", val);
951 else if (strcmp(name, "g_bigspace") == 0)
952 return varnish_submit_gauge(conf->instance, "mse_segagg",
953 "bytes", "big_extents_bytes_available", val);
954 else if (strcmp(name, "g_extfree") == 0)
955 return varnish_submit_gauge(conf->instance, "mse_segagg",
956 "objects", "free_extents", val);
957 else if (strcmp(name, "g_sparenode") == 0)
958 return varnish_submit_gauge(conf->instance, "mse_segagg",
959 "objects", "spare_nodes_available", val);
960 else if (strcmp(name, "g_objnode") == 0)
961 return varnish_submit_gauge(conf->instance, "mse_segagg",
962 "objects", "object_nodes_in_use", val);
963 else if (strcmp(name, "g_extnode") == 0)
964 return varnish_submit_gauge(conf->instance, "mse_segagg",
965 "objects", "extent_nodes_in_use", val);
966 else if (strcmp(name, "g_bigextfree") == 0)
967 return varnish_submit_gauge(conf->instance, "mse_segagg",
968 "objects", "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);
994 } /* }}} static int varnish_monitor */
995 #else /* if HAVE_VARNISH_V2 */
996 static void varnish_monitor(const user_config_t *conf, /* {{{ */
997 const c_varnish_stats_t *stats) {
998 if (conf->collect_cache) {
1000 varnish_submit_derive(conf->instance, "cache", "cache_result", "hit",
1003 varnish_submit_derive(conf->instance, "cache", "cache_result", "miss",
1005 /* Cache hits for pass */
1006 varnish_submit_derive(conf->instance, "cache", "cache_result", "hitpass",
1007 stats->cache_hitpass);
1010 if (conf->collect_connections) {
1011 /* Client connections accepted */
1012 varnish_submit_derive(conf->instance, "connections", "connections",
1013 "accepted", stats->client_conn);
1014 /* Connection dropped, no sess */
1015 varnish_submit_derive(conf->instance, "connections", "connections",
1016 "dropped", stats->client_drop);
1017 /* Client requests received */
1018 varnish_submit_derive(conf->instance, "connections", "connections",
1019 "received", stats->client_req);
1022 if (conf->collect_esi) {
1023 /* ESI parse errors (unlock) */
1024 varnish_submit_derive(conf->instance, "esi", "total_operations", "error",
1026 /* Objects ESI parsed (unlock) */
1027 varnish_submit_derive(conf->instance, "esi", "total_operations", "parsed",
1031 if (conf->collect_backend) {
1032 /* Backend conn. success */
1033 varnish_submit_derive(conf->instance, "backend", "connections", "success",
1034 stats->backend_conn);
1035 /* Backend conn. not attempted */
1036 varnish_submit_derive(conf->instance, "backend", "connections",
1037 "not-attempted", stats->backend_unhealthy);
1038 /* Backend conn. too many */
1039 varnish_submit_derive(conf->instance, "backend", "connections", "too-many",
1040 stats->backend_busy);
1041 /* Backend conn. failures */
1042 varnish_submit_derive(conf->instance, "backend", "connections", "failures",
1043 stats->backend_fail);
1044 /* Backend conn. reuses */
1045 varnish_submit_derive(conf->instance, "backend", "connections", "reuses",
1046 stats->backend_reuse);
1047 /* Backend conn. was closed */
1048 varnish_submit_derive(conf->instance, "backend", "connections",
1049 "was-closed", stats->backend_toolate);
1050 /* Backend conn. recycles */
1051 varnish_submit_derive(conf->instance, "backend", "connections", "recycled",
1052 stats->backend_recycle);
1053 /* Backend conn. unused */
1054 varnish_submit_derive(conf->instance, "backend", "connections", "unused",
1055 stats->backend_unused);
1056 /* Backend requests mades */
1057 varnish_submit_derive(conf->instance, "backend", "http_requests",
1058 "requests", stats->backend_req);
1060 varnish_submit_gauge(conf->instance, "backend", "backends", "n_backends",
1064 if (conf->collect_fetch) {
1066 varnish_submit_derive(conf->instance, "fetch", "http_requests", "head",
1068 /* Fetch with length */
1069 varnish_submit_derive(conf->instance, "fetch", "http_requests", "length",
1070 stats->fetch_length);
1072 varnish_submit_derive(conf->instance, "fetch", "http_requests", "chunked",
1073 stats->fetch_chunked);
1075 varnish_submit_derive(conf->instance, "fetch", "http_requests", "eof",
1077 /* Fetch bad headers */
1078 varnish_submit_derive(conf->instance, "fetch", "http_requests",
1079 "bad_headers", stats->fetch_bad);
1080 /* Fetch wanted close */
1081 varnish_submit_derive(conf->instance, "fetch", "http_requests", "close",
1082 stats->fetch_close);
1083 /* Fetch pre HTTP/1.1 closed */
1084 varnish_submit_derive(conf->instance, "fetch", "http_requests", "oldhttp",
1085 stats->fetch_oldhttp);
1086 /* Fetch zero len */
1087 varnish_submit_derive(conf->instance, "fetch", "http_requests", "zero",
1090 varnish_submit_derive(conf->instance, "fetch", "http_requests", "failed",
1091 stats->fetch_failed);
1094 if (conf->collect_hcb) {
1095 /* HCB Lookups without lock */
1096 varnish_submit_derive(conf->instance, "hcb", "cache_operation",
1097 "lookup_nolock", stats->hcb_nolock);
1098 /* HCB Lookups with lock */
1099 varnish_submit_derive(conf->instance, "hcb", "cache_operation",
1100 "lookup_lock", stats->hcb_lock);
1102 varnish_submit_derive(conf->instance, "hcb", "cache_operation", "insert",
1106 if (conf->collect_objects) {
1107 /* N expired objects */
1108 varnish_submit_derive(conf->instance, "objects", "total_objects", "expired",
1110 /* N LRU nuked objects */
1111 varnish_submit_derive(conf->instance, "objects", "total_objects",
1112 "lru_nuked", stats->n_lru_nuked);
1113 /* N LRU saved objects */
1114 varnish_submit_derive(conf->instance, "objects", "total_objects",
1115 "lru_saved", stats->n_lru_saved);
1116 /* N LRU moved objects */
1117 varnish_submit_derive(conf->instance, "objects", "total_objects",
1118 "lru_moved", stats->n_lru_moved);
1119 /* N objects on deathrow */
1120 varnish_submit_derive(conf->instance, "objects", "total_objects",
1121 "deathrow", stats->n_deathrow);
1122 /* HTTP header overflows */
1123 varnish_submit_derive(conf->instance, "objects", "total_objects",
1124 "header_overflow", stats->losthdr);
1125 /* Objects sent with sendfile */
1126 varnish_submit_derive(conf->instance, "objects", "total_objects",
1127 "sent_sendfile", stats->n_objsendfile);
1128 /* Objects sent with write */
1129 varnish_submit_derive(conf->instance, "objects", "total_objects",
1130 "sent_write", stats->n_objwrite);
1131 /* Objects overflowing workspace */
1132 varnish_submit_derive(conf->instance, "objects", "total_objects",
1133 "workspace_overflow", stats->n_objoverflow);
1136 if (conf->collect_purge) {
1137 /* N total active purges */
1138 varnish_submit_derive(conf->instance, "purge", "total_operations", "total",
1140 /* N new purges added */
1141 varnish_submit_derive(conf->instance, "purge", "total_operations", "added",
1142 stats->n_purge_add);
1143 /* N old purges deleted */
1144 varnish_submit_derive(conf->instance, "purge", "total_operations",
1145 "deleted", stats->n_purge_retire);
1146 /* N objects tested */
1147 varnish_submit_derive(conf->instance, "purge", "total_operations",
1148 "objects_tested", stats->n_purge_obj_test);
1149 /* N regexps tested against */
1150 varnish_submit_derive(conf->instance, "purge", "total_operations",
1151 "regexps_tested", stats->n_purge_re_test);
1152 /* N duplicate purges removed */
1153 varnish_submit_derive(conf->instance, "purge", "total_operations",
1154 "duplicate", stats->n_purge_dups);
1157 if (conf->collect_session) {
1158 /* Session Closed */
1159 varnish_submit_derive(conf->instance, "session", "total_operations",
1160 "closed", stats->sess_closed);
1161 /* Session Pipeline */
1162 varnish_submit_derive(conf->instance, "session", "total_operations",
1163 "pipeline", stats->sess_pipeline);
1164 /* Session Read Ahead */
1165 varnish_submit_derive(conf->instance, "session", "total_operations",
1166 "readahead", stats->sess_readahead);
1167 /* Session Linger */
1168 varnish_submit_derive(conf->instance, "session", "total_operations",
1169 "linger", stats->sess_linger);
1171 varnish_submit_derive(conf->instance, "session", "total_operations", "herd",
1175 if (conf->collect_shm) {
1177 varnish_submit_derive(conf->instance, "shm", "total_operations", "records",
1178 stats->shm_records);
1180 varnish_submit_derive(conf->instance, "shm", "total_operations", "writes",
1182 /* SHM flushes due to overflow */
1183 varnish_submit_derive(conf->instance, "shm", "total_operations", "flushes",
1184 stats->shm_flushes);
1185 /* SHM MTX contention */
1186 varnish_submit_derive(conf->instance, "shm", "total_operations",
1187 "contention", stats->shm_cont);
1188 /* SHM cycles through buffer */
1189 varnish_submit_derive(conf->instance, "shm", "total_operations", "cycles",
1193 if (conf->collect_sm) {
1194 /* allocator requests */
1195 varnish_submit_derive(conf->instance, "sm", "total_requests", "nreq",
1197 /* outstanding allocations */
1198 varnish_submit_gauge(conf->instance, "sm", "requests", "outstanding",
1200 /* bytes allocated */
1201 varnish_submit_derive(conf->instance, "sm", "total_bytes", "allocated",
1204 varnish_submit_derive(conf->instance, "sm", "total_bytes", "free",
1208 if (conf->collect_sma) {
1209 /* SMA allocator requests */
1210 varnish_submit_derive(conf->instance, "sma", "total_requests", "nreq",
1212 /* SMA outstanding allocations */
1213 varnish_submit_gauge(conf->instance, "sma", "requests", "outstanding",
1215 /* SMA outstanding bytes */
1216 varnish_submit_gauge(conf->instance, "sma", "bytes", "outstanding",
1218 /* SMA bytes allocated */
1219 varnish_submit_derive(conf->instance, "sma", "total_bytes", "allocated",
1221 /* SMA bytes free */
1222 varnish_submit_derive(conf->instance, "sma", "total_bytes", "free",
1226 if (conf->collect_sms) {
1227 /* SMS allocator requests */
1228 varnish_submit_derive(conf->instance, "sms", "total_requests", "allocator",
1230 /* SMS outstanding allocations */
1231 varnish_submit_gauge(conf->instance, "sms", "requests", "outstanding",
1233 /* SMS outstanding bytes */
1234 varnish_submit_gauge(conf->instance, "sms", "bytes", "outstanding",
1236 /* SMS bytes allocated */
1237 varnish_submit_derive(conf->instance, "sms", "total_bytes", "allocated",
1239 /* SMS bytes freed */
1240 varnish_submit_derive(conf->instance, "sms", "total_bytes", "free",
1244 if (conf->collect_struct) {
1245 /* N struct sess_mem */
1246 varnish_submit_gauge(conf->instance, "struct", "current_sessions",
1247 "sess_mem", stats->n_sess_mem);
1249 varnish_submit_gauge(conf->instance, "struct", "current_sessions", "sess",
1251 /* N struct object */
1252 varnish_submit_gauge(conf->instance, "struct", "objects", "object",
1254 /* N struct objecthead */
1255 varnish_submit_gauge(conf->instance, "struct", "objects", "objecthead",
1256 stats->n_objecthead);
1258 varnish_submit_gauge(conf->instance, "struct", "objects", "smf",
1260 /* N small free smf */
1261 varnish_submit_gauge(conf->instance, "struct", "objects", "smf_frag",
1263 /* N large free smf */
1264 varnish_submit_gauge(conf->instance, "struct", "objects", "smf_large",
1265 stats->n_smf_large);
1266 /* N struct vbe_conn */
1267 varnish_submit_gauge(conf->instance, "struct", "objects", "vbe_conn",
1271 if (conf->collect_totals) {
1272 /* Total Sessions */
1273 varnish_submit_derive(conf->instance, "totals", "total_sessions",
1274 "sessions", stats->s_sess);
1275 /* Total Requests */
1276 varnish_submit_derive(conf->instance, "totals", "total_requests",
1277 "requests", stats->s_req);
1279 varnish_submit_derive(conf->instance, "totals", "total_operations", "pipe",
1282 varnish_submit_derive(conf->instance, "totals", "total_operations", "pass",
1285 varnish_submit_derive(conf->instance, "totals", "total_operations",
1286 "fetches", stats->s_fetch);
1287 /* Total header bytes */
1288 varnish_submit_derive(conf->instance, "totals", "total_bytes",
1289 "header-bytes", stats->s_hdrbytes);
1290 /* Total body byte */
1291 varnish_submit_derive(conf->instance, "totals", "total_bytes", "body-bytes",
1292 stats->s_bodybytes);
1295 if (conf->collect_vcl) {
1297 varnish_submit_gauge(conf->instance, "vcl", "vcl", "total_vcl",
1299 /* N vcl available */
1300 varnish_submit_gauge(conf->instance, "vcl", "vcl", "avail_vcl",
1301 stats->n_vcl_avail);
1302 /* N vcl discarded */
1303 varnish_submit_gauge(conf->instance, "vcl", "vcl", "discarded_vcl",
1304 stats->n_vcl_discard);
1307 if (conf->collect_workers) {
1308 /* worker threads */
1309 varnish_submit_gauge(conf->instance, "workers", "threads", "worker",
1311 /* worker threads created */
1312 varnish_submit_derive(conf->instance, "workers", "total_threads", "created",
1313 stats->n_wrk_create);
1314 /* worker threads not created */
1315 varnish_submit_derive(conf->instance, "workers", "total_threads", "failed",
1316 stats->n_wrk_failed);
1317 /* worker threads limited */
1318 varnish_submit_derive(conf->instance, "workers", "total_threads", "limited",
1320 /* dropped work requests */
1321 varnish_submit_derive(conf->instance, "workers", "total_threads", "dropped",
1323 /* queued work requests */
1324 varnish_submit_derive(conf->instance, "workers", "total_requests", "queued",
1325 stats->n_wrk_queue);
1326 /* overflowed work requests */
1327 varnish_submit_derive(conf->instance, "workers", "total_requests",
1328 "overflowed", stats->n_wrk_overflow);
1331 } /* }}} void varnish_monitor */
1334 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1335 static int varnish_read(user_data_t *ud) /* {{{ */
1337 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
1338 struct VSM_data *vd;
1340 const c_varnish_stats_t *stats;
1341 #elif HAVE_VARNISH_V5
1347 user_config_t *conf;
1349 if ((ud == NULL) || (ud->data == NULL))
1364 if (conf->instance != NULL) {
1367 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
1368 status = VSM_n_Arg(vd, conf->instance);
1369 #elif HAVE_VARNISH_V5
1370 status = VSM_Arg(vd, 'n', conf->instance);
1374 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
1376 #elif HAVE_VARNISH_V5
1377 VSC_Destroy(&vsc, vd);
1380 ERROR("varnish plugin: VSM_Arg (\"%s\") failed "
1382 conf->instance, status);
1388 ok = (VSC_Open(vd, /* diag = */ 1) == 0);
1389 #elif HAVE_VARNISH_V4
1390 ok = (VSM_Open(vd) == 0);
1392 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
1395 ERROR("varnish plugin: Unable to open connection.");
1401 stats = VSC_Main(vd);
1402 #elif HAVE_VARNISH_V4
1403 stats = VSC_Main(vd, NULL);
1405 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
1408 ERROR("varnish plugin: Unable to get statistics.");
1414 if (VSM_Attach(vd, STDERR_FILENO)) {
1415 ERROR("varnish plugin: Cannot attach to varnish. %s", VSM_Error(vd));
1416 VSC_Destroy(&vsc, vd);
1421 vsm_status = VSM_Status(vd);
1422 if (vsm_status & ~(VSM_MGT_RUNNING|VSM_WRK_RUNNING)) {
1423 ERROR("varnish plugin: Unable to get statistics.");
1424 VSC_Destroy(&vsc, vd);
1431 VSC_Iter(vd, varnish_monitor, conf);
1432 #elif HAVE_VARNISH_V4
1433 VSC_Iter(vd, NULL, varnish_monitor, conf);
1434 #elif HAVE_VARNISH_V5
1435 VSC_Iter(vsc, vd, varnish_monitor, conf);
1438 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
1440 #elif HAVE_VARNISH_V5
1441 VSC_Destroy(&vsc, vd);
1447 #else /* if HAVE_VARNISH_V2 */
1448 static int varnish_read(user_data_t *ud) /* {{{ */
1450 const c_varnish_stats_t *stats;
1452 user_config_t *conf;
1454 if ((ud == NULL) || (ud->data == NULL))
1459 stats = VSL_OpenStats(conf->instance);
1460 if (stats == NULL) {
1461 ERROR("Varnish plugin : unable to load statistics");
1466 varnish_monitor(conf, stats);
1472 static void varnish_config_free(void *ptr) /* {{{ */
1474 user_config_t *conf = ptr;
1479 sfree(conf->instance);
1483 static int varnish_config_apply_default(user_config_t *conf) /* {{{ */
1488 conf->collect_backend = 1;
1489 conf->collect_cache = 1;
1490 conf->collect_connections = 1;
1491 #ifdef HAVE_VARNISH_V3
1492 conf->collect_dirdns = 0;
1494 conf->collect_esi = 0;
1495 conf->collect_fetch = 0;
1496 conf->collect_hcb = 0;
1497 conf->collect_objects = 0;
1499 conf->collect_purge = 0;
1501 conf->collect_ban = 0;
1503 conf->collect_session = 0;
1504 conf->collect_shm = 1;
1506 conf->collect_sm = 0;
1508 #if HAVE_VARNISH_V2 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1509 conf->collect_sma = 0;
1511 conf->collect_sms = 0;
1512 conf->collect_struct = 0;
1513 conf->collect_totals = 0;
1514 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1515 conf->collect_uptime = 0;
1517 conf->collect_vcl = 0;
1518 conf->collect_workers = 0;
1519 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1520 conf->collect_vsm = 0;
1521 conf->collect_lck = 0;
1522 conf->collect_mempool = 0;
1523 conf->collect_mgt = 0;
1524 conf->collect_smf = 0;
1525 conf->collect_vbe = 0;
1526 conf->collect_mse = 0;
1530 } /* }}} int varnish_config_apply_default */
1532 static int varnish_init(void) /* {{{ */
1534 user_config_t *conf;
1539 conf = calloc(1, sizeof(*conf));
1543 /* Default settings: */
1544 conf->instance = NULL;
1546 varnish_config_apply_default(conf);
1548 plugin_register_complex_read(
1549 /* group = */ "varnish",
1550 /* name = */ "varnish/localhost",
1551 /* callback = */ varnish_read,
1554 .data = conf, .free_func = varnish_config_free,
1558 } /* }}} int varnish_init */
1560 static int varnish_config_instance(const oconfig_item_t *ci) /* {{{ */
1562 user_config_t *conf;
1563 char callback_name[DATA_MAX_NAME_LEN];
1565 conf = calloc(1, sizeof(*conf));
1568 conf->instance = NULL;
1570 varnish_config_apply_default(conf);
1572 if (ci->values_num == 1) {
1575 status = cf_util_get_string(ci, &conf->instance);
1580 assert(conf->instance != NULL);
1582 if (strcmp("localhost", conf->instance) == 0) {
1583 sfree(conf->instance);
1584 conf->instance = NULL;
1586 } else if (ci->values_num > 1) {
1587 WARNING("Varnish plugin: \"Instance\" blocks accept only "
1593 for (int i = 0; i < ci->children_num; i++) {
1594 oconfig_item_t *child = ci->children + i;
1596 if (strcasecmp("CollectCache", child->key) == 0)
1597 cf_util_get_boolean(child, &conf->collect_cache);
1598 else if (strcasecmp("CollectConnections", child->key) == 0)
1599 cf_util_get_boolean(child, &conf->collect_connections);
1600 else if (strcasecmp("CollectESI", child->key) == 0)
1601 cf_util_get_boolean(child, &conf->collect_esi);
1602 else if (strcasecmp("CollectDirectorDNS", child->key) == 0)
1603 #ifdef HAVE_VARNISH_V3
1604 cf_util_get_boolean(child, &conf->collect_dirdns);
1606 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1609 else if (strcasecmp("CollectBackend", child->key) == 0)
1610 cf_util_get_boolean(child, &conf->collect_backend);
1611 else if (strcasecmp("CollectFetch", child->key) == 0)
1612 cf_util_get_boolean(child, &conf->collect_fetch);
1613 else if (strcasecmp("CollectHCB", child->key) == 0)
1614 cf_util_get_boolean(child, &conf->collect_hcb);
1615 else if (strcasecmp("CollectObjects", child->key) == 0)
1616 cf_util_get_boolean(child, &conf->collect_objects);
1617 else if (strcasecmp("CollectPurge", child->key) == 0)
1619 cf_util_get_boolean(child, &conf->collect_purge);
1621 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1624 else if (strcasecmp("CollectBan", child->key) == 0)
1626 WARNING("Varnish plugin: \"%s\" is not available for Varnish %s.",
1629 cf_util_get_boolean(child, &conf->collect_ban);
1631 else if (strcasecmp("CollectSession", child->key) == 0)
1632 cf_util_get_boolean(child, &conf->collect_session);
1633 else if (strcasecmp("CollectSHM", child->key) == 0)
1634 cf_util_get_boolean(child, &conf->collect_shm);
1635 else if (strcasecmp("CollectSMS", child->key) == 0)
1636 cf_util_get_boolean(child, &conf->collect_sms);
1637 else if (strcasecmp("CollectSMA", child->key) == 0)
1638 #if HAVE_VARNISH_V2 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1639 cf_util_get_boolean(child, &conf->collect_sma);
1641 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1642 child->key, "v2 and v4");
1644 else if (strcasecmp("CollectSM", child->key) == 0)
1646 cf_util_get_boolean(child, &conf->collect_sm);
1648 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1651 else if (strcasecmp("CollectStruct", child->key) == 0)
1652 cf_util_get_boolean(child, &conf->collect_struct);
1653 else if (strcasecmp("CollectTotals", child->key) == 0)
1654 cf_util_get_boolean(child, &conf->collect_totals);
1655 else if (strcasecmp("CollectUptime", child->key) == 0)
1656 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1657 cf_util_get_boolean(child, &conf->collect_uptime);
1659 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1660 child->key, "v3 and v4");
1662 else if (strcasecmp("CollectVCL", child->key) == 0)
1663 cf_util_get_boolean(child, &conf->collect_vcl);
1664 else if (strcasecmp("CollectWorkers", child->key) == 0)
1665 cf_util_get_boolean(child, &conf->collect_workers);
1666 else if (strcasecmp("CollectVSM", child->key) == 0)
1667 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1668 cf_util_get_boolean(child, &conf->collect_vsm);
1670 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1673 else if (strcasecmp("CollectLock", child->key) == 0)
1674 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1675 cf_util_get_boolean(child, &conf->collect_lck);
1677 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1680 else if (strcasecmp("CollectMempool", child->key) == 0)
1681 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1682 cf_util_get_boolean(child, &conf->collect_mempool);
1684 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1687 else if (strcasecmp("CollectManagement", child->key) == 0)
1688 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1689 cf_util_get_boolean(child, &conf->collect_mgt);
1691 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1694 else if (strcasecmp("CollectSMF", child->key) == 0)
1695 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1696 cf_util_get_boolean(child, &conf->collect_smf);
1698 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1701 else if (strcasecmp("CollectSMF", child->key) == 0)
1702 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1703 cf_util_get_boolean(child, &conf->collect_smf);
1705 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1708 else if (strcasecmp("CollectVBE", child->key) == 0)
1709 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1710 cf_util_get_boolean(child, &conf->collect_vbe);
1712 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1715 else if (strcasecmp("CollectMSE", child->key) == 0)
1716 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1717 cf_util_get_boolean(child, &conf->collect_mse);
1719 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1720 child->key, "Plus v4");
1723 WARNING("Varnish plugin: Ignoring unknown "
1724 "configuration option: \"%s\". Did "
1725 "you forget to add an <Instance /> "
1726 "block around the configuration?",
1731 if (!conf->collect_cache && !conf->collect_connections &&
1732 !conf->collect_esi && !conf->collect_backend
1733 #ifdef HAVE_VARNISH_V3
1734 && !conf->collect_dirdns
1736 && !conf->collect_fetch && !conf->collect_hcb && !conf->collect_objects
1738 && !conf->collect_purge
1740 && !conf->collect_ban
1742 && !conf->collect_session && !conf->collect_shm && !conf->collect_sms
1744 && !conf->collect_sm
1746 #if HAVE_VARNISH_V2 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1747 && !conf->collect_sma
1749 && !conf->collect_struct && !conf->collect_totals
1750 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1751 && !conf->collect_uptime
1753 && !conf->collect_vcl && !conf->collect_workers
1754 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1755 && !conf->collect_vsm && !conf->collect_vbe && !conf->collect_smf
1756 && !conf->collect_mgt && !conf->collect_lck && !conf->collect_mempool
1757 && !conf->collect_mse
1760 WARNING("Varnish plugin: No metric has been configured for "
1761 "instance \"%s\". Disabling this instance.",
1762 (conf->instance == NULL) ? "localhost" : conf->instance);
1767 snprintf(callback_name, sizeof(callback_name), "varnish/%s",
1768 (conf->instance == NULL) ? "localhost" : conf->instance);
1770 plugin_register_complex_read(
1771 /* group = */ "varnish",
1772 /* name = */ callback_name,
1773 /* callback = */ varnish_read,
1776 .data = conf, .free_func = varnish_config_free,
1782 } /* }}} int varnish_config_instance */
1784 static int varnish_config(oconfig_item_t *ci) /* {{{ */
1786 for (int i = 0; i < ci->children_num; i++) {
1787 oconfig_item_t *child = ci->children + i;
1789 if (strcasecmp("Instance", child->key) == 0)
1790 varnish_config_instance(child);
1792 WARNING("Varnish plugin: Ignoring unknown "
1793 "configuration option: \"%s\"",
1799 } /* }}} int varnish_config */
1801 void module_register(void) /* {{{ */
1803 plugin_register_complex_config("varnish", varnish_config);
1804 plugin_register_init("varnish", varnish_init);