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