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 **/
26 #include "collectd.h"
28 #include "common.h"
29 #include "plugin.h"
31 #if HAVE_VARNISH_V4
32 #include <vapi/vsm.h>
33 #include <vapi/vsc.h>
34 typedef struct VSC_C_main c_varnish_stats_t;
35 #endif
37 #if HAVE_VARNISH_V3
38 #include <varnishapi.h>
39 #include <vsc.h>
40 typedef struct VSC_C_main c_varnish_stats_t;
41 #endif
43 #if HAVE_VARNISH_V2
44 #include <varnishapi.h>
45 typedef struct varnish_stats c_varnish_stats_t;
46 #endif
48 /* {{{ user_config_s */
49 struct user_config_s {
50 char *instance;
52 _Bool collect_cache;
53 _Bool collect_connections;
54 _Bool collect_esi;
55 _Bool collect_backend;
56 #ifdef HAVE_VARNISH_V3
57 _Bool collect_dirdns;
58 #endif
59 _Bool collect_fetch;
60 _Bool collect_hcb;
61 _Bool collect_objects;
62 #if HAVE_VARNISH_V2
63 _Bool collect_purge;
64 #else
65 _Bool collect_ban;
66 #endif
67 _Bool collect_session;
68 _Bool collect_shm;
69 _Bool collect_sms;
70 #if HAVE_VARNISH_V2
71 _Bool collect_sm;
72 _Bool collect_sma;
73 #endif
74 _Bool collect_struct;
75 _Bool collect_totals;
76 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
77 _Bool collect_uptime;
78 #endif
79 _Bool collect_vcl;
80 _Bool collect_workers;
81 #if HAVE_VARNISH_V4
82 _Bool collect_vsm;
83 #endif
84 };
85 typedef struct user_config_s user_config_t; /* }}} */
87 static _Bool have_instance = 0;
89 static int varnish_submit (const char *plugin_instance, /* {{{ */
90 const char *category, const char *type, const char *type_instance, value_t value)
91 {
92 value_list_t vl = VALUE_LIST_INIT;
94 vl.values = &value;
95 vl.values_len = 1;
97 sstrncpy (vl.plugin, "varnish", sizeof (vl.plugin));
99 if (plugin_instance == NULL)
100 plugin_instance = "default";
101 ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance),
102 "%s-%s", plugin_instance, category);
104 sstrncpy (vl.type, type, sizeof (vl.type));
106 if (type_instance != NULL)
107 sstrncpy (vl.type_instance, type_instance,
108 sizeof (vl.type_instance));
110 return (plugin_dispatch_values (&vl));
111 } /* }}} int varnish_submit */
113 static int varnish_submit_gauge (const char *plugin_instance, /* {{{ */
114 const char *category, const char *type, const char *type_instance,
115 uint64_t gauge_value)
116 {
117 return (varnish_submit (plugin_instance, category, type, type_instance,
118 (value_t) { .gauge = (gauge_t) gauge_value }));
119 } /* }}} int varnish_submit_gauge */
121 static int varnish_submit_derive (const char *plugin_instance, /* {{{ */
122 const char *category, const char *type, const char *type_instance,
123 uint64_t derive_value)
124 {
125 return (varnish_submit (plugin_instance, category, type, type_instance,
126 (value_t) { .derive = (derive_t) derive_value }));
127 } /* }}} int varnish_submit_derive */
129 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
130 static int varnish_monitor (void *priv, const struct VSC_point * const pt) /* {{{ */
131 {
132 uint64_t val;
133 const user_config_t *conf;
134 const char *class;
135 const char *name;
137 if (pt == NULL)
138 return (0);
140 conf = priv;
142 #if HAVE_VARNISH_V4
143 class = pt->section->fantom->type;
144 name = pt->desc->name;
146 if (strcmp(class, "MAIN") != 0)
147 return (0);
149 #elif HAVE_VARNISH_V3
150 class = pt->class;
151 name = pt->name;
153 if (strcmp(class, "") != 0)
154 return (0);
155 #endif
157 val = *(const volatile uint64_t*) pt->ptr;
159 if (conf->collect_cache)
160 {
161 if (strcmp(name, "cache_hit") == 0)
162 return varnish_submit_derive (conf->instance, "cache", "cache_result", "hit", val);
163 else if (strcmp(name, "cache_miss") == 0)
164 return varnish_submit_derive (conf->instance, "cache", "cache_result", "miss", val);
165 else if (strcmp(name, "cache_hitpass") == 0)
166 return varnish_submit_derive (conf->instance, "cache", "cache_result", "hitpass", val);
167 }
169 if (conf->collect_connections)
170 {
171 if (strcmp(name, "client_conn") == 0)
172 return varnish_submit_derive (conf->instance, "connections", "connections", "accepted", val);
173 else if (strcmp(name, "client_drop") == 0)
174 return varnish_submit_derive (conf->instance, "connections", "connections", "dropped" , val);
175 else if (strcmp(name, "client_req") == 0)
176 return varnish_submit_derive (conf->instance, "connections", "connections", "received", val);
177 }
179 #ifdef HAVE_VARNISH_V3
180 if (conf->collect_dirdns)
181 {
182 if (strcmp(name, "dir_dns_lookups") == 0)
183 return varnish_submit_derive (conf->instance, "dirdns", "cache_operation", "lookups", val);
184 else if (strcmp(name, "dir_dns_failed") == 0)
185 return varnish_submit_derive (conf->instance, "dirdns", "cache_result", "failed", val);
186 else if (strcmp(name, "dir_dns_hit") == 0)
187 return varnish_submit_derive (conf->instance, "dirdns", "cache_result", "hits", val);
188 else if (strcmp(name, "dir_dns_cache_full") == 0)
189 return varnish_submit_derive (conf->instance, "dirdns", "cache_result", "cache_full", val);
190 }
191 #endif
193 if (conf->collect_esi)
194 {
195 if (strcmp(name, "esi_errors") == 0)
196 return varnish_submit_derive (conf->instance, "esi", "total_operations", "error", val);
197 else if (strcmp(name, "esi_parse") == 0)
198 return varnish_submit_derive (conf->instance, "esi", "total_operations", "parsed", val);
199 else if (strcmp(name, "esi_warnings") == 0)
200 return varnish_submit_derive (conf->instance, "esi", "total_operations", "warning", val);
201 }
203 if (conf->collect_backend)
204 {
205 if (strcmp(name, "backend_conn") == 0)
206 return varnish_submit_derive (conf->instance, "backend", "connections", "success", val);
207 else if (strcmp(name, "backend_unhealthy") == 0)
208 return varnish_submit_derive (conf->instance, "backend", "connections", "not-attempted", val);
209 else if (strcmp(name, "backend_busy") == 0)
210 return varnish_submit_derive (conf->instance, "backend", "connections", "too-many", val);
211 else if (strcmp(name, "backend_fail") == 0)
212 return varnish_submit_derive (conf->instance, "backend", "connections", "failures", val);
213 else if (strcmp(name, "backend_reuse") == 0)
214 return varnish_submit_derive (conf->instance, "backend", "connections", "reuses", val);
215 else if (strcmp(name, "backend_toolate") == 0)
216 return varnish_submit_derive (conf->instance, "backend", "connections", "was-closed", val);
217 else if (strcmp(name, "backend_recycle") == 0)
218 return varnish_submit_derive (conf->instance, "backend", "connections", "recycled", val);
219 else if (strcmp(name, "backend_unused") == 0)
220 return varnish_submit_derive (conf->instance, "backend", "connections", "unused", val);
221 else if (strcmp(name, "backend_retry") == 0)
222 return varnish_submit_derive (conf->instance, "backend", "connections", "retries", val);
223 else if (strcmp(name, "backend_req") == 0)
224 return varnish_submit_derive (conf->instance, "backend", "http_requests", "requests", val);
225 else if (strcmp(name, "n_backend") == 0)
226 return varnish_submit_gauge (conf->instance, "backend", "backends", "n_backends", val);
227 }
229 if (conf->collect_fetch)
230 {
231 if (strcmp(name, "fetch_head") == 0)
232 return varnish_submit_derive (conf->instance, "fetch", "http_requests", "head", val);
233 else if (strcmp(name, "fetch_length") == 0)
234 return varnish_submit_derive (conf->instance, "fetch", "http_requests", "length", val);
235 else if (strcmp(name, "fetch_chunked") == 0)
236 return varnish_submit_derive (conf->instance, "fetch", "http_requests", "chunked", val);
237 else if (strcmp(name, "fetch_eof") == 0)
238 return varnish_submit_derive (conf->instance, "fetch", "http_requests", "eof", val);
239 else if (strcmp(name, "fetch_bad") == 0)
240 return varnish_submit_derive (conf->instance, "fetch", "http_requests", "bad_headers", val);
241 else if (strcmp(name, "fetch_close") == 0)
242 return varnish_submit_derive (conf->instance, "fetch", "http_requests", "close", val);
243 else if (strcmp(name, "fetch_oldhttp") == 0)
244 return varnish_submit_derive (conf->instance, "fetch", "http_requests", "oldhttp", val);
245 else if (strcmp(name, "fetch_zero") == 0)
246 return varnish_submit_derive (conf->instance, "fetch", "http_requests", "zero", val);
247 else if (strcmp(name, "fetch_failed") == 0)
248 return varnish_submit_derive (conf->instance, "fetch", "http_requests", "failed", val);
249 else if (strcmp(name, "fetch_1xx") == 0)
250 return varnish_submit_derive (conf->instance, "fetch", "http_requests", "no_body_1xx", val);
251 else if (strcmp(name, "fetch_204") == 0)
252 return varnish_submit_derive (conf->instance, "fetch", "http_requests", "no_body_204", val);
253 else if (strcmp(name, "fetch_304") == 0)
254 return varnish_submit_derive (conf->instance, "fetch", "http_requests", "no_body_304", val);
255 }
257 if (conf->collect_hcb)
258 {
259 if (strcmp(name, "hcb_nolock") == 0)
260 return varnish_submit_derive (conf->instance, "hcb", "cache_operation", "lookup_nolock", val);
261 else if (strcmp(name, "hcb_lock") == 0)
262 return varnish_submit_derive (conf->instance, "hcb", "cache_operation", "lookup_lock", val);
263 else if (strcmp(name, "hcb_insert") == 0)
264 return varnish_submit_derive (conf->instance, "hcb", "cache_operation", "insert", val);
265 }
267 if (conf->collect_objects)
268 {
269 if (strcmp(name, "n_expired") == 0)
270 return varnish_submit_derive (conf->instance, "objects", "total_objects", "expired", val);
271 else if (strcmp(name, "n_lru_nuked") == 0)
272 return varnish_submit_derive (conf->instance, "objects", "total_objects", "lru_nuked", val);
273 else if (strcmp(name, "n_lru_saved") == 0)
274 return varnish_submit_derive (conf->instance, "objects", "total_objects", "lru_saved", val);
275 else if (strcmp(name, "n_lru_moved") == 0)
276 return varnish_submit_derive (conf->instance, "objects", "total_objects", "lru_moved", val);
277 else if (strcmp(name, "n_deathrow") == 0)
278 return varnish_submit_derive (conf->instance, "objects", "total_objects", "deathrow", val);
279 else if (strcmp(name, "losthdr") == 0)
280 return varnish_submit_derive (conf->instance, "objects", "total_objects", "header_overflow", val);
281 else if (strcmp(name, "n_obj_purged") == 0)
282 return varnish_submit_derive (conf->instance, "objects", "total_objects", "purged", val);
283 else if (strcmp(name, "n_objsendfile") == 0)
284 return varnish_submit_derive (conf->instance, "objects", "total_objects", "sent_sendfile", val);
285 else if (strcmp(name, "n_objwrite") == 0)
286 return varnish_submit_derive (conf->instance, "objects", "total_objects", "sent_write", val);
287 else if (strcmp(name, "n_objoverflow") == 0)
288 return varnish_submit_derive (conf->instance, "objects", "total_objects", "workspace_overflow", val);
289 }
291 #if HAVE_VARNISH_V3
292 if (conf->collect_ban)
293 {
294 if (strcmp(name, "n_ban") == 0)
295 return varnish_submit_derive (conf->instance, "ban", "total_operations", "total", val);
296 else if (strcmp(name, "n_ban_add") == 0)
297 return varnish_submit_derive (conf->instance, "ban", "total_operations", "added", val);
298 else if (strcmp(name, "n_ban_retire") == 0)
299 return varnish_submit_derive (conf->instance, "ban", "total_operations", "deleted", val);
300 else if (strcmp(name, "n_ban_obj_test") == 0)
301 return varnish_submit_derive (conf->instance, "ban", "total_operations", "objects_tested", val);
302 else if (strcmp(name, "n_ban_re_test") == 0)
303 return varnish_submit_derive (conf->instance, "ban", "total_operations", "regexps_tested", val);
304 else if (strcmp(name, "n_ban_dups") == 0)
305 return varnish_submit_derive (conf->instance, "ban", "total_operations", "duplicate", val);
306 }
307 #endif
308 #if HAVE_VARNISH_V4
309 if (conf->collect_ban)
310 {
311 if (strcmp(name, "bans") == 0)
312 return varnish_submit_derive (conf->instance, "ban", "total_operations", "total", val);
313 else if (strcmp(name, "bans_added") == 0)
314 return varnish_submit_derive (conf->instance, "ban", "total_operations", "added", val);
315 else if (strcmp(name, "bans_obj") == 0)
316 return varnish_submit_derive (conf->instance, "ban", "total_operations", "obj", val);
317 else if (strcmp(name, "bans_req") == 0)
318 return varnish_submit_derive (conf->instance, "ban", "total_operations", "req", val);
319 else if (strcmp(name, "bans_completed") == 0)
320 return varnish_submit_derive (conf->instance, "ban", "total_operations", "completed", val);
321 else if (strcmp(name, "bans_deleted") == 0)
322 return varnish_submit_derive (conf->instance, "ban", "total_operations", "deleted", val);
323 else if (strcmp(name, "bans_tested") == 0)
324 return varnish_submit_derive (conf->instance, "ban", "total_operations", "tested", val);
325 else if (strcmp(name, "bans_dups") == 0)
326 return varnish_submit_derive (conf->instance, "ban", "total_operations", "duplicate", val);
327 }
328 #endif
330 if (conf->collect_session)
331 {
332 if (strcmp(name, "sess_closed") == 0)
333 return varnish_submit_derive (conf->instance, "session", "total_operations", "closed", val);
334 else if (strcmp(name, "sess_pipeline") == 0)
335 return varnish_submit_derive (conf->instance, "session", "total_operations", "pipeline", val);
336 else if (strcmp(name, "sess_readahead") == 0)
337 return varnish_submit_derive (conf->instance, "session", "total_operations", "readahead", val);
338 else if (strcmp(name, "sess_conn") == 0)
339 return varnish_submit_derive (conf->instance, "session", "total_operations", "accepted", val);
340 else if (strcmp(name, "sess_drop") == 0)
341 return varnish_submit_derive (conf->instance, "session", "total_operations", "dropped", val);
342 else if (strcmp(name, "sess_fail") == 0)
343 return varnish_submit_derive (conf->instance, "session", "total_operations", "failed", val);
344 else if (strcmp(name, "sess_pipe_overflow") == 0)
345 return varnish_submit_derive (conf->instance, "session", "total_operations", "overflow", val);
346 else if (strcmp(name, "sess_queued") == 0)
347 return varnish_submit_derive (conf->instance, "session", "total_operations", "queued", val);
348 else if (strcmp(name, "sess_linger") == 0)
349 return varnish_submit_derive (conf->instance, "session", "total_operations", "linger", val);
350 else if (strcmp(name, "sess_herd") == 0)
351 return varnish_submit_derive (conf->instance, "session", "total_operations", "herd", val);
352 }
354 if (conf->collect_shm)
355 {
356 if (strcmp(name, "shm_records") == 0)
357 return varnish_submit_derive (conf->instance, "shm", "total_operations", "records", val);
358 else if (strcmp(name, "shm_writes") == 0)
359 return varnish_submit_derive (conf->instance, "shm", "total_operations", "writes", val);
360 else if (strcmp(name, "shm_flushes") == 0)
361 return varnish_submit_derive (conf->instance, "shm", "total_operations", "flushes", val);
362 else if (strcmp(name, "shm_cont") == 0)
363 return varnish_submit_derive (conf->instance, "shm", "total_operations", "contention", val);
364 else if (strcmp(name, "shm_cycles") == 0)
365 return varnish_submit_derive (conf->instance, "shm", "total_operations", "cycles", val);
366 }
368 if (conf->collect_sms)
369 {
370 if (strcmp(name, "sms_nreq") == 0)
371 return varnish_submit_derive (conf->instance, "sms", "total_requests", "allocator", val);
372 else if (strcmp(name, "sms_nobj") == 0)
373 return varnish_submit_gauge (conf->instance, "sms", "requests", "outstanding", val);
374 else if (strcmp(name, "sms_nbytes") == 0)
375 return varnish_submit_gauge (conf->instance, "sms", "bytes", "outstanding", val);
376 else if (strcmp(name, "sms_balloc") == 0)
377 return varnish_submit_derive (conf->instance, "sms", "total_bytes", "allocated", val);
378 else if (strcmp(name, "sms_bfree") == 0)
379 return varnish_submit_derive (conf->instance, "sms", "total_bytes", "free", val);
380 }
382 if (conf->collect_struct)
383 {
384 if (strcmp(name, "n_sess_mem") == 0)
385 return varnish_submit_gauge (conf->instance, "struct", "current_sessions", "sess_mem", val);
386 else if (strcmp(name, "n_sess") == 0)
387 return varnish_submit_gauge (conf->instance, "struct", "current_sessions", "sess", val);
388 else if (strcmp(name, "n_object") == 0)
389 return varnish_submit_gauge (conf->instance, "struct", "objects", "object", val);
390 else if (strcmp(name, "n_vampireobject") == 0)
391 return varnish_submit_gauge (conf->instance, "struct", "objects", "vampireobject", val);
392 else if (strcmp(name, "n_objectcore") == 0)
393 return varnish_submit_gauge (conf->instance, "struct", "objects", "objectcore", val);
394 else if (strcmp(name, "n_waitinglist") == 0)
395 return varnish_submit_gauge (conf->instance, "struct", "objects", "waitinglist", val);
396 else if (strcmp(name, "n_objecthead") == 0)
397 return varnish_submit_gauge (conf->instance, "struct", "objects", "objecthead", val);
398 else if (strcmp(name, "n_smf") == 0)
399 return varnish_submit_gauge (conf->instance, "struct", "objects", "smf", val);
400 else if (strcmp(name, "n_smf_frag") == 0)
401 return varnish_submit_gauge (conf->instance, "struct", "objects", "smf_frag", val);
402 else if (strcmp(name, "n_smf_large") == 0)
403 return varnish_submit_gauge (conf->instance, "struct", "objects", "smf_large", val);
404 else if (strcmp(name, "n_vbe_conn") == 0)
405 return varnish_submit_gauge (conf->instance, "struct", "objects", "vbe_conn", val);
406 }
408 if (conf->collect_totals)
409 {
410 if (strcmp(name, "s_sess") == 0)
411 return varnish_submit_derive (conf->instance, "totals", "total_sessions", "sessions", val);
412 else if (strcmp(name, "s_req") == 0)
413 return varnish_submit_derive (conf->instance, "totals", "total_requests", "requests", val);
414 else if (strcmp(name, "s_pipe") == 0)
415 return varnish_submit_derive (conf->instance, "totals", "total_operations", "pipe", val);
416 else if (strcmp(name, "s_pass") == 0)
417 return varnish_submit_derive (conf->instance, "totals", "total_operations", "pass", val);
418 else if (strcmp(name, "s_fetch") == 0)
419 return varnish_submit_derive (conf->instance, "totals", "total_operations", "fetches", val);
420 else if (strcmp(name, "s_synth") == 0)
421 return varnish_submit_derive (conf->instance, "totals", "total_bytes", "synth", val);
422 else if (strcmp(name, "s_req_hdrbytes") == 0)
423 return varnish_submit_derive (conf->instance, "totals", "total_bytes", "req_header", val);
424 else if (strcmp(name, "s_req_bodybytes") == 0)
425 return varnish_submit_derive (conf->instance, "totals", "total_bytes", "req_body", val);
426 else if (strcmp(name, "s_resp_hdrbytes") == 0)
427 return varnish_submit_derive (conf->instance, "totals", "total_bytes", "resp_header", val);
428 else if (strcmp(name, "s_resp_bodybytes") == 0)
429 return varnish_submit_derive (conf->instance, "totals", "total_bytes", "resp_body", val);
430 else if (strcmp(name, "s_pipe_hdrbytes") == 0)
431 return varnish_submit_derive (conf->instance, "totals", "total_bytes", "pipe_header", val);
432 else if (strcmp(name, "s_pipe_in") == 0)
433 return varnish_submit_derive (conf->instance, "totals", "total_bytes", "pipe_in", val);
434 else if (strcmp(name, "s_pipe_out") == 0)
435 return varnish_submit_derive (conf->instance, "totals", "total_bytes", "pipe_out", val);
436 else if (strcmp(name, "n_purges") == 0)
437 return varnish_submit_derive (conf->instance, "totals", "total_operations", "purges", val);
438 else if (strcmp(name, "s_hdrbytes") == 0)
439 return varnish_submit_derive (conf->instance, "totals", "total_bytes", "header-bytes", val);
440 else if (strcmp(name, "s_bodybytes") == 0)
441 return varnish_submit_derive (conf->instance, "totals", "total_bytes", "body-bytes", val);
442 else if (strcmp(name, "n_gzip") == 0)
443 return varnish_submit_derive (conf->instance, "totals", "total_operations", "gzip", val);
444 else if (strcmp(name, "n_gunzip") == 0)
445 return varnish_submit_derive (conf->instance, "totals", "total_operations", "gunzip", val);
446 }
448 if (conf->collect_uptime)
449 {
450 if (strcmp(name, "uptime") == 0)
451 return varnish_submit_gauge (conf->instance, "uptime", "uptime", "client_uptime", val);
452 }
454 if (conf->collect_vcl)
455 {
456 if (strcmp(name, "n_vcl") == 0)
457 return varnish_submit_gauge (conf->instance, "vcl", "vcl", "total_vcl", val);
458 else if (strcmp(name, "n_vcl_avail") == 0)
459 return varnish_submit_gauge (conf->instance, "vcl", "vcl", "avail_vcl", val);
460 else if (strcmp(name, "n_vcl_discard") == 0)
461 return varnish_submit_gauge (conf->instance, "vcl", "vcl", "discarded_vcl", val);
462 else if (strcmp(name, "vmods") == 0)
463 return varnish_submit_gauge (conf->instance, "vcl", "objects", "vmod", val);
464 }
466 if (conf->collect_workers)
467 {
468 if (strcmp(name, "threads") == 0)
469 return varnish_submit_gauge (conf->instance, "workers", "threads", "worker", val);
470 else if (strcmp(name, "threads_created") == 0)
471 return varnish_submit_derive (conf->instance, "workers", "total_threads", "created", val);
472 else if (strcmp(name, "threads_failed") == 0)
473 return varnish_submit_derive (conf->instance, "workers", "total_threads", "failed", val);
474 else if (strcmp(name, "threads_limited") == 0)
475 return varnish_submit_derive (conf->instance, "workers", "total_threads", "limited", val);
476 else if (strcmp(name, "threads_destroyed") == 0)
477 return varnish_submit_derive (conf->instance, "workers", "total_threads", "dropped", val);
478 else if (strcmp(name, "thread_queue_len") == 0)
479 return varnish_submit_derive (conf->instance, "workers", "queue_length", "threads", val);
480 else if (strcmp(name, "n_wrk") == 0)
481 return varnish_submit_gauge (conf->instance, "workers", "threads", "worker", val);
482 else if (strcmp(name, "n_wrk_create") == 0)
483 return varnish_submit_derive (conf->instance, "workers", "total_threads", "created", val);
484 else if (strcmp(name, "n_wrk_failed") == 0)
485 return varnish_submit_derive (conf->instance, "workers", "total_threads", "failed", val);
486 else if (strcmp(name, "n_wrk_max") == 0)
487 return varnish_submit_derive (conf->instance, "workers", "total_threads", "limited", val);
488 else if (strcmp(name, "n_wrk_drop") == 0)
489 return varnish_submit_derive (conf->instance, "workers", "total_threads", "dropped", val);
490 else if (strcmp(name, "n_wrk_queue") == 0)
491 return varnish_submit_derive (conf->instance, "workers", "total_requests", "queued", val);
492 else if (strcmp(name, "n_wrk_overflow") == 0)
493 return varnish_submit_derive (conf->instance, "workers", "total_requests", "overflowed", val);
494 else if (strcmp(name, "n_wrk_queued") == 0)
495 return varnish_submit_derive (conf->instance, "workers", "total_requests", "queued", val);
496 else if (strcmp(name, "n_wrk_lqueue") == 0)
497 return varnish_submit_derive (conf->instance, "workers", "total_requests", "queue_length", val);
498 }
500 #if HAVE_VARNISH_V4
501 if (conf->collect_vsm)
502 {
503 if (strcmp(name, "vsm_free") == 0)
504 return varnish_submit_gauge (conf->instance, "vsm", "bytes", "free", val);
505 else if (strcmp(name, "vsm_used") == 0)
506 return varnish_submit_gauge (conf->instance, "vsm", "bytes", "used", val);
507 else if (strcmp(name, "vsm_cooling") == 0)
508 return varnish_submit_gauge (conf->instance, "vsm", "bytes", "cooling", val);
509 else if (strcmp(name, "vsm_overflow") == 0)
510 return varnish_submit_gauge (conf->instance, "vsm", "bytes", "overflow", val);
511 else if (strcmp(name, "vsm_overflowed") == 0)
512 return varnish_submit_derive (conf->instance, "vsm", "total_bytes", "overflowed", val);
513 }
514 #endif
516 return (0);
518 } /* }}} static int varnish_monitor */
519 #else /* if HAVE_VARNISH_V2 */
520 static void varnish_monitor (const user_config_t *conf, /* {{{ */
521 const c_varnish_stats_t *stats)
522 {
523 if (conf->collect_cache)
524 {
525 /* Cache hits */
526 varnish_submit_derive (conf->instance, "cache", "cache_result", "hit", stats->cache_hit);
527 /* Cache misses */
528 varnish_submit_derive (conf->instance, "cache", "cache_result", "miss", stats->cache_miss);
529 /* Cache hits for pass */
530 varnish_submit_derive (conf->instance, "cache", "cache_result", "hitpass", stats->cache_hitpass);
531 }
533 if (conf->collect_connections)
534 {
535 /* Client connections accepted */
536 varnish_submit_derive (conf->instance, "connections", "connections", "accepted", stats->client_conn);
537 /* Connection dropped, no sess */
538 varnish_submit_derive (conf->instance, "connections", "connections", "dropped" , stats->client_drop);
539 /* Client requests received */
540 varnish_submit_derive (conf->instance, "connections", "connections", "received", stats->client_req);
541 }
543 if (conf->collect_esi)
544 {
545 /* ESI parse errors (unlock) */
546 varnish_submit_derive (conf->instance, "esi", "total_operations", "error", stats->esi_errors);
547 /* Objects ESI parsed (unlock) */
548 varnish_submit_derive (conf->instance, "esi", "total_operations", "parsed", stats->esi_parse);
549 }
551 if (conf->collect_backend)
552 {
553 /* Backend conn. success */
554 varnish_submit_derive (conf->instance, "backend", "connections", "success" , stats->backend_conn);
555 /* Backend conn. not attempted */
556 varnish_submit_derive (conf->instance, "backend", "connections", "not-attempted", stats->backend_unhealthy);
557 /* Backend conn. too many */
558 varnish_submit_derive (conf->instance, "backend", "connections", "too-many" , stats->backend_busy);
559 /* Backend conn. failures */
560 varnish_submit_derive (conf->instance, "backend", "connections", "failures" , stats->backend_fail);
561 /* Backend conn. reuses */
562 varnish_submit_derive (conf->instance, "backend", "connections", "reuses" , stats->backend_reuse);
563 /* Backend conn. was closed */
564 varnish_submit_derive (conf->instance, "backend", "connections", "was-closed" , stats->backend_toolate);
565 /* Backend conn. recycles */
566 varnish_submit_derive (conf->instance, "backend", "connections", "recycled" , stats->backend_recycle);
567 /* Backend conn. unused */
568 varnish_submit_derive (conf->instance, "backend", "connections", "unused" , stats->backend_unused);
569 /* Backend requests mades */
570 varnish_submit_derive (conf->instance, "backend", "http_requests", "requests" , stats->backend_req);
571 /* N backends */
572 varnish_submit_gauge (conf->instance, "backend", "backends", "n_backends" , stats->n_backend);
573 }
575 if (conf->collect_fetch)
576 {
577 /* Fetch head */
578 varnish_submit_derive (conf->instance, "fetch", "http_requests", "head" , stats->fetch_head);
579 /* Fetch with length */
580 varnish_submit_derive (conf->instance, "fetch", "http_requests", "length" , stats->fetch_length);
581 /* Fetch chunked */
582 varnish_submit_derive (conf->instance, "fetch", "http_requests", "chunked" , stats->fetch_chunked);
583 /* Fetch EOF */
584 varnish_submit_derive (conf->instance, "fetch", "http_requests", "eof" , stats->fetch_eof);
585 /* Fetch bad headers */
586 varnish_submit_derive (conf->instance, "fetch", "http_requests", "bad_headers", stats->fetch_bad);
587 /* Fetch wanted close */
588 varnish_submit_derive (conf->instance, "fetch", "http_requests", "close" , stats->fetch_close);
589 /* Fetch pre HTTP/1.1 closed */
590 varnish_submit_derive (conf->instance, "fetch", "http_requests", "oldhttp" , stats->fetch_oldhttp);
591 /* Fetch zero len */
592 varnish_submit_derive (conf->instance, "fetch", "http_requests", "zero" , stats->fetch_zero);
593 /* Fetch failed */
594 varnish_submit_derive (conf->instance, "fetch", "http_requests", "failed" , stats->fetch_failed);
595 }
597 if (conf->collect_hcb)
598 {
599 /* HCB Lookups without lock */
600 varnish_submit_derive (conf->instance, "hcb", "cache_operation", "lookup_nolock", stats->hcb_nolock);
601 /* HCB Lookups with lock */
602 varnish_submit_derive (conf->instance, "hcb", "cache_operation", "lookup_lock", stats->hcb_lock);
603 /* HCB Inserts */
604 varnish_submit_derive (conf->instance, "hcb", "cache_operation", "insert", stats->hcb_insert);
605 }
607 if (conf->collect_objects)
608 {
609 /* N expired objects */
610 varnish_submit_derive (conf->instance, "objects", "total_objects", "expired", stats->n_expired);
611 /* N LRU nuked objects */
612 varnish_submit_derive (conf->instance, "objects", "total_objects", "lru_nuked", stats->n_lru_nuked);
613 /* N LRU saved objects */
614 varnish_submit_derive (conf->instance, "objects", "total_objects", "lru_saved", stats->n_lru_saved);
615 /* N LRU moved objects */
616 varnish_submit_derive (conf->instance, "objects", "total_objects", "lru_moved", stats->n_lru_moved);
617 /* N objects on deathrow */
618 varnish_submit_derive (conf->instance, "objects", "total_objects", "deathrow", stats->n_deathrow);
619 /* HTTP header overflows */
620 varnish_submit_derive (conf->instance, "objects", "total_objects", "header_overflow", stats->losthdr);
621 /* Objects sent with sendfile */
622 varnish_submit_derive (conf->instance, "objects", "total_objects", "sent_sendfile", stats->n_objsendfile);
623 /* Objects sent with write */
624 varnish_submit_derive (conf->instance, "objects", "total_objects", "sent_write", stats->n_objwrite);
625 /* Objects overflowing workspace */
626 varnish_submit_derive (conf->instance, "objects", "total_objects", "workspace_overflow", stats->n_objoverflow);
627 }
629 if (conf->collect_purge)
630 {
631 /* N total active purges */
632 varnish_submit_derive (conf->instance, "purge", "total_operations", "total", stats->n_purge);
633 /* N new purges added */
634 varnish_submit_derive (conf->instance, "purge", "total_operations", "added", stats->n_purge_add);
635 /* N old purges deleted */
636 varnish_submit_derive (conf->instance, "purge", "total_operations", "deleted", stats->n_purge_retire);
637 /* N objects tested */
638 varnish_submit_derive (conf->instance, "purge", "total_operations", "objects_tested", stats->n_purge_obj_test);
639 /* N regexps tested against */
640 varnish_submit_derive (conf->instance, "purge", "total_operations", "regexps_tested", stats->n_purge_re_test);
641 /* N duplicate purges removed */
642 varnish_submit_derive (conf->instance, "purge", "total_operations", "duplicate", stats->n_purge_dups);
643 }
645 if (conf->collect_session)
646 {
647 /* Session Closed */
648 varnish_submit_derive (conf->instance, "session", "total_operations", "closed", stats->sess_closed);
649 /* Session Pipeline */
650 varnish_submit_derive (conf->instance, "session", "total_operations", "pipeline", stats->sess_pipeline);
651 /* Session Read Ahead */
652 varnish_submit_derive (conf->instance, "session", "total_operations", "readahead", stats->sess_readahead);
653 /* Session Linger */
654 varnish_submit_derive (conf->instance, "session", "total_operations", "linger", stats->sess_linger);
655 /* Session herd */
656 varnish_submit_derive (conf->instance, "session", "total_operations", "herd", stats->sess_herd);
657 }
659 if (conf->collect_shm)
660 {
661 /* SHM records */
662 varnish_submit_derive (conf->instance, "shm", "total_operations", "records" , stats->shm_records);
663 /* SHM writes */
664 varnish_submit_derive (conf->instance, "shm", "total_operations", "writes" , stats->shm_writes);
665 /* SHM flushes due to overflow */
666 varnish_submit_derive (conf->instance, "shm", "total_operations", "flushes" , stats->shm_flushes);
667 /* SHM MTX contention */
668 varnish_submit_derive (conf->instance, "shm", "total_operations", "contention", stats->shm_cont);
669 /* SHM cycles through buffer */
670 varnish_submit_derive (conf->instance, "shm", "total_operations", "cycles" , stats->shm_cycles);
671 }
673 if (conf->collect_sm)
674 {
675 /* allocator requests */
676 varnish_submit_derive (conf->instance, "sm", "total_requests", "nreq", stats->sm_nreq);
677 /* outstanding allocations */
678 varnish_submit_gauge (conf->instance, "sm", "requests", "outstanding", stats->sm_nobj);
679 /* bytes allocated */
680 varnish_submit_derive (conf->instance, "sm", "total_bytes", "allocated", stats->sm_balloc);
681 /* bytes free */
682 varnish_submit_derive (conf->instance, "sm", "total_bytes", "free", stats->sm_bfree);
683 }
685 if (conf->collect_sma)
686 {
687 /* SMA allocator requests */
688 varnish_submit_derive (conf->instance, "sma", "total_requests", "nreq", stats->sma_nreq);
689 /* SMA outstanding allocations */
690 varnish_submit_gauge (conf->instance, "sma", "requests", "outstanding", stats->sma_nobj);
691 /* SMA outstanding bytes */
692 varnish_submit_gauge (conf->instance, "sma", "bytes", "outstanding", stats->sma_nbytes);
693 /* SMA bytes allocated */
694 varnish_submit_derive (conf->instance, "sma", "total_bytes", "allocated", stats->sma_balloc);
695 /* SMA bytes free */
696 varnish_submit_derive (conf->instance, "sma", "total_bytes", "free" , stats->sma_bfree);
697 }
699 if (conf->collect_sms)
700 {
701 /* SMS allocator requests */
702 varnish_submit_derive (conf->instance, "sms", "total_requests", "allocator", stats->sms_nreq);
703 /* SMS outstanding allocations */
704 varnish_submit_gauge (conf->instance, "sms", "requests", "outstanding", stats->sms_nobj);
705 /* SMS outstanding bytes */
706 varnish_submit_gauge (conf->instance, "sms", "bytes", "outstanding", stats->sms_nbytes);
707 /* SMS bytes allocated */
708 varnish_submit_derive (conf->instance, "sms", "total_bytes", "allocated", stats->sms_balloc);
709 /* SMS bytes freed */
710 varnish_submit_derive (conf->instance, "sms", "total_bytes", "free", stats->sms_bfree);
711 }
713 if (conf->collect_struct)
714 {
715 /* N struct sess_mem */
716 varnish_submit_gauge (conf->instance, "struct", "current_sessions", "sess_mem", stats->n_sess_mem);
717 /* N struct sess */
718 varnish_submit_gauge (conf->instance, "struct", "current_sessions", "sess", stats->n_sess);
719 /* N struct object */
720 varnish_submit_gauge (conf->instance, "struct", "objects", "object", stats->n_object);
721 /* N struct objecthead */
722 varnish_submit_gauge (conf->instance, "struct", "objects", "objecthead", stats->n_objecthead);
723 /* N struct smf */
724 varnish_submit_gauge (conf->instance, "struct", "objects", "smf", stats->n_smf);
725 /* N small free smf */
726 varnish_submit_gauge (conf->instance, "struct", "objects", "smf_frag", stats->n_smf_frag);
727 /* N large free smf */
728 varnish_submit_gauge (conf->instance, "struct", "objects", "smf_large", stats->n_smf_large);
729 /* N struct vbe_conn */
730 varnish_submit_gauge (conf->instance, "struct", "objects", "vbe_conn", stats->n_vbe_conn);
731 }
733 if (conf->collect_totals)
734 {
735 /* Total Sessions */
736 varnish_submit_derive (conf->instance, "totals", "total_sessions", "sessions", stats->s_sess);
737 /* Total Requests */
738 varnish_submit_derive (conf->instance, "totals", "total_requests", "requests", stats->s_req);
739 /* Total pipe */
740 varnish_submit_derive (conf->instance, "totals", "total_operations", "pipe", stats->s_pipe);
741 /* Total pass */
742 varnish_submit_derive (conf->instance, "totals", "total_operations", "pass", stats->s_pass);
743 /* Total fetch */
744 varnish_submit_derive (conf->instance, "totals", "total_operations", "fetches", stats->s_fetch);
745 /* Total header bytes */
746 varnish_submit_derive (conf->instance, "totals", "total_bytes", "header-bytes", stats->s_hdrbytes);
747 /* Total body byte */
748 varnish_submit_derive (conf->instance, "totals", "total_bytes", "body-bytes", stats->s_bodybytes);
749 }
751 if (conf->collect_vcl)
752 {
753 /* N vcl total */
754 varnish_submit_gauge (conf->instance, "vcl", "vcl", "total_vcl", stats->n_vcl);
755 /* N vcl available */
756 varnish_submit_gauge (conf->instance, "vcl", "vcl", "avail_vcl", stats->n_vcl_avail);
757 /* N vcl discarded */
758 varnish_submit_gauge (conf->instance, "vcl", "vcl", "discarded_vcl", stats->n_vcl_discard);
759 }
761 if (conf->collect_workers)
762 {
763 /* worker threads */
764 varnish_submit_gauge (conf->instance, "workers", "threads", "worker", stats->n_wrk);
765 /* worker threads created */
766 varnish_submit_derive (conf->instance, "workers", "total_threads", "created", stats->n_wrk_create);
767 /* worker threads not created */
768 varnish_submit_derive (conf->instance, "workers", "total_threads", "failed", stats->n_wrk_failed);
769 /* worker threads limited */
770 varnish_submit_derive (conf->instance, "workers", "total_threads", "limited", stats->n_wrk_max);
771 /* dropped work requests */
772 varnish_submit_derive (conf->instance, "workers", "total_threads", "dropped", stats->n_wrk_drop);
773 /* queued work requests */
774 varnish_submit_derive (conf->instance, "workers", "total_requests", "queued", stats->n_wrk_queue);
775 /* overflowed work requests */
776 varnish_submit_derive (conf->instance, "workers", "total_requests", "overflowed", stats->n_wrk_overflow);
777 }
779 } /* }}} void varnish_monitor */
780 #endif
782 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
783 static int varnish_read (user_data_t *ud) /* {{{ */
784 {
785 struct VSM_data *vd;
786 const c_varnish_stats_t *stats;
787 _Bool ok;
789 user_config_t *conf;
791 if ((ud == NULL) || (ud->data == NULL))
792 return (EINVAL);
794 conf = ud->data;
796 vd = VSM_New();
797 #if HAVE_VARNISH_V3
798 VSC_Setup(vd);
799 #endif
801 if (conf->instance != NULL)
802 {
803 int status;
805 status = VSM_n_Arg (vd, conf->instance);
806 if (status < 0)
807 {
808 VSM_Delete (vd);
809 ERROR ("varnish plugin: VSM_n_Arg (\"%s\") failed "
810 "with status %i.",
811 conf->instance, status);
812 return (-1);
813 }
814 }
816 #if HAVE_VARNISH_V3
817 ok = (VSC_Open (vd, /* diag = */ 1) == 0);
818 #else /* if HAVE_VARNISH_V4 */
819 ok = (VSM_Open (vd) == 0);
820 #endif
821 if (!ok)
822 {
823 VSM_Delete (vd);
824 ERROR ("varnish plugin: Unable to open connection.");
826 return (-1);
827 }
829 #if HAVE_VARNISH_V3
830 stats = VSC_Main(vd);
831 #else /* if HAVE_VARNISH_V4 */
832 stats = VSC_Main(vd, NULL);
833 #endif
834 if (!stats)
835 {
836 VSM_Delete (vd);
837 ERROR ("varnish plugin: Unable to get statistics.");
839 return (-1);
840 }
842 #if HAVE_VARNISH_V3
843 VSC_Iter (vd, varnish_monitor, conf);
844 #else /* if HAVE_VARNISH_V4 */
845 VSC_Iter (vd, NULL, varnish_monitor, conf);
846 #endif
847 VSM_Delete (vd);
849 return (0);
850 } /* }}} */
851 #else /* if HAVE_VARNISH_V2 */
852 static int varnish_read (user_data_t *ud) /* {{{ */
853 {
854 const c_varnish_stats_t *stats;
856 user_config_t *conf;
858 if ((ud == NULL) || (ud->data == NULL))
859 return (EINVAL);
861 conf = ud->data;
863 stats = VSL_OpenStats (conf->instance);
864 if (stats == NULL)
865 {
866 ERROR ("Varnish plugin : unable to load statistics");
868 return (-1);
869 }
871 varnish_monitor (conf, stats);
873 return (0);
874 } /* }}} */
875 #endif
877 static void varnish_config_free (void *ptr) /* {{{ */
878 {
879 user_config_t *conf = ptr;
881 if (conf == NULL)
882 return;
884 sfree (conf->instance);
885 sfree (conf);
886 } /* }}} */
888 static int varnish_config_apply_default (user_config_t *conf) /* {{{ */
889 {
890 if (conf == NULL)
891 return (EINVAL);
893 conf->collect_backend = 1;
894 conf->collect_cache = 1;
895 conf->collect_connections = 1;
896 #ifdef HAVE_VARNISH_V3
897 conf->collect_dirdns = 0;
898 #endif
899 conf->collect_esi = 0;
900 conf->collect_fetch = 0;
901 conf->collect_hcb = 0;
902 conf->collect_objects = 0;
903 #if HAVE_VARNISH_V2
904 conf->collect_purge = 0;
905 #else
906 conf->collect_ban = 0;
907 #endif
908 conf->collect_session = 0;
909 conf->collect_shm = 1;
910 #if HAVE_VARNISH_V2
911 conf->collect_sm = 0;
912 conf->collect_sma = 0;
913 #endif
914 conf->collect_sms = 0;
915 conf->collect_struct = 0;
916 conf->collect_totals = 0;
917 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
918 conf->collect_uptime = 0;
919 #endif
920 conf->collect_vcl = 0;
921 conf->collect_workers = 0;
922 #if HAVE_VARNISH_V4
923 conf->collect_vsm = 0;
924 #endif
926 return (0);
927 } /* }}} int varnish_config_apply_default */
929 static int varnish_init (void) /* {{{ */
930 {
931 user_config_t *conf;
933 if (have_instance)
934 return (0);
936 conf = calloc (1, sizeof (*conf));
937 if (conf == NULL)
938 return (ENOMEM);
940 /* Default settings: */
941 conf->instance = NULL;
943 varnish_config_apply_default (conf);
945 plugin_register_complex_read (/* group = */ "varnish",
946 /* name = */ "varnish/localhost",
947 /* callback = */ varnish_read,
948 /* interval = */ 0,
949 &(user_data_t) {
950 .data = conf,
951 .free_func = varnish_config_free,
952 });
954 return (0);
955 } /* }}} int varnish_init */
957 static int varnish_config_instance (const oconfig_item_t *ci) /* {{{ */
958 {
959 user_config_t *conf;
960 char callback_name[DATA_MAX_NAME_LEN];
962 conf = calloc (1, sizeof (*conf));
963 if (conf == NULL)
964 return (ENOMEM);
965 conf->instance = NULL;
967 varnish_config_apply_default (conf);
969 if (ci->values_num == 1)
970 {
971 int status;
973 status = cf_util_get_string (ci, &conf->instance);
974 if (status != 0)
975 {
976 sfree (conf);
977 return (status);
978 }
979 assert (conf->instance != NULL);
981 if (strcmp ("localhost", conf->instance) == 0)
982 {
983 sfree (conf->instance);
984 conf->instance = NULL;
985 }
986 }
987 else if (ci->values_num > 1)
988 {
989 WARNING ("Varnish plugin: \"Instance\" blocks accept only "
990 "one argument.");
991 sfree (conf);
992 return (EINVAL);
993 }
995 for (int i = 0; i < ci->children_num; i++)
996 {
997 oconfig_item_t *child = ci->children + i;
999 if (strcasecmp ("CollectCache", child->key) == 0)
1000 cf_util_get_boolean (child, &conf->collect_cache);
1001 else if (strcasecmp ("CollectConnections", child->key) == 0)
1002 cf_util_get_boolean (child, &conf->collect_connections);
1003 else if (strcasecmp ("CollectESI", child->key) == 0)
1004 cf_util_get_boolean (child, &conf->collect_esi);
1005 else if (strcasecmp ("CollectDirectorDNS", child->key) == 0)
1006 #ifdef HAVE_VARNISH_V3
1007 cf_util_get_boolean (child, &conf->collect_dirdns);
1008 #else
1009 WARNING ("Varnish plugin: \"%s\" is available for Varnish %s only.", child->key, "v3");
1010 #endif
1011 else if (strcasecmp ("CollectBackend", child->key) == 0)
1012 cf_util_get_boolean (child, &conf->collect_backend);
1013 else if (strcasecmp ("CollectFetch", child->key) == 0)
1014 cf_util_get_boolean (child, &conf->collect_fetch);
1015 else if (strcasecmp ("CollectHCB", child->key) == 0)
1016 cf_util_get_boolean (child, &conf->collect_hcb);
1017 else if (strcasecmp ("CollectObjects", child->key) == 0)
1018 cf_util_get_boolean (child, &conf->collect_objects);
1019 else if (strcasecmp ("CollectPurge", child->key) == 0)
1020 #if HAVE_VARNISH_V2
1021 cf_util_get_boolean (child, &conf->collect_purge);
1022 #else
1023 WARNING ("Varnish plugin: \"%s\" is available for Varnish %s only.", child->key, "v2");
1024 #endif
1025 else if (strcasecmp ("CollectBan", child->key) == 0)
1026 #if HAVE_VARNISH_V2
1027 WARNING ("Varnish plugin: \"%s\" is not available for Varnish %s.", child->key, "v2");
1028 #else
1029 cf_util_get_boolean (child, &conf->collect_ban);
1030 #endif
1031 else if (strcasecmp ("CollectSession", child->key) == 0)
1032 cf_util_get_boolean (child, &conf->collect_session);
1033 else if (strcasecmp ("CollectSHM", child->key) == 0)
1034 cf_util_get_boolean (child, &conf->collect_shm);
1035 else if (strcasecmp ("CollectSMS", child->key) == 0)
1036 cf_util_get_boolean (child, &conf->collect_sms);
1037 else if (strcasecmp ("CollectSMA", child->key) == 0)
1038 #if HAVE_VARNISH_V2
1039 cf_util_get_boolean (child, &conf->collect_sma);
1040 #else
1041 WARNING ("Varnish plugin: \"%s\" is available for Varnish %s only.", child->key, "v2");
1042 #endif
1043 else if (strcasecmp ("CollectSM", child->key) == 0)
1044 #if HAVE_VARNISH_V2
1045 cf_util_get_boolean (child, &conf->collect_sm);
1046 #else
1047 WARNING ("Varnish plugin: \"%s\" is available for Varnish %s only.", child->key, "v2");
1048 #endif
1049 else if (strcasecmp ("CollectStruct", child->key) == 0)
1050 cf_util_get_boolean (child, &conf->collect_struct);
1051 else if (strcasecmp ("CollectTotals", child->key) == 0)
1052 cf_util_get_boolean (child, &conf->collect_totals);
1053 else if (strcasecmp ("CollectUptime", child->key) == 0)
1054 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
1055 cf_util_get_boolean (child, &conf->collect_uptime);
1056 #else
1057 WARNING ("Varnish plugin: \"%s\" is available for Varnish %s only.", child->key, "v3 and v4");
1058 #endif
1059 else if (strcasecmp ("CollectVCL", child->key) == 0)
1060 cf_util_get_boolean (child, &conf->collect_vcl);
1061 else if (strcasecmp ("CollectWorkers", child->key) == 0)
1062 cf_util_get_boolean (child, &conf->collect_workers);
1063 else if (strcasecmp ("CollectVSM", child->key) == 0)
1064 #if HAVE_VARNISH_V4
1065 cf_util_get_boolean (child, &conf->collect_vsm);
1066 #else
1067 WARNING ("Varnish plugin: \"%s\" is available for Varnish %s only.", child->key, "v4");
1068 #endif
1069 else
1070 {
1071 WARNING ("Varnish plugin: Ignoring unknown "
1072 "configuration option: \"%s\". Did "
1073 "you forget to add an <Instance /> "
1074 "block around the configuration?",
1075 child->key);
1076 }
1077 }
1079 if (!conf->collect_cache
1080 && !conf->collect_connections
1081 && !conf->collect_esi
1082 && !conf->collect_backend
1083 #ifdef HAVE_VARNISH_V3
1084 && !conf->collect_dirdns
1085 #endif
1086 && !conf->collect_fetch
1087 && !conf->collect_hcb
1088 && !conf->collect_objects
1089 #if HAVE_VARNISH_V2
1090 && !conf->collect_purge
1091 #else
1092 && !conf->collect_ban
1093 #endif
1094 && !conf->collect_session
1095 && !conf->collect_shm
1096 && !conf->collect_sms
1097 #if HAVE_VARNISH_V2
1098 && !conf->collect_sma
1099 && !conf->collect_sm
1100 #endif
1101 && !conf->collect_struct
1102 && !conf->collect_totals
1103 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
1104 && !conf->collect_uptime
1105 #endif
1106 && !conf->collect_vcl
1107 && !conf->collect_workers
1108 #if HAVE_VARNISH_V4
1109 && !conf->collect_vsm
1110 #endif
1111 )
1112 {
1113 WARNING ("Varnish plugin: No metric has been configured for "
1114 "instance \"%s\". Disabling this instance.",
1115 (conf->instance == NULL) ? "localhost" : conf->instance);
1116 sfree (conf);
1117 return (EINVAL);
1118 }
1120 ssnprintf (callback_name, sizeof (callback_name), "varnish/%s",
1121 (conf->instance == NULL) ? "localhost" : conf->instance);
1123 plugin_register_complex_read (/* group = */ "varnish",
1124 /* name = */ callback_name,
1125 /* callback = */ varnish_read,
1126 /* interval = */ 0,
1127 &(user_data_t) {
1128 .data = conf,
1129 .free_func = varnish_config_free,
1130 });
1132 have_instance = 1;
1134 return (0);
1135 } /* }}} int varnish_config_instance */
1137 static int varnish_config (oconfig_item_t *ci) /* {{{ */
1138 {
1139 for (int i = 0; i < ci->children_num; i++)
1140 {
1141 oconfig_item_t *child = ci->children + i;
1143 if (strcasecmp ("Instance", child->key) == 0)
1144 varnish_config_instance (child);
1145 else
1146 {
1147 WARNING ("Varnish plugin: Ignoring unknown "
1148 "configuration option: \"%s\"",
1149 child->key);
1150 }
1151 }
1153 return (0);
1154 } /* }}} int varnish_config */
1156 void module_register (void) /* {{{ */
1157 {
1158 plugin_register_complex_config ("varnish", varnish_config);
1159 plugin_register_init ("varnish", varnish_init);
1160 } /* }}} */
1162 /* vim: set sw=8 noet fdm=marker : */