d105b025a62922f332a754403411f3d5e449956d
1 /**
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
6 *
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.
10 *
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.
15 *
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
19 *
20 * Authors:
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>
25 **/
27 #include "collectd.h"
29 #include "common.h"
30 #include "plugin.h"
32 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
33 #include <vapi/vsc.h>
34 #include <vapi/vsm.h>
35 typedef struct VSC_C_main c_varnish_stats_t;
36 #endif
38 #if HAVE_VARNISH_V3
39 #include <varnishapi.h>
40 #include <vsc.h>
41 typedef struct VSC_C_main c_varnish_stats_t;
42 #endif
44 #if HAVE_VARNISH_V2
45 #include <varnishapi.h>
46 typedef struct varnish_stats c_varnish_stats_t;
47 #endif
49 /* {{{ user_config_s */
50 struct user_config_s {
51 char *instance;
53 _Bool collect_cache;
54 _Bool collect_connections;
55 _Bool collect_esi;
56 _Bool collect_backend;
57 #ifdef HAVE_VARNISH_V3
58 _Bool collect_dirdns;
59 #endif
60 _Bool collect_fetch;
61 _Bool collect_hcb;
62 _Bool collect_objects;
63 #if HAVE_VARNISH_V2
64 _Bool collect_purge;
65 #else
66 _Bool collect_ban;
67 #endif
68 _Bool collect_session;
69 _Bool collect_shm;
70 _Bool collect_sms;
71 #if HAVE_VARNISH_V2
72 _Bool collect_sm;
73 #endif
74 #if HAVE_VARNISH_V2 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
75 _Bool collect_sma;
76 #endif
77 _Bool collect_struct;
78 _Bool collect_totals;
79 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
80 _Bool collect_uptime;
81 #endif
82 _Bool collect_vcl;
83 _Bool collect_workers;
84 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
85 _Bool collect_vsm;
86 _Bool collect_lck;
87 _Bool collect_mempool;
88 _Bool collect_mgt;
89 _Bool collect_smf;
90 _Bool collect_vbe;
91 _Bool collect_mse;
92 #endif
93 };
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;
103 vl.values = &value;
104 vl.values_len = 1;
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,
126 (value_t){
127 .gauge = (gauge_t)gauge_value,
128 });
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,
136 (value_t){
137 .derive = (derive_t)derive_value,
138 });
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) /* {{{ */
144 {
145 uint64_t val;
146 const user_config_t *conf;
147 const char *name;
149 if (pt == NULL)
150 return 0;
152 conf = priv;
154 #if HAVE_VARNISH_V5
155 char namebuff[100];
156 char *c;
158 c = rindex(pt->name, '.');
159 strcpy(namebuff, c + 1);
160 name = namebuff;
162 #elif HAVE_VARNISH_V4
163 if (strcmp(pt->section->fantom->type, "MAIN") != 0)
164 return 0;
166 name = pt->desc->name;
167 #elif HAVE_VARNISH_V3
168 if (strcmp(pt->class, "") != 0)
169 return 0;
171 name = pt->name;
172 #endif
174 val = *(const volatile uint64_t *)pt->ptr;
176 if (conf->collect_cache) {
177 if (strcmp(name, "cache_hit") == 0)
178 return varnish_submit_derive(conf->instance, "cache", "cache_result",
179 "hit", val);
180 else if (strcmp(name, "cache_miss") == 0)
181 return varnish_submit_derive(conf->instance, "cache", "cache_result",
182 "miss", val);
183 else if (strcmp(name, "cache_hitpass") == 0)
184 return varnish_submit_derive(conf->instance, "cache", "cache_result",
185 "hitpass", val);
186 }
188 if (conf->collect_connections) {
189 if (strcmp(name, "client_conn") == 0)
190 return varnish_submit_derive(conf->instance, "connections", "connections",
191 "accepted", val);
192 else if (strcmp(name, "client_drop") == 0)
193 return varnish_submit_derive(conf->instance, "connections", "connections",
194 "dropped", val);
195 else if (strcmp(name, "client_req") == 0)
196 return varnish_submit_derive(conf->instance, "connections", "connections",
197 "received", val);
198 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
199 else if (strcmp(name, "client_req_400") == 0)
200 return varnish_submit_derive(conf->instance, "connections", "connections",
201 "error_400", val);
202 else if (strcmp(name, "client_req_417") == 0)
203 return varnish_submit_derive(conf->instance, "connections", "connections",
204 "error_417", val);
205 #endif
206 }
208 #ifdef HAVE_VARNISH_V3
209 if (conf->collect_dirdns) {
210 if (strcmp(name, "dir_dns_lookups") == 0)
211 return varnish_submit_derive(conf->instance, "dirdns", "cache_operation",
212 "lookups", val);
213 else if (strcmp(name, "dir_dns_failed") == 0)
214 return varnish_submit_derive(conf->instance, "dirdns", "cache_result",
215 "failed", val);
216 else if (strcmp(name, "dir_dns_hit") == 0)
217 return varnish_submit_derive(conf->instance, "dirdns", "cache_result",
218 "hits", val);
219 else if (strcmp(name, "dir_dns_cache_full") == 0)
220 return varnish_submit_derive(conf->instance, "dirdns", "cache_result",
221 "cache_full", val);
222 }
223 #endif
225 if (conf->collect_esi) {
226 if (strcmp(name, "esi_errors") == 0)
227 return varnish_submit_derive(conf->instance, "esi", "total_operations",
228 "error", val);
229 else if (strcmp(name, "esi_parse") == 0)
230 return varnish_submit_derive(conf->instance, "esi", "total_operations",
231 "parsed", val);
232 else if (strcmp(name, "esi_warnings") == 0)
233 return varnish_submit_derive(conf->instance, "esi", "total_operations",
234 "warning", val);
235 else if (strcmp(name, "esi_maxdepth") == 0)
236 return varnish_submit_derive(conf->instance, "esi", "total_operations",
237 "max_depth", val);
238 }
240 if (conf->collect_backend) {
241 if (strcmp(name, "backend_conn") == 0)
242 return varnish_submit_derive(conf->instance, "backend", "connections",
243 "success", val);
244 else if (strcmp(name, "backend_unhealthy") == 0)
245 return varnish_submit_derive(conf->instance, "backend", "connections",
246 "not-attempted", val);
247 else if (strcmp(name, "backend_busy") == 0)
248 return varnish_submit_derive(conf->instance, "backend", "connections",
249 "too-many", val);
250 else if (strcmp(name, "backend_fail") == 0)
251 return varnish_submit_derive(conf->instance, "backend", "connections",
252 "failures", val);
253 else if (strcmp(name, "backend_reuse") == 0)
254 return varnish_submit_derive(conf->instance, "backend", "connections",
255 "reuses", val);
256 else if (strcmp(name, "backend_toolate") == 0)
257 return varnish_submit_derive(conf->instance, "backend", "connections",
258 "was-closed", val);
259 else if (strcmp(name, "backend_recycle") == 0)
260 return varnish_submit_derive(conf->instance, "backend", "connections",
261 "recycled", val);
262 else if (strcmp(name, "backend_unused") == 0)
263 return varnish_submit_derive(conf->instance, "backend", "connections",
264 "unused", val);
265 else if (strcmp(name, "backend_retry") == 0)
266 return varnish_submit_derive(conf->instance, "backend", "connections",
267 "retries", val);
268 else if (strcmp(name, "backend_req") == 0)
269 return varnish_submit_derive(conf->instance, "backend", "http_requests",
270 "requests", val);
271 else if (strcmp(name, "n_backend") == 0)
272 return varnish_submit_gauge(conf->instance, "backend", "backends",
273 "n_backends", val);
274 }
276 if (conf->collect_fetch) {
277 if (strcmp(name, "fetch_head") == 0)
278 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
279 "head", val);
280 else if (strcmp(name, "fetch_length") == 0)
281 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
282 "length", val);
283 else if (strcmp(name, "fetch_chunked") == 0)
284 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
285 "chunked", val);
286 else if (strcmp(name, "fetch_eof") == 0)
287 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
288 "eof", val);
289 else if (strcmp(name, "fetch_bad") == 0)
290 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
291 "bad_headers", val);
292 else if (strcmp(name, "fetch_close") == 0)
293 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
294 "close", val);
295 else if (strcmp(name, "fetch_oldhttp") == 0)
296 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
297 "oldhttp", val);
298 else if (strcmp(name, "fetch_zero") == 0)
299 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
300 "zero", val);
301 else if (strcmp(name, "fetch_failed") == 0)
302 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
303 "failed", val);
304 else if (strcmp(name, "fetch_1xx") == 0)
305 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
306 "no_body_1xx", val);
307 else if (strcmp(name, "fetch_204") == 0)
308 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
309 "no_body_204", val);
310 else if (strcmp(name, "fetch_304") == 0)
311 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
312 "no_body_304", val);
313 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
314 else if (strcmp(name, "fetch_no_thread") == 0)
315 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
316 "no_thread", val);
317 else if (strcmp(name, "fetch_none") == 0)
318 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
319 "none", val);
320 else if (strcmp(name, "busy_sleep") == 0)
321 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
322 "busy_sleep", val);
323 else if (strcmp(name, "busy_wakeup") == 0)
324 return varnish_submit_derive(conf->instance, "fetch", "http_requests",
325 "busy_wakeup", val);
326 #endif
327 }
329 if (conf->collect_hcb) {
330 if (strcmp(name, "hcb_nolock") == 0)
331 return varnish_submit_derive(conf->instance, "hcb", "cache_operation",
332 "lookup_nolock", val);
333 else if (strcmp(name, "hcb_lock") == 0)
334 return varnish_submit_derive(conf->instance, "hcb", "cache_operation",
335 "lookup_lock", val);
336 else if (strcmp(name, "hcb_insert") == 0)
337 return varnish_submit_derive(conf->instance, "hcb", "cache_operation",
338 "insert", val);
339 }
341 if (conf->collect_objects) {
342 if (strcmp(name, "n_expired") == 0)
343 return varnish_submit_derive(conf->instance, "objects", "total_objects",
344 "expired", val);
345 else if (strcmp(name, "n_lru_nuked") == 0)
346 return varnish_submit_derive(conf->instance, "objects", "total_objects",
347 "lru_nuked", val);
348 else if (strcmp(name, "n_lru_saved") == 0)
349 return varnish_submit_derive(conf->instance, "objects", "total_objects",
350 "lru_saved", val);
351 else if (strcmp(name, "n_lru_moved") == 0)
352 return varnish_submit_derive(conf->instance, "objects", "total_objects",
353 "lru_moved", val);
354 else if (strcmp(name, "n_deathrow") == 0)
355 return varnish_submit_derive(conf->instance, "objects", "total_objects",
356 "deathrow", val);
357 else if (strcmp(name, "losthdr") == 0)
358 return varnish_submit_derive(conf->instance, "objects", "total_objects",
359 "header_overflow", val);
360 else if (strcmp(name, "n_obj_purged") == 0)
361 return varnish_submit_derive(conf->instance, "objects", "total_objects",
362 "purged", val);
363 else if (strcmp(name, "n_objsendfile") == 0)
364 return varnish_submit_derive(conf->instance, "objects", "total_objects",
365 "sent_sendfile", val);
366 else if (strcmp(name, "n_objwrite") == 0)
367 return varnish_submit_derive(conf->instance, "objects", "total_objects",
368 "sent_write", val);
369 else if (strcmp(name, "n_objoverflow") == 0)
370 return varnish_submit_derive(conf->instance, "objects", "total_objects",
371 "workspace_overflow", val);
372 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
373 else if (strcmp(name, "exp_mailed") == 0)
374 return varnish_submit_gauge(conf->instance, "struct", "objects",
375 "exp_mailed", val);
376 else if (strcmp(name, "exp_received") == 0)
377 return varnish_submit_gauge(conf->instance, "struct", "objects",
378 "exp_received", val);
379 #endif
380 }
382 #if HAVE_VARNISH_V3
383 if (conf->collect_ban) {
384 if (strcmp(name, "n_ban") == 0)
385 return varnish_submit_derive(conf->instance, "ban", "total_operations",
386 "total", val);
387 else if (strcmp(name, "n_ban_add") == 0)
388 return varnish_submit_derive(conf->instance, "ban", "total_operations",
389 "added", val);
390 else if (strcmp(name, "n_ban_retire") == 0)
391 return varnish_submit_derive(conf->instance, "ban", "total_operations",
392 "deleted", val);
393 else if (strcmp(name, "n_ban_obj_test") == 0)
394 return varnish_submit_derive(conf->instance, "ban", "total_operations",
395 "objects_tested", val);
396 else if (strcmp(name, "n_ban_re_test") == 0)
397 return varnish_submit_derive(conf->instance, "ban", "total_operations",
398 "regexps_tested", val);
399 else if (strcmp(name, "n_ban_dups") == 0)
400 return varnish_submit_derive(conf->instance, "ban", "total_operations",
401 "duplicate", val);
402 }
403 #endif
404 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
405 if (conf->collect_ban) {
406 if (strcmp(name, "bans") == 0)
407 return varnish_submit_derive(conf->instance, "ban", "total_operations",
408 "total", val);
409 else if (strcmp(name, "bans_added") == 0)
410 return varnish_submit_derive(conf->instance, "ban", "total_operations",
411 "added", val);
412 else if (strcmp(name, "bans_obj") == 0)
413 return varnish_submit_derive(conf->instance, "ban", "total_operations",
414 "obj", val);
415 else if (strcmp(name, "bans_req") == 0)
416 return varnish_submit_derive(conf->instance, "ban", "total_operations",
417 "req", val);
418 else if (strcmp(name, "bans_completed") == 0)
419 return varnish_submit_derive(conf->instance, "ban", "total_operations",
420 "completed", val);
421 else if (strcmp(name, "bans_deleted") == 0)
422 return varnish_submit_derive(conf->instance, "ban", "total_operations",
423 "deleted", val);
424 else if (strcmp(name, "bans_tested") == 0)
425 return varnish_submit_derive(conf->instance, "ban", "total_operations",
426 "tested", val);
427 else if (strcmp(name, "bans_dups") == 0)
428 return varnish_submit_derive(conf->instance, "ban", "total_operations",
429 "duplicate", val);
430 else if (strcmp(name, "bans_tested") == 0)
431 return varnish_submit_derive(conf->instance, "ban", "total_operations",
432 "tested", val);
433 else if (strcmp(name, "bans_lurker_contention") == 0)
434 return varnish_submit_derive(conf->instance, "ban", "total_operations",
435 "lurker_contention", val);
436 else if (strcmp(name, "bans_lurker_obj_killed") == 0)
437 return varnish_submit_derive(conf->instance, "ban", "total_operations",
438 "lurker_obj_killed", val);
439 else if (strcmp(name, "bans_lurker_tested") == 0)
440 return varnish_submit_derive(conf->instance, "ban", "total_operations",
441 "lurker_tested", val);
442 else if (strcmp(name, "bans_lurker_tests_tested") == 0)
443 return varnish_submit_derive(conf->instance, "ban", "total_operations",
444 "lurker_tests_tested", val);
445 else if (strcmp(name, "bans_obj_killed") == 0)
446 return varnish_submit_derive(conf->instance, "ban", "total_operations",
447 "obj_killed", val);
448 else if (strcmp(name, "bans_persisted_bytes") == 0)
449 return varnish_submit_derive(conf->instance, "ban", "total_bytes",
450 "persisted_bytes", val);
451 else if (strcmp(name, "bans_persisted_fragmentation") == 0)
452 return varnish_submit_derive(conf->instance, "ban", "total_bytes",
453 "persisted_fragmentation", val);
454 else if (strcmp(name, "bans_tests_tested") == 0)
455 return varnish_submit_derive(conf->instance, "ban", "total_operations",
456 "tests_tested", val);
457 }
458 #endif
460 if (conf->collect_session) {
461 if (strcmp(name, "sess_closed") == 0)
462 return varnish_submit_derive(conf->instance, "session",
463 "total_operations", "closed", val);
464 else if (strcmp(name, "sess_pipeline") == 0)
465 return varnish_submit_derive(conf->instance, "session",
466 "total_operations", "pipeline", val);
467 else if (strcmp(name, "sess_readahead") == 0)
468 return varnish_submit_derive(conf->instance, "session",
469 "total_operations", "readahead", val);
470 else if (strcmp(name, "sess_conn") == 0)
471 return varnish_submit_derive(conf->instance, "session",
472 "total_operations", "accepted", val);
473 else if (strcmp(name, "sess_drop") == 0)
474 return varnish_submit_derive(conf->instance, "session",
475 "total_operations", "dropped", val);
476 else if (strcmp(name, "sess_fail") == 0)
477 return varnish_submit_derive(conf->instance, "session",
478 "total_operations", "failed", val);
479 else if (strcmp(name, "sess_pipe_overflow") == 0)
480 return varnish_submit_derive(conf->instance, "session",
481 "total_operations", "overflow", val);
482 else if (strcmp(name, "sess_queued") == 0)
483 return varnish_submit_derive(conf->instance, "session",
484 "total_operations", "queued", val);
485 else if (strcmp(name, "sess_linger") == 0)
486 return varnish_submit_derive(conf->instance, "session",
487 "total_operations", "linger", val);
488 else if (strcmp(name, "sess_herd") == 0)
489 return varnish_submit_derive(conf->instance, "session",
490 "total_operations", "herd", val);
491 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
492 else if (strcmp(name, "sess_closed_err") == 0)
493 return varnish_submit_derive(conf->instance, "session",
494 "total_operations", "closed_err", val);
495 else if (strcmp(name, "sess_dropped") == 0)
496 return varnish_submit_derive(conf->instance, "session",
497 "total_operations", "dropped_for_thread",
498 val);
499 #endif
500 }
502 if (conf->collect_shm) {
503 if (strcmp(name, "shm_records") == 0)
504 return varnish_submit_derive(conf->instance, "shm", "total_operations",
505 "records", val);
506 else if (strcmp(name, "shm_writes") == 0)
507 return varnish_submit_derive(conf->instance, "shm", "total_operations",
508 "writes", val);
509 else if (strcmp(name, "shm_flushes") == 0)
510 return varnish_submit_derive(conf->instance, "shm", "total_operations",
511 "flushes", val);
512 else if (strcmp(name, "shm_cont") == 0)
513 return varnish_submit_derive(conf->instance, "shm", "total_operations",
514 "contention", val);
515 else if (strcmp(name, "shm_cycles") == 0)
516 return varnish_submit_derive(conf->instance, "shm", "total_operations",
517 "cycles", val);
518 }
520 if (conf->collect_sms) {
521 if (strcmp(name, "sms_nreq") == 0)
522 return varnish_submit_derive(conf->instance, "sms", "total_requests",
523 "allocator", val);
524 else if (strcmp(name, "sms_nobj") == 0)
525 return varnish_submit_gauge(conf->instance, "sms", "requests",
526 "outstanding", val);
527 else if (strcmp(name, "sms_nbytes") == 0)
528 return varnish_submit_gauge(conf->instance, "sms", "bytes", "outstanding",
529 val);
530 else if (strcmp(name, "sms_balloc") == 0)
531 return varnish_submit_derive(conf->instance, "sms", "total_bytes",
532 "allocated", val);
533 else if (strcmp(name, "sms_bfree") == 0)
534 return varnish_submit_derive(conf->instance, "sms", "total_bytes", "free",
535 val);
536 }
538 if (conf->collect_struct) {
539 if (strcmp(name, "n_sess_mem") == 0)
540 return varnish_submit_gauge(conf->instance, "struct", "current_sessions",
541 "sess_mem", val);
542 else if (strcmp(name, "n_sess") == 0)
543 return varnish_submit_gauge(conf->instance, "struct", "current_sessions",
544 "sess", val);
545 else if (strcmp(name, "n_object") == 0)
546 return varnish_submit_gauge(conf->instance, "struct", "objects", "object",
547 val);
548 else if (strcmp(name, "n_vampireobject") == 0)
549 return varnish_submit_gauge(conf->instance, "struct", "objects",
550 "vampireobject", val);
551 else if (strcmp(name, "n_objectcore") == 0)
552 return varnish_submit_gauge(conf->instance, "struct", "objects",
553 "objectcore", val);
554 else if (strcmp(name, "n_waitinglist") == 0)
555 return varnish_submit_gauge(conf->instance, "struct", "objects",
556 "waitinglist", val);
557 else if (strcmp(name, "n_objecthead") == 0)
558 return varnish_submit_gauge(conf->instance, "struct", "objects",
559 "objecthead", val);
560 else if (strcmp(name, "n_smf") == 0)
561 return varnish_submit_gauge(conf->instance, "struct", "objects", "smf",
562 val);
563 else if (strcmp(name, "n_smf_frag") == 0)
564 return varnish_submit_gauge(conf->instance, "struct", "objects",
565 "smf_frag", val);
566 else if (strcmp(name, "n_smf_large") == 0)
567 return varnish_submit_gauge(conf->instance, "struct", "objects",
568 "smf_large", val);
569 else if (strcmp(name, "n_vbe_conn") == 0)
570 return varnish_submit_gauge(conf->instance, "struct", "objects",
571 "vbe_conn", val);
572 }
574 if (conf->collect_totals) {
575 if (strcmp(name, "s_sess") == 0)
576 return varnish_submit_derive(conf->instance, "totals", "total_sessions",
577 "sessions", val);
578 else if (strcmp(name, "s_req") == 0)
579 return varnish_submit_derive(conf->instance, "totals", "total_requests",
580 "requests", val);
581 else if (strcmp(name, "s_pipe") == 0)
582 return varnish_submit_derive(conf->instance, "totals", "total_operations",
583 "pipe", val);
584 else if (strcmp(name, "s_pass") == 0)
585 return varnish_submit_derive(conf->instance, "totals", "total_operations",
586 "pass", val);
587 else if (strcmp(name, "s_fetch") == 0)
588 return varnish_submit_derive(conf->instance, "totals", "total_operations",
589 "fetches", val);
590 else if (strcmp(name, "s_synth") == 0)
591 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
592 "synth", val);
593 else if (strcmp(name, "s_req_hdrbytes") == 0)
594 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
595 "req_header", val);
596 else if (strcmp(name, "s_req_bodybytes") == 0)
597 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
598 "req_body", val);
599 else if (strcmp(name, "s_req_protobytes") == 0)
600 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
601 "req_proto", val);
602 else if (strcmp(name, "s_resp_hdrbytes") == 0)
603 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
604 "resp_header", val);
605 else if (strcmp(name, "s_resp_bodybytes") == 0)
606 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
607 "resp_body", val);
608 else if (strcmp(name, "s_resp_protobytes") == 0)
609 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
610 "resp_proto", val);
611 else if (strcmp(name, "s_pipe_hdrbytes") == 0)
612 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
613 "pipe_header", val);
614 else if (strcmp(name, "s_pipe_in") == 0)
615 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
616 "pipe_in", val);
617 else if (strcmp(name, "s_pipe_out") == 0)
618 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
619 "pipe_out", val);
620 else if (strcmp(name, "n_purges") == 0)
621 return varnish_submit_derive(conf->instance, "totals", "total_operations",
622 "purges", val);
623 else if (strcmp(name, "s_hdrbytes") == 0)
624 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
625 "header-bytes", val);
626 else if (strcmp(name, "s_bodybytes") == 0)
627 return varnish_submit_derive(conf->instance, "totals", "total_bytes",
628 "body-bytes", val);
629 else if (strcmp(name, "n_gzip") == 0)
630 return varnish_submit_derive(conf->instance, "totals", "total_operations",
631 "gzip", val);
632 else if (strcmp(name, "n_gunzip") == 0)
633 return varnish_submit_derive(conf->instance, "totals", "total_operations",
634 "gunzip", val);
635 }
637 if (conf->collect_uptime) {
638 if (strcmp(name, "uptime") == 0)
639 return varnish_submit_gauge(conf->instance, "uptime", "uptime",
640 "client_uptime", val);
641 }
643 if (conf->collect_vcl) {
644 if (strcmp(name, "n_vcl") == 0)
645 return varnish_submit_gauge(conf->instance, "vcl", "vcl", "total_vcl",
646 val);
647 else if (strcmp(name, "n_vcl_avail") == 0)
648 return varnish_submit_gauge(conf->instance, "vcl", "vcl", "avail_vcl",
649 val);
650 else if (strcmp(name, "n_vcl_discard") == 0)
651 return varnish_submit_gauge(conf->instance, "vcl", "vcl", "discarded_vcl",
652 val);
653 else if (strcmp(name, "vmods") == 0)
654 return varnish_submit_gauge(conf->instance, "vcl", "objects", "vmod",
655 val);
656 }
658 if (conf->collect_workers) {
659 if (strcmp(name, "threads") == 0)
660 return varnish_submit_gauge(conf->instance, "workers", "threads",
661 "worker", val);
662 else if (strcmp(name, "threads_created") == 0)
663 return varnish_submit_derive(conf->instance, "workers", "total_threads",
664 "created", val);
665 else if (strcmp(name, "threads_failed") == 0)
666 return varnish_submit_derive(conf->instance, "workers", "total_threads",
667 "failed", val);
668 else if (strcmp(name, "threads_limited") == 0)
669 return varnish_submit_derive(conf->instance, "workers", "total_threads",
670 "limited", val);
671 else if (strcmp(name, "threads_destroyed") == 0)
672 return varnish_submit_derive(conf->instance, "workers", "total_threads",
673 "dropped", val);
674 else if (strcmp(name, "thread_queue_len") == 0)
675 return varnish_submit_gauge(conf->instance, "workers", "queue_length",
676 "threads", val);
677 else if (strcmp(name, "n_wrk") == 0)
678 return varnish_submit_gauge(conf->instance, "workers", "threads",
679 "worker", val);
680 else if (strcmp(name, "n_wrk_create") == 0)
681 return varnish_submit_derive(conf->instance, "workers", "total_threads",
682 "created", val);
683 else if (strcmp(name, "n_wrk_failed") == 0)
684 return varnish_submit_derive(conf->instance, "workers", "total_threads",
685 "failed", val);
686 else if (strcmp(name, "n_wrk_max") == 0)
687 return varnish_submit_derive(conf->instance, "workers", "total_threads",
688 "limited", val);
689 else if (strcmp(name, "n_wrk_drop") == 0)
690 return varnish_submit_derive(conf->instance, "workers", "total_threads",
691 "dropped", val);
692 else if (strcmp(name, "n_wrk_queue") == 0)
693 return varnish_submit_derive(conf->instance, "workers", "total_requests",
694 "queued", val);
695 else if (strcmp(name, "n_wrk_overflow") == 0)
696 return varnish_submit_derive(conf->instance, "workers", "total_requests",
697 "overflowed", val);
698 else if (strcmp(name, "n_wrk_queued") == 0)
699 return varnish_submit_derive(conf->instance, "workers", "total_requests",
700 "queued", val);
701 else if (strcmp(name, "n_wrk_lqueue") == 0)
702 return varnish_submit_derive(conf->instance, "workers", "total_requests",
703 "queue_length", val);
704 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
705 else if (strcmp(name, "pools") == 0)
706 return varnish_submit_gauge(conf->instance, "workers", "pools", "pools",
707 val);
708 else if (strcmp(name, "busy_killed") == 0)
709 return varnish_submit_derive(conf->instance, "workers", "http_requests",
710 "busy_killed", val);
711 #endif
712 }
714 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
715 if (conf->collect_vsm) {
716 if (strcmp(name, "vsm_free") == 0)
717 return varnish_submit_gauge(conf->instance, "vsm", "bytes", "free", val);
718 else if (strcmp(name, "vsm_used") == 0)
719 return varnish_submit_gauge(conf->instance, "vsm", "bytes", "used", val);
720 else if (strcmp(name, "vsm_cooling") == 0)
721 return varnish_submit_gauge(conf->instance, "vsm", "bytes", "cooling",
722 val);
723 else if (strcmp(name, "vsm_overflow") == 0)
724 return varnish_submit_gauge(conf->instance, "vsm", "bytes", "overflow",
725 val);
726 else if (strcmp(name, "vsm_overflowed") == 0)
727 return varnish_submit_derive(conf->instance, "vsm", "total_bytes",
728 "overflowed", val);
729 }
731 if (conf->collect_vbe) {
732 /* @TODO figure out the collectd type for bitmap
733 if (strcmp(name, "happy") == 0)
734 return varnish_submit_derive(conf->instance, "vbe",
735 "bitmap", "happy_hprobes", val);
736 */
737 if (strcmp(name, "bereq_hdrbytes") == 0)
738 return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
739 "bereq_hdrbytes", val);
740 else if (strcmp(name, "bereq_bodybytes") == 0)
741 return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
742 "bereq_bodybytes", val);
743 else if (strcmp(name, "bereq_protobytes") == 0)
744 return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
745 "bereq_protobytes", val);
746 else if (strcmp(name, "beresp_hdrbytes") == 0)
747 return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
748 "beresp_hdrbytes", val);
749 else if (strcmp(name, "beresp_bodybytes") == 0)
750 return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
751 "beresp_bodybytes", val);
752 else if (strcmp(name, "beresp_protobytes") == 0)
753 return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
754 "beresp_protobytes", val);
755 else if (strcmp(name, "pipe_hdrbytes") == 0)
756 return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
757 "pipe_hdrbytes", val);
758 else if (strcmp(name, "pipe_out") == 0)
759 return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
760 "pipe_out", val);
761 else if (strcmp(name, "pipe_in") == 0)
762 return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
763 "pipe_in", val);
764 else if (strcmp(name, "conn") == 0)
765 return varnish_submit_derive(conf->instance, "vbe", "connections",
766 "c_conns", val);
767 else if (strcmp(name, "req") == 0)
768 return varnish_submit_derive(conf->instance, "vbe", "http_requests",
769 "b_reqs", val);
770 }
772 /* All Stevedores support these counters */
773 if (conf->collect_sma || conf->collect_smf || conf->collect_mse) {
775 char category[4];
776 if (conf->collect_sma)
777 strncpy(category, "sma", 4);
778 else if (conf->collect_smf)
779 strncpy(category, "smf", 4);
780 else
781 strncpy(category, "mse", 4);
783 if (strcmp(name, "c_req") == 0)
784 return varnish_submit_derive(conf->instance, category, "total_operations",
785 "alloc_req", val);
786 else if (strcmp(name, "c_fail") == 0)
787 return varnish_submit_derive(conf->instance, category, "total_operations",
788 "alloc_fail", val);
789 else if (strcmp(name, "c_bytes") == 0)
790 return varnish_submit_derive(conf->instance, category, "total_bytes",
791 "bytes_allocated", val);
792 else if (strcmp(name, "c_freed") == 0)
793 return varnish_submit_derive(conf->instance, category, "total_bytes",
794 "bytes_freed", val);
795 else if (strcmp(name, "g_alloc") == 0)
796 return varnish_submit_derive(conf->instance, category, "total_operations",
797 "alloc_outstanding", val);
798 else if (strcmp(name, "g_bytes") == 0)
799 return varnish_submit_gauge(conf->instance, category, "bytes",
800 "bytes_outstanding", val);
801 else if (strcmp(name, "g_space") == 0)
802 return varnish_submit_gauge(conf->instance, category, "bytes",
803 "bytes_available", val);
804 }
806 /* No SMA specific counters */
808 if (conf->collect_smf) {
809 if (strcmp(name, "g_smf") == 0)
810 return varnish_submit_gauge(conf->instance, "smf", "objects",
811 "n_struct_smf", val);
812 else if (strcmp(name, "g_smf_frag") == 0)
813 return varnish_submit_gauge(conf->instance, "smf", "objects",
814 "n_small_free_smf", val);
815 else if (strcmp(name, "g_smf_large") == 0)
816 return varnish_submit_gauge(conf->instance, "smf", "objects",
817 "n_large_free_smf", val);
818 }
820 if (conf->collect_mgt) {
821 if (strcmp(name, "uptime") == 0)
822 return varnish_submit_gauge(conf->instance, "mgt", "uptime",
823 "mgt_proc_uptime", val);
824 else if (strcmp(name, "child_start") == 0)
825 return varnish_submit_derive(conf->instance, "mgt", "total_operations",
826 "child_start", val);
827 else if (strcmp(name, "child_exit") == 0)
828 return varnish_submit_derive(conf->instance, "mgt", "total_operations",
829 "child_exit", val);
830 else if (strcmp(name, "child_stop") == 0)
831 return varnish_submit_derive(conf->instance, "mgt", "total_operations",
832 "child_stop", val);
833 else if (strcmp(name, "child_died") == 0)
834 return varnish_submit_derive(conf->instance, "mgt", "total_operations",
835 "child_died", val);
836 else if (strcmp(name, "child_dump") == 0)
837 return varnish_submit_derive(conf->instance, "mgt", "total_operations",
838 "child_dump", val);
839 else if (strcmp(name, "child_panic") == 0)
840 return varnish_submit_derive(conf->instance, "mgt", "total_operations",
841 "child_panic", val);
842 }
844 if (conf->collect_lck) {
845 if (strcmp(name, "creat") == 0)
846 return varnish_submit_gauge(conf->instance, "lck", "objects", "created",
847 val);
848 else if (strcmp(name, "destroy") == 0)
849 return varnish_submit_gauge(conf->instance, "lck", "objects", "destroyed",
850 val);
851 else if (strcmp(name, "locks") == 0)
852 return varnish_submit_derive(conf->instance, "lck", "total_operations",
853 "lock_ops", val);
854 }
856 if (conf->collect_mempool) {
857 if (strcmp(name, "live") == 0)
858 return varnish_submit_gauge(conf->instance, "mempool", "objects",
859 "in_use", val);
860 else if (strcmp(name, "pool") == 0)
861 return varnish_submit_gauge(conf->instance, "mempool", "objects",
862 "in_pool", val);
863 else if (strcmp(name, "sz_wanted") == 0)
864 return varnish_submit_gauge(conf->instance, "mempool", "bytes",
865 "size_requested", val);
866 else if (strcmp(name, "sz_actual") == 0)
867 return varnish_submit_gauge(conf->instance, "mempool", "bytes",
868 "size_allocated", val);
869 else if (strcmp(name, "allocs") == 0)
870 return varnish_submit_derive(conf->instance, "mempool",
871 "total_operations", "allocations", val);
872 else if (strcmp(name, "frees") == 0)
873 return varnish_submit_derive(conf->instance, "mempool",
874 "total_operations", "frees", val);
875 else if (strcmp(name, "recycle") == 0)
876 return varnish_submit_gauge(conf->instance, "mempool", "objects",
877 "recycled", val);
878 else if (strcmp(name, "timeout") == 0)
879 return varnish_submit_gauge(conf->instance, "mempool", "objects",
880 "timed_out", val);
881 else if (strcmp(name, "toosmall") == 0)
882 return varnish_submit_gauge(conf->instance, "mempool", "objects",
883 "too_small", val);
884 else if (strcmp(name, "surplus") == 0)
885 return varnish_submit_gauge(conf->instance, "mempool", "objects",
886 "surplus", val);
887 else if (strcmp(name, "randry") == 0)
888 return varnish_submit_gauge(conf->instance, "mempool", "objects",
889 "ran_dry", val);
890 }
892 if (conf->collect_mse) {
893 if (strcmp(name, "c_full") == 0)
894 return varnish_submit_derive(conf->instance, "mse", "total_operations",
895 "full_allocs", val);
896 else if (strcmp(name, "c_truncated") == 0)
897 return varnish_submit_derive(conf->instance, "mse", "total_operations",
898 "truncated_allocs", val);
899 else if (strcmp(name, "c_expanded") == 0)
900 return varnish_submit_derive(conf->instance, "mse", "total_operations",
901 "expanded_allocs", val);
902 else if (strcmp(name, "c_failed") == 0)
903 return varnish_submit_derive(conf->instance, "mse", "total_operations",
904 "failed_allocs", val);
905 else if (strcmp(name, "c_bytes") == 0)
906 return varnish_submit_derive(conf->instance, "mse", "total_bytes",
907 "bytes_allocated", val);
908 else if (strcmp(name, "c_freed") == 0)
909 return varnish_submit_derive(conf->instance, "mse", "total_bytes",
910 "bytes_freed", val);
911 else if (strcmp(name, "g_fo_alloc") == 0)
912 return varnish_submit_derive(conf->instance, "mse", "total_operations",
913 "fo_allocs_outstanding", val);
914 else if (strcmp(name, "g_fo_bytes") == 0)
915 return varnish_submit_gauge(conf->instance, "mse", "bytes",
916 "fo_bytes_outstanding", val);
917 else if (strcmp(name, "g_membuf_alloc") == 0)
918 return varnish_submit_gauge(conf->instance, "mse", "objects",
919 "membufs_allocated", val);
920 else if (strcmp(name, "g_membuf_inuse") == 0)
921 return varnish_submit_gauge(conf->instance, "mse", "objects",
922 "membufs_inuse", val);
923 else if (strcmp(name, "g_bans_bytes") == 0)
924 return varnish_submit_gauge(conf->instance, "mse", "bytes",
925 "persisted_banspace_used", val);
926 else if (strcmp(name, "g_bans_space") == 0)
927 return varnish_submit_gauge(conf->instance, "mse", "bytes",
928 "persisted_banspace_available", val);
929 else if (strcmp(name, "g_bans_persisted") == 0)
930 return varnish_submit_derive(conf->instance, "mse", "total_operations",
931 "bans_persisted", val);
932 else if (strcmp(name, "g_bans_lost") == 0)
933 return varnish_submit_derive(conf->instance, "mse", "total_operations",
934 "bans_lost", val);
936 /* mse seg */
937 else if (strcmp(name, "g_journal_bytes") == 0)
938 return varnish_submit_gauge(conf->instance, "mse_reg", "bytes",
939 "journal_bytes_used", val);
940 else if (strcmp(name, "g_journal_space") == 0)
941 return varnish_submit_gauge(conf->instance, "mse_reg", "bytes",
942 "journal_bytes_free", val);
944 /* mse segagg */
945 else if (strcmp(name, "g_bigspace") == 0)
946 return varnish_submit_gauge(conf->instance, "mse_segagg", "bytes",
947 "big_extents_bytes_available", val);
948 else if (strcmp(name, "g_extfree") == 0)
949 return varnish_submit_gauge(conf->instance, "mse_segagg", "objects",
950 "free_extents", val);
951 else if (strcmp(name, "g_sparenode") == 0)
952 return varnish_submit_gauge(conf->instance, "mse_segagg", "objects",
953 "spare_nodes_available", val);
954 else if (strcmp(name, "g_objnode") == 0)
955 return varnish_submit_gauge(conf->instance, "mse_segagg", "objects",
956 "object_nodes_in_use", val);
957 else if (strcmp(name, "g_extnode") == 0)
958 return varnish_submit_gauge(conf->instance, "mse_segagg", "objects",
959 "extent_nodes_in_use", val);
960 else if (strcmp(name, "g_bigextfree") == 0)
961 return varnish_submit_gauge(conf->instance, "mse_segagg", "objects",
962 "free_big_extents", val);
963 else if (strcmp(name, "c_pruneloop") == 0)
964 return varnish_submit_derive(conf->instance, "mse_segagg",
965 "total_operations", "prune_loops", val);
966 else if (strcmp(name, "c_pruned") == 0)
967 return varnish_submit_derive(conf->instance, "mse_segagg",
968 "total_objects", "pruned_objects", val);
969 else if (strcmp(name, "c_spared") == 0)
970 return varnish_submit_derive(conf->instance, "mse_segagg",
971 "total_operations", "spared_objects", val);
972 else if (strcmp(name, "c_skipped") == 0)
973 return varnish_submit_derive(conf->instance, "mse_segagg",
974 "total_operations", "missed_objects", val);
975 else if (strcmp(name, "c_nuked") == 0)
976 return varnish_submit_derive(conf->instance, "mse_segagg",
977 "total_operations", "nuked_objects", val);
978 else if (strcmp(name, "c_sniped") == 0)
979 return varnish_submit_derive(conf->instance, "mse_segagg",
980 "total_operations", "sniped_objects", val);
981 }
983 #endif
985 return 0;
987 } /* }}} static int varnish_monitor */
988 #else /* if HAVE_VARNISH_V2 */
989 static void varnish_monitor(const user_config_t *conf, /* {{{ */
990 const c_varnish_stats_t *stats) {
991 if (conf->collect_cache) {
992 /* Cache hits */
993 varnish_submit_derive(conf->instance, "cache", "cache_result", "hit",
994 stats->cache_hit);
995 /* Cache misses */
996 varnish_submit_derive(conf->instance, "cache", "cache_result", "miss",
997 stats->cache_miss);
998 /* Cache hits for pass */
999 varnish_submit_derive(conf->instance, "cache", "cache_result", "hitpass",
1000 stats->cache_hitpass);
1001 }
1003 if (conf->collect_connections) {
1004 /* Client connections accepted */
1005 varnish_submit_derive(conf->instance, "connections", "connections",
1006 "accepted", stats->client_conn);
1007 /* Connection dropped, no sess */
1008 varnish_submit_derive(conf->instance, "connections", "connections",
1009 "dropped", stats->client_drop);
1010 /* Client requests received */
1011 varnish_submit_derive(conf->instance, "connections", "connections",
1012 "received", stats->client_req);
1013 }
1015 if (conf->collect_esi) {
1016 /* ESI parse errors (unlock) */
1017 varnish_submit_derive(conf->instance, "esi", "total_operations", "error",
1018 stats->esi_errors);
1019 /* Objects ESI parsed (unlock) */
1020 varnish_submit_derive(conf->instance, "esi", "total_operations", "parsed",
1021 stats->esi_parse);
1022 }
1024 if (conf->collect_backend) {
1025 /* Backend conn. success */
1026 varnish_submit_derive(conf->instance, "backend", "connections", "success",
1027 stats->backend_conn);
1028 /* Backend conn. not attempted */
1029 varnish_submit_derive(conf->instance, "backend", "connections",
1030 "not-attempted", stats->backend_unhealthy);
1031 /* Backend conn. too many */
1032 varnish_submit_derive(conf->instance, "backend", "connections", "too-many",
1033 stats->backend_busy);
1034 /* Backend conn. failures */
1035 varnish_submit_derive(conf->instance, "backend", "connections", "failures",
1036 stats->backend_fail);
1037 /* Backend conn. reuses */
1038 varnish_submit_derive(conf->instance, "backend", "connections", "reuses",
1039 stats->backend_reuse);
1040 /* Backend conn. was closed */
1041 varnish_submit_derive(conf->instance, "backend", "connections",
1042 "was-closed", stats->backend_toolate);
1043 /* Backend conn. recycles */
1044 varnish_submit_derive(conf->instance, "backend", "connections", "recycled",
1045 stats->backend_recycle);
1046 /* Backend conn. unused */
1047 varnish_submit_derive(conf->instance, "backend", "connections", "unused",
1048 stats->backend_unused);
1049 /* Backend requests mades */
1050 varnish_submit_derive(conf->instance, "backend", "http_requests",
1051 "requests", stats->backend_req);
1052 /* N backends */
1053 varnish_submit_gauge(conf->instance, "backend", "backends", "n_backends",
1054 stats->n_backend);
1055 }
1057 if (conf->collect_fetch) {
1058 /* Fetch head */
1059 varnish_submit_derive(conf->instance, "fetch", "http_requests", "head",
1060 stats->fetch_head);
1061 /* Fetch with length */
1062 varnish_submit_derive(conf->instance, "fetch", "http_requests", "length",
1063 stats->fetch_length);
1064 /* Fetch chunked */
1065 varnish_submit_derive(conf->instance, "fetch", "http_requests", "chunked",
1066 stats->fetch_chunked);
1067 /* Fetch EOF */
1068 varnish_submit_derive(conf->instance, "fetch", "http_requests", "eof",
1069 stats->fetch_eof);
1070 /* Fetch bad headers */
1071 varnish_submit_derive(conf->instance, "fetch", "http_requests",
1072 "bad_headers", stats->fetch_bad);
1073 /* Fetch wanted close */
1074 varnish_submit_derive(conf->instance, "fetch", "http_requests", "close",
1075 stats->fetch_close);
1076 /* Fetch pre HTTP/1.1 closed */
1077 varnish_submit_derive(conf->instance, "fetch", "http_requests", "oldhttp",
1078 stats->fetch_oldhttp);
1079 /* Fetch zero len */
1080 varnish_submit_derive(conf->instance, "fetch", "http_requests", "zero",
1081 stats->fetch_zero);
1082 /* Fetch failed */
1083 varnish_submit_derive(conf->instance, "fetch", "http_requests", "failed",
1084 stats->fetch_failed);
1085 }
1087 if (conf->collect_hcb) {
1088 /* HCB Lookups without lock */
1089 varnish_submit_derive(conf->instance, "hcb", "cache_operation",
1090 "lookup_nolock", stats->hcb_nolock);
1091 /* HCB Lookups with lock */
1092 varnish_submit_derive(conf->instance, "hcb", "cache_operation",
1093 "lookup_lock", stats->hcb_lock);
1094 /* HCB Inserts */
1095 varnish_submit_derive(conf->instance, "hcb", "cache_operation", "insert",
1096 stats->hcb_insert);
1097 }
1099 if (conf->collect_objects) {
1100 /* N expired objects */
1101 varnish_submit_derive(conf->instance, "objects", "total_objects", "expired",
1102 stats->n_expired);
1103 /* N LRU nuked objects */
1104 varnish_submit_derive(conf->instance, "objects", "total_objects",
1105 "lru_nuked", stats->n_lru_nuked);
1106 /* N LRU saved objects */
1107 varnish_submit_derive(conf->instance, "objects", "total_objects",
1108 "lru_saved", stats->n_lru_saved);
1109 /* N LRU moved objects */
1110 varnish_submit_derive(conf->instance, "objects", "total_objects",
1111 "lru_moved", stats->n_lru_moved);
1112 /* N objects on deathrow */
1113 varnish_submit_derive(conf->instance, "objects", "total_objects",
1114 "deathrow", stats->n_deathrow);
1115 /* HTTP header overflows */
1116 varnish_submit_derive(conf->instance, "objects", "total_objects",
1117 "header_overflow", stats->losthdr);
1118 /* Objects sent with sendfile */
1119 varnish_submit_derive(conf->instance, "objects", "total_objects",
1120 "sent_sendfile", stats->n_objsendfile);
1121 /* Objects sent with write */
1122 varnish_submit_derive(conf->instance, "objects", "total_objects",
1123 "sent_write", stats->n_objwrite);
1124 /* Objects overflowing workspace */
1125 varnish_submit_derive(conf->instance, "objects", "total_objects",
1126 "workspace_overflow", stats->n_objoverflow);
1127 }
1129 if (conf->collect_purge) {
1130 /* N total active purges */
1131 varnish_submit_derive(conf->instance, "purge", "total_operations", "total",
1132 stats->n_purge);
1133 /* N new purges added */
1134 varnish_submit_derive(conf->instance, "purge", "total_operations", "added",
1135 stats->n_purge_add);
1136 /* N old purges deleted */
1137 varnish_submit_derive(conf->instance, "purge", "total_operations",
1138 "deleted", stats->n_purge_retire);
1139 /* N objects tested */
1140 varnish_submit_derive(conf->instance, "purge", "total_operations",
1141 "objects_tested", stats->n_purge_obj_test);
1142 /* N regexps tested against */
1143 varnish_submit_derive(conf->instance, "purge", "total_operations",
1144 "regexps_tested", stats->n_purge_re_test);
1145 /* N duplicate purges removed */
1146 varnish_submit_derive(conf->instance, "purge", "total_operations",
1147 "duplicate", stats->n_purge_dups);
1148 }
1150 if (conf->collect_session) {
1151 /* Session Closed */
1152 varnish_submit_derive(conf->instance, "session", "total_operations",
1153 "closed", stats->sess_closed);
1154 /* Session Pipeline */
1155 varnish_submit_derive(conf->instance, "session", "total_operations",
1156 "pipeline", stats->sess_pipeline);
1157 /* Session Read Ahead */
1158 varnish_submit_derive(conf->instance, "session", "total_operations",
1159 "readahead", stats->sess_readahead);
1160 /* Session Linger */
1161 varnish_submit_derive(conf->instance, "session", "total_operations",
1162 "linger", stats->sess_linger);
1163 /* Session herd */
1164 varnish_submit_derive(conf->instance, "session", "total_operations", "herd",
1165 stats->sess_herd);
1166 }
1168 if (conf->collect_shm) {
1169 /* SHM records */
1170 varnish_submit_derive(conf->instance, "shm", "total_operations", "records",
1171 stats->shm_records);
1172 /* SHM writes */
1173 varnish_submit_derive(conf->instance, "shm", "total_operations", "writes",
1174 stats->shm_writes);
1175 /* SHM flushes due to overflow */
1176 varnish_submit_derive(conf->instance, "shm", "total_operations", "flushes",
1177 stats->shm_flushes);
1178 /* SHM MTX contention */
1179 varnish_submit_derive(conf->instance, "shm", "total_operations",
1180 "contention", stats->shm_cont);
1181 /* SHM cycles through buffer */
1182 varnish_submit_derive(conf->instance, "shm", "total_operations", "cycles",
1183 stats->shm_cycles);
1184 }
1186 if (conf->collect_sm) {
1187 /* allocator requests */
1188 varnish_submit_derive(conf->instance, "sm", "total_requests", "nreq",
1189 stats->sm_nreq);
1190 /* outstanding allocations */
1191 varnish_submit_gauge(conf->instance, "sm", "requests", "outstanding",
1192 stats->sm_nobj);
1193 /* bytes allocated */
1194 varnish_submit_derive(conf->instance, "sm", "total_bytes", "allocated",
1195 stats->sm_balloc);
1196 /* bytes free */
1197 varnish_submit_derive(conf->instance, "sm", "total_bytes", "free",
1198 stats->sm_bfree);
1199 }
1201 if (conf->collect_sma) {
1202 /* SMA allocator requests */
1203 varnish_submit_derive(conf->instance, "sma", "total_requests", "nreq",
1204 stats->sma_nreq);
1205 /* SMA outstanding allocations */
1206 varnish_submit_gauge(conf->instance, "sma", "requests", "outstanding",
1207 stats->sma_nobj);
1208 /* SMA outstanding bytes */
1209 varnish_submit_gauge(conf->instance, "sma", "bytes", "outstanding",
1210 stats->sma_nbytes);
1211 /* SMA bytes allocated */
1212 varnish_submit_derive(conf->instance, "sma", "total_bytes", "allocated",
1213 stats->sma_balloc);
1214 /* SMA bytes free */
1215 varnish_submit_derive(conf->instance, "sma", "total_bytes", "free",
1216 stats->sma_bfree);
1217 }
1219 if (conf->collect_sms) {
1220 /* SMS allocator requests */
1221 varnish_submit_derive(conf->instance, "sms", "total_requests", "allocator",
1222 stats->sms_nreq);
1223 /* SMS outstanding allocations */
1224 varnish_submit_gauge(conf->instance, "sms", "requests", "outstanding",
1225 stats->sms_nobj);
1226 /* SMS outstanding bytes */
1227 varnish_submit_gauge(conf->instance, "sms", "bytes", "outstanding",
1228 stats->sms_nbytes);
1229 /* SMS bytes allocated */
1230 varnish_submit_derive(conf->instance, "sms", "total_bytes", "allocated",
1231 stats->sms_balloc);
1232 /* SMS bytes freed */
1233 varnish_submit_derive(conf->instance, "sms", "total_bytes", "free",
1234 stats->sms_bfree);
1235 }
1237 if (conf->collect_struct) {
1238 /* N struct sess_mem */
1239 varnish_submit_gauge(conf->instance, "struct", "current_sessions",
1240 "sess_mem", stats->n_sess_mem);
1241 /* N struct sess */
1242 varnish_submit_gauge(conf->instance, "struct", "current_sessions", "sess",
1243 stats->n_sess);
1244 /* N struct object */
1245 varnish_submit_gauge(conf->instance, "struct", "objects", "object",
1246 stats->n_object);
1247 /* N struct objecthead */
1248 varnish_submit_gauge(conf->instance, "struct", "objects", "objecthead",
1249 stats->n_objecthead);
1250 /* N struct smf */
1251 varnish_submit_gauge(conf->instance, "struct", "objects", "smf",
1252 stats->n_smf);
1253 /* N small free smf */
1254 varnish_submit_gauge(conf->instance, "struct", "objects", "smf_frag",
1255 stats->n_smf_frag);
1256 /* N large free smf */
1257 varnish_submit_gauge(conf->instance, "struct", "objects", "smf_large",
1258 stats->n_smf_large);
1259 /* N struct vbe_conn */
1260 varnish_submit_gauge(conf->instance, "struct", "objects", "vbe_conn",
1261 stats->n_vbe_conn);
1262 }
1264 if (conf->collect_totals) {
1265 /* Total Sessions */
1266 varnish_submit_derive(conf->instance, "totals", "total_sessions",
1267 "sessions", stats->s_sess);
1268 /* Total Requests */
1269 varnish_submit_derive(conf->instance, "totals", "total_requests",
1270 "requests", stats->s_req);
1271 /* Total pipe */
1272 varnish_submit_derive(conf->instance, "totals", "total_operations", "pipe",
1273 stats->s_pipe);
1274 /* Total pass */
1275 varnish_submit_derive(conf->instance, "totals", "total_operations", "pass",
1276 stats->s_pass);
1277 /* Total fetch */
1278 varnish_submit_derive(conf->instance, "totals", "total_operations",
1279 "fetches", stats->s_fetch);
1280 /* Total header bytes */
1281 varnish_submit_derive(conf->instance, "totals", "total_bytes",
1282 "header-bytes", stats->s_hdrbytes);
1283 /* Total body byte */
1284 varnish_submit_derive(conf->instance, "totals", "total_bytes", "body-bytes",
1285 stats->s_bodybytes);
1286 }
1288 if (conf->collect_vcl) {
1289 /* N vcl total */
1290 varnish_submit_gauge(conf->instance, "vcl", "vcl", "total_vcl",
1291 stats->n_vcl);
1292 /* N vcl available */
1293 varnish_submit_gauge(conf->instance, "vcl", "vcl", "avail_vcl",
1294 stats->n_vcl_avail);
1295 /* N vcl discarded */
1296 varnish_submit_gauge(conf->instance, "vcl", "vcl", "discarded_vcl",
1297 stats->n_vcl_discard);
1298 }
1300 if (conf->collect_workers) {
1301 /* worker threads */
1302 varnish_submit_gauge(conf->instance, "workers", "threads", "worker",
1303 stats->n_wrk);
1304 /* worker threads created */
1305 varnish_submit_derive(conf->instance, "workers", "total_threads", "created",
1306 stats->n_wrk_create);
1307 /* worker threads not created */
1308 varnish_submit_derive(conf->instance, "workers", "total_threads", "failed",
1309 stats->n_wrk_failed);
1310 /* worker threads limited */
1311 varnish_submit_derive(conf->instance, "workers", "total_threads", "limited",
1312 stats->n_wrk_max);
1313 /* dropped work requests */
1314 varnish_submit_derive(conf->instance, "workers", "total_threads", "dropped",
1315 stats->n_wrk_drop);
1316 /* queued work requests */
1317 varnish_submit_derive(conf->instance, "workers", "total_requests", "queued",
1318 stats->n_wrk_queue);
1319 /* overflowed work requests */
1320 varnish_submit_derive(conf->instance, "workers", "total_requests",
1321 "overflowed", stats->n_wrk_overflow);
1322 }
1324 } /* }}} void varnish_monitor */
1325 #endif
1327 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1328 static int varnish_read(user_data_t *ud) /* {{{ */
1329 {
1330 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
1331 struct VSM_data *vd;
1332 _Bool ok;
1333 const c_varnish_stats_t *stats;
1334 #elif HAVE_VARNISH_V5
1335 struct vsm *vd;
1336 struct vsc *vsc;
1337 int vsm_status;
1338 #endif
1340 user_config_t *conf;
1342 if ((ud == NULL) || (ud->data == NULL))
1343 return EINVAL;
1345 conf = ud->data;
1347 vd = VSM_New();
1349 #if HAVE_VARNISH_V5
1350 vsc = VSC_New();
1351 #endif
1353 #if HAVE_VARNISH_V3
1354 VSC_Setup(vd);
1355 #endif
1357 if (conf->instance != NULL) {
1358 int status;
1360 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
1361 status = VSM_n_Arg(vd, conf->instance);
1362 #elif HAVE_VARNISH_V5
1363 status = VSM_Arg(vd, 'n', conf->instance);
1364 #endif
1366 if (status < 0) {
1367 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
1368 VSM_Delete(vd);
1369 #elif HAVE_VARNISH_V5
1370 VSC_Destroy(&vsc, vd);
1371 VSM_Destroy(&vd);
1372 #endif
1373 ERROR("varnish plugin: VSM_Arg (\"%s\") failed "
1374 "with status %i.",
1375 conf->instance, status);
1376 return -1;
1377 }
1378 }
1380 #if HAVE_VARNISH_V3
1381 ok = (VSC_Open(vd, /* diag = */ 1) == 0);
1382 #elif HAVE_VARNISH_V4
1383 ok = (VSM_Open(vd) == 0);
1384 #endif
1385 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
1386 if (!ok) {
1387 VSM_Delete(vd);
1388 ERROR("varnish plugin: Unable to open connection.");
1389 return -1;
1390 }
1391 #endif
1393 #if HAVE_VARNISH_V3
1394 stats = VSC_Main(vd);
1395 #elif HAVE_VARNISH_V4
1396 stats = VSC_Main(vd, NULL);
1397 #endif
1398 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
1399 if (!stats) {
1400 VSM_Delete(vd);
1401 ERROR("varnish plugin: Unable to get statistics.");
1402 return -1;
1403 }
1404 #endif
1406 #if HAVE_VARNISH_V5
1407 if (VSM_Attach(vd, STDERR_FILENO)) {
1408 ERROR("varnish plugin: Cannot attach to varnish. %s", VSM_Error(vd));
1409 VSC_Destroy(&vsc, vd);
1410 VSM_Destroy(&vd);
1411 return -1;
1412 }
1414 vsm_status = VSM_Status(vd);
1415 if (vsm_status & ~(VSM_MGT_RUNNING | VSM_WRK_RUNNING)) {
1416 ERROR("varnish plugin: Unable to get statistics.");
1417 VSC_Destroy(&vsc, vd);
1418 VSM_Destroy(&vd);
1419 return -1;
1420 }
1421 #endif
1423 #if HAVE_VARNISH_V3
1424 VSC_Iter(vd, varnish_monitor, conf);
1425 #elif HAVE_VARNISH_V4
1426 VSC_Iter(vd, NULL, varnish_monitor, conf);
1427 #elif HAVE_VARNISH_V5
1428 VSC_Iter(vsc, vd, varnish_monitor, conf);
1429 #endif
1431 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
1432 VSM_Delete(vd);
1433 #elif HAVE_VARNISH_V5
1434 VSC_Destroy(&vsc, vd);
1435 VSM_Destroy(&vd);
1436 #endif
1438 return 0;
1439 } /* }}} */
1440 #else /* if HAVE_VARNISH_V2 */
1441 static int varnish_read(user_data_t *ud) /* {{{ */
1442 {
1443 const c_varnish_stats_t *stats;
1445 user_config_t *conf;
1447 if ((ud == NULL) || (ud->data == NULL))
1448 return EINVAL;
1450 conf = ud->data;
1452 stats = VSL_OpenStats(conf->instance);
1453 if (stats == NULL) {
1454 ERROR("Varnish plugin : unable to load statistics");
1456 return -1;
1457 }
1459 varnish_monitor(conf, stats);
1461 return 0;
1462 } /* }}} */
1463 #endif
1465 static void varnish_config_free(void *ptr) /* {{{ */
1466 {
1467 user_config_t *conf = ptr;
1469 if (conf == NULL)
1470 return;
1472 sfree(conf->instance);
1473 sfree(conf);
1474 } /* }}} */
1476 static int varnish_config_apply_default(user_config_t *conf) /* {{{ */
1477 {
1478 if (conf == NULL)
1479 return EINVAL;
1481 conf->collect_backend = 1;
1482 conf->collect_cache = 1;
1483 conf->collect_connections = 1;
1484 #ifdef HAVE_VARNISH_V3
1485 conf->collect_dirdns = 0;
1486 #endif
1487 conf->collect_esi = 0;
1488 conf->collect_fetch = 0;
1489 conf->collect_hcb = 0;
1490 conf->collect_objects = 0;
1491 #if HAVE_VARNISH_V2
1492 conf->collect_purge = 0;
1493 #else
1494 conf->collect_ban = 0;
1495 #endif
1496 conf->collect_session = 0;
1497 conf->collect_shm = 1;
1498 #if HAVE_VARNISH_V2
1499 conf->collect_sm = 0;
1500 #endif
1501 #if HAVE_VARNISH_V2 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1502 conf->collect_sma = 0;
1503 #endif
1504 conf->collect_sms = 0;
1505 conf->collect_struct = 0;
1506 conf->collect_totals = 0;
1507 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1508 conf->collect_uptime = 0;
1509 #endif
1510 conf->collect_vcl = 0;
1511 conf->collect_workers = 0;
1512 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1513 conf->collect_vsm = 0;
1514 conf->collect_lck = 0;
1515 conf->collect_mempool = 0;
1516 conf->collect_mgt = 0;
1517 conf->collect_smf = 0;
1518 conf->collect_vbe = 0;
1519 conf->collect_mse = 0;
1520 #endif
1522 return 0;
1523 } /* }}} int varnish_config_apply_default */
1525 static int varnish_init(void) /* {{{ */
1526 {
1527 user_config_t *conf;
1529 if (have_instance)
1530 return 0;
1532 conf = calloc(1, sizeof(*conf));
1533 if (conf == NULL)
1534 return ENOMEM;
1536 /* Default settings: */
1537 conf->instance = NULL;
1539 varnish_config_apply_default(conf);
1541 plugin_register_complex_read(
1542 /* group = */ "varnish",
1543 /* name = */ "varnish/localhost",
1544 /* callback = */ varnish_read,
1545 /* interval = */ 0,
1546 &(user_data_t){
1547 .data = conf, .free_func = varnish_config_free,
1548 });
1550 return 0;
1551 } /* }}} int varnish_init */
1553 static int varnish_config_instance(const oconfig_item_t *ci) /* {{{ */
1554 {
1555 user_config_t *conf;
1556 char callback_name[DATA_MAX_NAME_LEN];
1558 conf = calloc(1, sizeof(*conf));
1559 if (conf == NULL)
1560 return ENOMEM;
1561 conf->instance = NULL;
1563 varnish_config_apply_default(conf);
1565 if (ci->values_num == 1) {
1566 int status;
1568 status = cf_util_get_string(ci, &conf->instance);
1569 if (status != 0) {
1570 sfree(conf);
1571 return status;
1572 }
1573 assert(conf->instance != NULL);
1575 if (strcmp("localhost", conf->instance) == 0) {
1576 sfree(conf->instance);
1577 conf->instance = NULL;
1578 }
1579 } else if (ci->values_num > 1) {
1580 WARNING("Varnish plugin: \"Instance\" blocks accept only "
1581 "one argument.");
1582 sfree(conf);
1583 return EINVAL;
1584 }
1586 for (int i = 0; i < ci->children_num; i++) {
1587 oconfig_item_t *child = ci->children + i;
1589 if (strcasecmp("CollectCache", child->key) == 0)
1590 cf_util_get_boolean(child, &conf->collect_cache);
1591 else if (strcasecmp("CollectConnections", child->key) == 0)
1592 cf_util_get_boolean(child, &conf->collect_connections);
1593 else if (strcasecmp("CollectESI", child->key) == 0)
1594 cf_util_get_boolean(child, &conf->collect_esi);
1595 else if (strcasecmp("CollectDirectorDNS", child->key) == 0)
1596 #ifdef HAVE_VARNISH_V3
1597 cf_util_get_boolean(child, &conf->collect_dirdns);
1598 #else
1599 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1600 child->key, "v3");
1601 #endif
1602 else if (strcasecmp("CollectBackend", child->key) == 0)
1603 cf_util_get_boolean(child, &conf->collect_backend);
1604 else if (strcasecmp("CollectFetch", child->key) == 0)
1605 cf_util_get_boolean(child, &conf->collect_fetch);
1606 else if (strcasecmp("CollectHCB", child->key) == 0)
1607 cf_util_get_boolean(child, &conf->collect_hcb);
1608 else if (strcasecmp("CollectObjects", child->key) == 0)
1609 cf_util_get_boolean(child, &conf->collect_objects);
1610 else if (strcasecmp("CollectPurge", child->key) == 0)
1611 #if HAVE_VARNISH_V2
1612 cf_util_get_boolean(child, &conf->collect_purge);
1613 #else
1614 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1615 child->key, "v2");
1616 #endif
1617 else if (strcasecmp("CollectBan", child->key) == 0)
1618 #if HAVE_VARNISH_V2
1619 WARNING("Varnish plugin: \"%s\" is not available for Varnish %s.",
1620 child->key, "v2");
1621 #else
1622 cf_util_get_boolean(child, &conf->collect_ban);
1623 #endif
1624 else if (strcasecmp("CollectSession", child->key) == 0)
1625 cf_util_get_boolean(child, &conf->collect_session);
1626 else if (strcasecmp("CollectSHM", child->key) == 0)
1627 cf_util_get_boolean(child, &conf->collect_shm);
1628 else if (strcasecmp("CollectSMS", child->key) == 0)
1629 cf_util_get_boolean(child, &conf->collect_sms);
1630 else if (strcasecmp("CollectSMA", child->key) == 0)
1631 #if HAVE_VARNISH_V2 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1632 cf_util_get_boolean(child, &conf->collect_sma);
1633 #else
1634 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1635 child->key, "v2 and v4");
1636 #endif
1637 else if (strcasecmp("CollectSM", child->key) == 0)
1638 #if HAVE_VARNISH_V2
1639 cf_util_get_boolean(child, &conf->collect_sm);
1640 #else
1641 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1642 child->key, "v2");
1643 #endif
1644 else if (strcasecmp("CollectStruct", child->key) == 0)
1645 cf_util_get_boolean(child, &conf->collect_struct);
1646 else if (strcasecmp("CollectTotals", child->key) == 0)
1647 cf_util_get_boolean(child, &conf->collect_totals);
1648 else if (strcasecmp("CollectUptime", child->key) == 0)
1649 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1650 cf_util_get_boolean(child, &conf->collect_uptime);
1651 #else
1652 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1653 child->key, "v3 and v4");
1654 #endif
1655 else if (strcasecmp("CollectVCL", child->key) == 0)
1656 cf_util_get_boolean(child, &conf->collect_vcl);
1657 else if (strcasecmp("CollectWorkers", child->key) == 0)
1658 cf_util_get_boolean(child, &conf->collect_workers);
1659 else if (strcasecmp("CollectVSM", child->key) == 0)
1660 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1661 cf_util_get_boolean(child, &conf->collect_vsm);
1662 #else
1663 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1664 child->key, "v4");
1665 #endif
1666 else if (strcasecmp("CollectLock", child->key) == 0)
1667 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1668 cf_util_get_boolean(child, &conf->collect_lck);
1669 #else
1670 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1671 child->key, "v4");
1672 #endif
1673 else if (strcasecmp("CollectMempool", child->key) == 0)
1674 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1675 cf_util_get_boolean(child, &conf->collect_mempool);
1676 #else
1677 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1678 child->key, "v4");
1679 #endif
1680 else if (strcasecmp("CollectManagement", child->key) == 0)
1681 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1682 cf_util_get_boolean(child, &conf->collect_mgt);
1683 #else
1684 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1685 child->key, "v4");
1686 #endif
1687 else if (strcasecmp("CollectSMF", child->key) == 0)
1688 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1689 cf_util_get_boolean(child, &conf->collect_smf);
1690 #else
1691 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1692 child->key, "v4");
1693 #endif
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);
1697 #else
1698 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1699 child->key, "v4");
1700 #endif
1701 else if (strcasecmp("CollectVBE", child->key) == 0)
1702 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1703 cf_util_get_boolean(child, &conf->collect_vbe);
1704 #else
1705 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1706 child->key, "v4");
1707 #endif
1708 else if (strcasecmp("CollectMSE", child->key) == 0)
1709 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1710 cf_util_get_boolean(child, &conf->collect_mse);
1711 #else
1712 WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
1713 child->key, "Plus v4");
1714 #endif
1715 else {
1716 WARNING("Varnish plugin: Ignoring unknown "
1717 "configuration option: \"%s\". Did "
1718 "you forget to add an <Instance /> "
1719 "block around the configuration?",
1720 child->key);
1721 }
1722 }
1724 if (!conf->collect_cache && !conf->collect_connections &&
1725 !conf->collect_esi && !conf->collect_backend
1726 #ifdef HAVE_VARNISH_V3
1727 && !conf->collect_dirdns
1728 #endif
1729 && !conf->collect_fetch && !conf->collect_hcb && !conf->collect_objects
1730 #if HAVE_VARNISH_V2
1731 && !conf->collect_purge
1732 #else
1733 && !conf->collect_ban
1734 #endif
1735 && !conf->collect_session && !conf->collect_shm && !conf->collect_sms
1736 #if HAVE_VARNISH_V2
1737 && !conf->collect_sm
1738 #endif
1739 #if HAVE_VARNISH_V2 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1740 && !conf->collect_sma
1741 #endif
1742 && !conf->collect_struct && !conf->collect_totals
1743 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1744 && !conf->collect_uptime
1745 #endif
1746 && !conf->collect_vcl && !conf->collect_workers
1747 #if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
1748 && !conf->collect_vsm && !conf->collect_vbe && !conf->collect_smf &&
1749 !conf->collect_mgt && !conf->collect_lck && !conf->collect_mempool &&
1750 !conf->collect_mse
1751 #endif
1752 ) {
1753 WARNING("Varnish plugin: No metric has been configured for "
1754 "instance \"%s\". Disabling this instance.",
1755 (conf->instance == NULL) ? "localhost" : conf->instance);
1756 sfree(conf);
1757 return EINVAL;
1758 }
1760 snprintf(callback_name, sizeof(callback_name), "varnish/%s",
1761 (conf->instance == NULL) ? "localhost" : conf->instance);
1763 plugin_register_complex_read(
1764 /* group = */ "varnish",
1765 /* name = */ callback_name,
1766 /* callback = */ varnish_read,
1767 /* interval = */ 0,
1768 &(user_data_t){
1769 .data = conf, .free_func = varnish_config_free,
1770 });
1772 have_instance = 1;
1774 return 0;
1775 } /* }}} int varnish_config_instance */
1777 static int varnish_config(oconfig_item_t *ci) /* {{{ */
1778 {
1779 for (int i = 0; i < ci->children_num; i++) {
1780 oconfig_item_t *child = ci->children + i;
1782 if (strcasecmp("Instance", child->key) == 0)
1783 varnish_config_instance(child);
1784 else {
1785 WARNING("Varnish plugin: Ignoring unknown "
1786 "configuration option: \"%s\"",
1787 child->key);
1788 }
1789 }
1791 return 0;
1792 } /* }}} int varnish_config */
1794 void module_register(void) /* {{{ */
1795 {
1796 plugin_register_complex_config("varnish", varnish_config);
1797 plugin_register_init("varnish", varnish_init);
1798 } /* }}} */