src/common.[ch]: Add rate_to_value().
[collectd.git] / src / varnish.c
1 /**
2  * collectd - src/varnish.c
3  * Copyright (C) 2010 Jérôme Renard
4  * Copyright (C) 2010 Marc Fournier
5  * Copyright (C) 2010 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 verplant.org>
24  **/
25
26 /**
27  * Current list of what is monitored and what is not monitored (yet)
28  * {{{
29  * Field name           Description                           Monitored
30  * ----------           -----------                           ---------
31  * uptime               Child uptime                              N
32  * client_conn          Client connections accepted               Y
33  * client_drop          Connection dropped, no sess               Y
34  * client_req           Client requests received                  Y
35  * cache_hit            Cache hits                                Y
36  * cache_hitpass        Cache hits for pass                       Y
37  * cache_miss           Cache misses                              Y
38  * backend_conn         Backend conn. success                     Y
39  * backend_unhealthy    Backend conn. not attempted               Y
40  * backend_busy         Backend conn. too many                    Y
41  * backend_fail         Backend conn. failures                    Y
42  * backend_reuse        Backend conn. reuses                      Y
43  * backend_toolate      Backend conn. was closed                  Y
44  * backend_recycle      Backend conn. recycles                    Y
45  * backend_unused       Backend conn. unused                      Y
46  * fetch_head           Fetch head                                Y
47  * fetch_length         Fetch with Length                         Y
48  * fetch_chunked        Fetch chunked                             Y
49  * fetch_eof            Fetch EOF                                 Y
50  * fetch_bad            Fetch had bad headers                     Y
51  * fetch_close          Fetch wanted close                        Y
52  * fetch_oldhttp        Fetch pre HTTP/1.1 closed                 Y
53  * fetch_zero           Fetch zero len                            Y
54  * fetch_failed         Fetch failed                              Y
55  * n_sess_mem           N struct sess_mem                         N
56  * n_sess               N struct sess                             N
57  * n_object             N struct object                           N
58  * n_vampireobject      N unresurrected objects                   N
59  * n_objectcore         N struct objectcore                       N
60  * n_objecthead         N struct objecthead                       N
61  * n_smf                N struct smf                              N
62  * n_smf_frag           N small free smf                          N
63  * n_smf_large          N large free smf                          N
64  * n_vbe_conn           N struct vbe_conn                         N
65  * n_wrk                N worker threads                          Y
66  * n_wrk_create         N worker threads created                  Y
67  * n_wrk_failed         N worker threads not created              Y
68  * n_wrk_max            N worker threads limited                  Y
69  * n_wrk_queue          N queued work requests                    Y
70  * n_wrk_overflow       N overflowed work requests                Y
71  * n_wrk_drop           N dropped work requests                   Y
72  * n_backend            N backends                                N
73  * n_expired            N expired objects                         N
74  * n_lru_nuked          N LRU nuked objects                       N
75  * n_lru_saved          N LRU saved objects                       N
76  * n_lru_moved          N LRU moved objects                       N
77  * n_deathrow           N objects on deathrow                     N
78  * losthdr              HTTP header overflows                     N
79  * n_objsendfile        Objects sent with sendfile                N
80  * n_objwrite           Objects sent with write                   N
81  * n_objoverflow        Objects overflowing workspace             N
82  * s_sess               Total Sessions                            Y
83  * s_req                Total Requests                            Y
84  * s_pipe               Total pipe                                Y
85  * s_pass               Total pass                                Y
86  * s_fetch              Total fetch                               Y
87  * s_hdrbytes           Total header bytes                        Y
88  * s_bodybytes          Total body bytes                          Y
89  * sess_closed          Session Closed                            N
90  * sess_pipeline        Session Pipeline                          N
91  * sess_readahead       Session Read Ahead                        N
92  * sess_linger          Session Linger                            N
93  * sess_herd            Session herd                              N
94  * shm_records          SHM records                               Y
95  * shm_writes           SHM writes                                Y
96  * shm_flushes          SHM flushes due to overflow               Y
97  * shm_cont             SHM MTX contention                        Y
98  * shm_cycles           SHM cycles through buffer                 Y
99  * sm_nreq              allocator requests                        Y
100  * sm_nobj              outstanding allocations                   Y
101  * sm_balloc            bytes allocated                           Y
102  * sm_bfree             bytes free                                Y
103  * sma_nreq             SMA allocator requests                    Y
104  * sma_nobj             SMA outstanding allocations               Y
105  * sma_nbytes           SMA outstanding bytes                     Y
106  * sma_balloc           SMA bytes allocated                       Y
107  * sma_bfree            SMA bytes free                            Y
108  * sms_nreq             SMS allocator requests                    Y
109  * sms_nobj             SMS outstanding allocations               Y
110  * sms_nbytes           SMS outstanding bytes                     Y
111  * sms_balloc           SMS bytes allocated                       Y
112  * sms_bfree            SMS bytes freed                           Y
113  * backend_req          Backend requests made                     N
114  * n_vcl                N vcl total                               N
115  * n_vcl_avail          N vcl available                           N
116  * n_vcl_discard        N vcl discarded                           N
117  * n_purge              N total active purges                     N
118  * n_purge_add          N new purges added                        N
119  * n_purge_retire       N old purges deleted                      N
120  * n_purge_obj_test     N objects tested                          N
121  * n_purge_re_test      N regexps tested against                  N
122  * n_purge_dups         N duplicate purges removed                N
123  * hcb_nolock           HCB Lookups without lock                  Y
124  * hcb_lock             HCB Lookups with lock                     Y
125  * hcb_insert           HCB Inserts                               Y
126  * esi_parse            Objects ESI parsed (unlock)               Y
127  * esi_errors           ESI parse errors (unlock)                 Y
128  * }}}
129  */
130 #include "collectd.h"
131 #include "common.h"
132 #include "plugin.h"
133 #include "configfile.h"
134
135 #include <varnish/varnishapi.h>
136
137 #if HAVE_VARNISH_V3
138 # include <varnish/vsc.h>
139 typedef struct VSC_C_main c_varnish_stats_t;
140 #endif
141
142 #if HAVE_VARNISH_V2
143 typedef struct varnish_stats c_varnish_stats_t;
144 #endif
145
146 /* {{{ user_config_s */
147 struct user_config_s {
148         char *instance;
149
150         _Bool collect_cache;
151         _Bool collect_connections;
152         _Bool collect_esi;
153         _Bool collect_backend;
154         _Bool collect_fetch;
155         _Bool collect_hcb;
156         _Bool collect_shm;
157         _Bool collect_sms;
158 #if HAVE_VARNISH_V2
159         _Bool collect_sm;
160         _Bool collect_sma;
161 #endif
162         _Bool collect_totals;
163         _Bool collect_workers;
164 };
165 typedef struct user_config_s user_config_t; /* }}} */
166
167 static _Bool have_instance = 0;
168
169 static int varnish_submit (const char *plugin_instance, /* {{{ */
170                 const char *category, const char *type, const char *type_instance, value_t value)
171 {
172         value_list_t vl = VALUE_LIST_INIT;
173
174         vl.values = &value;
175         vl.values_len = 1;
176
177         sstrncpy (vl.host, hostname_g, sizeof (vl.host));
178
179         sstrncpy (vl.plugin, "varnish", sizeof (vl.plugin));
180
181         if (plugin_instance == NULL)
182                 plugin_instance = "default";
183
184         ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance),
185                 "%s-%s", plugin_instance, category);
186
187         sstrncpy (vl.type, type, sizeof (vl.type));
188
189         if (type_instance != NULL)
190                 sstrncpy (vl.type_instance, type_instance,
191                                 sizeof (vl.type_instance));
192
193         return (plugin_dispatch_values (&vl));
194 } /* }}} int varnish_submit */
195
196 static int varnish_submit_gauge (const char *plugin_instance, /* {{{ */
197                 const char *category, const char *type, const char *type_instance,
198                 uint64_t gauge_value)
199 {
200         value_t value;
201
202         value.gauge = (gauge_t) gauge_value;
203
204         return (varnish_submit (plugin_instance, category, type, type_instance, value));
205 } /* }}} int varnish_submit_gauge */
206
207 static int varnish_submit_derive (const char *plugin_instance, /* {{{ */
208                 const char *category, const char *type, const char *type_instance,
209                 uint64_t derive_value)
210 {
211         value_t value;
212
213         value.derive = (derive_t) derive_value;
214
215         return (varnish_submit (plugin_instance, category, type, type_instance, value));
216 } /* }}} int varnish_submit_derive */
217
218 static void varnish_monitor (const user_config_t *conf, /* {{{ */
219                 const c_varnish_stats_t *stats)
220 {
221         if (conf->collect_cache)
222         {
223                 /* Cache hits */
224                 varnish_submit_derive (conf->instance, "cache", "cache_result", "hit",     stats->cache_hit);
225                 /* Cache misses */
226                 varnish_submit_derive (conf->instance, "cache", "cache_result", "miss",    stats->cache_miss);
227                 /* Cache hits for pass */
228                 varnish_submit_derive (conf->instance, "cache", "cache_result", "hitpass", stats->cache_hitpass);
229         }
230
231         if (conf->collect_connections)
232         {
233                 /* Client connections accepted */
234                 varnish_submit_derive (conf->instance, "connections", "connections", "accepted", stats->client_conn);
235                 /* Connection dropped, no sess */
236                 varnish_submit_derive (conf->instance, "connections", "connections", "dropped" , stats->client_drop);
237                 /* Client requests received    */
238                 varnish_submit_derive (conf->instance, "connections", "connections", "received", stats->client_req);
239         }
240
241         if (conf->collect_esi)
242         {
243                 /* ESI parse errors (unlock)   */
244                 varnish_submit_derive (conf->instance, "esi", "total_operations", "error",  stats->esi_errors);
245 #if HAVE_VARNISH_V2
246                 /* Objects ESI parsed (unlock) */
247                 varnish_submit_derive (conf->instance, "esi", "total_operations", "parsed", stats->esi_parse);
248 #endif
249         }
250
251         if (conf->collect_backend)
252         {
253                 /* Backend conn. success       */
254                 varnish_submit_derive (conf->instance, "backend", "connections", "success"      , stats->backend_conn);
255                 /* Backend conn. not attempted */
256                 varnish_submit_derive (conf->instance, "backend", "connections", "not-attempted", stats->backend_unhealthy);
257                 /* Backend conn. too many      */
258                 varnish_submit_derive (conf->instance, "backend", "connections", "too-many"     , stats->backend_busy);
259                 /* Backend conn. failures      */
260                 varnish_submit_derive (conf->instance, "backend", "connections", "failures"     , stats->backend_fail);
261                 /* Backend conn. reuses        */
262                 varnish_submit_derive (conf->instance, "backend", "connections", "reuses"       , stats->backend_reuse);
263                 /* Backend conn. was closed    */
264                 varnish_submit_derive (conf->instance, "backend", "connections", "was-closed"   , stats->backend_toolate);
265                 /* Backend conn. recycles      */
266                 varnish_submit_derive (conf->instance, "backend", "connections", "recycled"     , stats->backend_recycle);
267 #if HAVE_VARNISH_V2
268                 /* Backend conn. unused        */
269                 varnish_submit_derive (conf->instance, "backend", "connections", "unused"       , stats->backend_unused);
270 #endif
271         }
272
273         if (conf->collect_fetch)
274         {
275                 /* Fetch head                */
276                 varnish_submit_derive (conf->instance, "fetch", "http_requests", "head"       , stats->fetch_head);
277                 /* Fetch with length         */
278                 varnish_submit_derive (conf->instance, "fetch", "http_requests", "length"     , stats->fetch_length);
279                 /* Fetch chunked             */
280                 varnish_submit_derive (conf->instance, "fetch", "http_requests", "chunked"    , stats->fetch_chunked);
281                 /* Fetch EOF                 */
282                 varnish_submit_derive (conf->instance, "fetch", "http_requests", "eof"        , stats->fetch_eof);
283                 /* Fetch bad headers         */
284                 varnish_submit_derive (conf->instance, "fetch", "http_requests", "bad_headers", stats->fetch_bad);
285                 /* Fetch wanted close        */
286                 varnish_submit_derive (conf->instance, "fetch", "http_requests", "close"      , stats->fetch_close);
287                 /* Fetch pre HTTP/1.1 closed */
288                 varnish_submit_derive (conf->instance, "fetch", "http_requests", "oldhttp"    , stats->fetch_oldhttp);
289                 /* Fetch zero len            */
290                 varnish_submit_derive (conf->instance, "fetch", "http_requests", "zero"       , stats->fetch_zero);
291                 /* Fetch failed              */
292                 varnish_submit_derive (conf->instance, "fetch", "http_requests", "failed"     , stats->fetch_failed);
293         }
294
295         if (conf->collect_hcb)
296         {
297                 /* HCB Lookups without lock */
298                 varnish_submit_derive (conf->instance, "hcb", "cache_operation", "lookup_nolock", stats->hcb_nolock);
299                 /* HCB Lookups with lock    */
300                 varnish_submit_derive (conf->instance, "hcb", "cache_operation", "lookup_lock",   stats->hcb_lock);
301                 /* HCB Inserts              */
302                 varnish_submit_derive (conf->instance, "hcb", "cache_operation", "insert",        stats->hcb_insert);
303         }
304
305         if (conf->collect_shm)
306         {
307                 /* SHM records                 */
308                 varnish_submit_derive (conf->instance, "shm", "total_operations", "records"   , stats->shm_records);
309                 /* SHM writes                  */
310                 varnish_submit_derive (conf->instance, "shm", "total_operations", "writes"    , stats->shm_writes);
311                 /* SHM flushes due to overflow */
312                 varnish_submit_derive (conf->instance, "shm", "total_operations", "flushes"   , stats->shm_flushes);
313                 /* SHM MTX contention          */
314                 varnish_submit_derive (conf->instance, "shm", "total_operations", "contention", stats->shm_cont);
315                 /* SHM cycles through buffer   */
316                 varnish_submit_derive (conf->instance, "shm", "total_operations", "cycles"    , stats->shm_cycles);
317         }
318
319 #if HAVE_VARNISH_V2
320         if (conf->collect_sm)
321         {
322                 /* allocator requests */
323                 varnish_submit_derive (conf->instance, "sm", "total_requests", "nreq",         stats->sm_nreq);
324                 /* outstanding allocations */
325                 varnish_submit_gauge (conf->instance,  "sm", "requests", "outstanding",        stats->sm_nobj);
326                 /* bytes allocated */
327                 varnish_submit_derive (conf->instance,  "sm", "total_bytes", "allocated",      stats->sm_balloc);
328                 /* bytes free */
329                 varnish_submit_derive (conf->instance,  "sm", "total_bytes", "free",           stats->sm_bfree);
330         }
331
332         if (conf->collect_sma)
333         {
334                 /* SMA allocator requests */
335                 varnish_submit_derive (conf->instance, "sma", "total_requests", "nreq",    stats->sma_nreq);
336                 /* SMA outstanding allocations */
337                 varnish_submit_gauge (conf->instance,  "sma", "requests", "outstanding",   stats->sma_nobj);
338                 /* SMA outstanding bytes */
339                 varnish_submit_gauge (conf->instance,  "sma", "bytes", "outstanding",      stats->sma_nbytes);
340                 /* SMA bytes allocated */
341                 varnish_submit_derive (conf->instance,  "sma", "total_bytes", "allocated", stats->sma_balloc);
342                 /* SMA bytes free */
343                 varnish_submit_derive (conf->instance,  "sma", "total_bytes", "free" ,     stats->sma_bfree);
344         }
345 #endif
346
347         if (conf->collect_sms)
348         {
349                 /* SMS allocator requests */
350                 varnish_submit_derive (conf->instance, "sms", "total_requests", "allocator", stats->sms_nreq);
351                 /* SMS outstanding allocations */
352                 varnish_submit_gauge (conf->instance,  "sms", "requests", "outstanding",     stats->sms_nobj);
353                 /* SMS outstanding bytes */
354                 varnish_submit_gauge (conf->instance,  "sms", "bytes", "outstanding",        stats->sms_nbytes);
355                 /* SMS bytes allocated */
356                 varnish_submit_derive (conf->instance,  "sms", "total_bytes", "allocated",   stats->sms_balloc);
357                 /* SMS bytes freed */
358                 varnish_submit_derive (conf->instance,  "sms", "total_bytes", "free",        stats->sms_bfree);
359         }
360
361         if (conf->collect_totals)
362         {
363                 /* Total Sessions */
364                 varnish_submit_derive (conf->instance, "totals", "total_sessions", "sessions",  stats->s_sess);
365                 /* Total Requests */
366                 varnish_submit_derive (conf->instance, "totals", "total_requests", "requests",  stats->s_req);
367                 /* Total pipe */
368                 varnish_submit_derive (conf->instance, "totals", "total_operations", "pipe",    stats->s_pipe);
369                 /* Total pass */
370                 varnish_submit_derive (conf->instance, "totals", "total_operations", "pass",    stats->s_pass);
371                 /* Total fetch */
372                 varnish_submit_derive (conf->instance, "totals", "total_operations", "fetches", stats->s_fetch);
373                 /* Total header bytes */
374                 varnish_submit_derive (conf->instance, "totals", "total_bytes", "header-bytes", stats->s_hdrbytes);
375                 /* Total body byte */
376                 varnish_submit_derive (conf->instance, "totals", "total_bytes", "body-bytes",   stats->s_bodybytes);
377         }
378
379         if (conf->collect_workers)
380         {
381                 /* worker threads */
382                 varnish_submit_gauge (conf->instance, "workers", "threads", "worker",             stats->n_wrk);
383                 /* worker threads created */
384                 varnish_submit_derive (conf->instance, "workers", "total_threads", "created",     stats->n_wrk_create);
385                 /* worker threads not created */
386                 varnish_submit_derive (conf->instance, "workers", "total_threads", "failed",      stats->n_wrk_failed);
387                 /* worker threads limited */
388                 varnish_submit_derive (conf->instance, "workers", "total_threads", "limited",     stats->n_wrk_max);
389                 /* dropped work requests */
390                 varnish_submit_derive (conf->instance, "workers", "total_requests", "dropped",    stats->n_wrk_drop);
391 #ifdef HAVE_VARNISH_V2
392                 /* queued work requests */
393                 varnish_submit_derive (conf->instance, "workers", "total_requests", "queued",     stats->n_wrk_queue);
394                 /* overflowed work requests */
395                 varnish_submit_derive (conf->instance, "workers", "total_requests", "overflowed", stats->n_wrk_overflow);
396 #endif
397         }
398 } /* }}} void varnish_monitor */
399
400 #if HAVE_VARNISH_V3
401 static int varnish_read (user_data_t *ud) /* {{{ */
402 {
403         struct VSM_data *vd;
404         const c_varnish_stats_t *stats;
405
406         user_config_t *conf;
407
408         if ((ud == NULL) || (ud->data == NULL))
409                 return (EINVAL);
410
411         conf = ud->data;
412
413         vd = VSM_New();
414         VSC_Setup(vd);
415         if (VSC_Open (vd, /* diag = */ 1))
416         {
417                 ERROR ("varnish plugin: Unable to load statistics.");
418
419                 return (-1);
420         }
421
422         stats = VSC_Main(vd);
423
424         varnish_monitor (conf, stats);
425         VSM_Close (vd);
426
427         return (0);
428 } /* }}} */
429 #else /* if HAVE_VARNISH_V2 */
430 static int varnish_read (user_data_t *ud) /* {{{ */
431 {
432         const c_varnish_stats_t *stats;
433
434         user_config_t *conf;
435
436         if ((ud == NULL) || (ud->data == NULL))
437                 return (EINVAL);
438
439         conf = ud->data;
440
441         stats = VSL_OpenStats (conf->instance);
442         if (stats == NULL)
443         {
444                 ERROR ("Varnish plugin : unable to load statistics");
445
446                 return (-1);
447         }
448
449         varnish_monitor (conf, stats);
450
451         return (0);
452 } /* }}} */
453 #endif
454
455 static void varnish_config_free (void *ptr) /* {{{ */
456 {
457         user_config_t *conf = ptr;
458
459         if (conf == NULL)
460                 return;
461
462         sfree (conf->instance);
463         sfree (conf);
464 } /* }}} */
465
466 static int varnish_config_apply_default (user_config_t *conf) /* {{{ */
467 {
468         if (conf == NULL)
469                 return (EINVAL);
470
471         conf->collect_backend     = 1;
472         conf->collect_cache       = 1;
473         conf->collect_connections = 1;
474         conf->collect_esi         = 0;
475         conf->collect_fetch       = 0;
476         conf->collect_hcb         = 0;
477         conf->collect_shm         = 1;
478 #if HAVE_VARNISH_V2
479         conf->collect_sm          = 0;
480         conf->collect_sma         = 0;
481 #endif
482         conf->collect_sms         = 0;
483         conf->collect_totals      = 0;
484
485         return (0);
486 } /* }}} int varnish_config_apply_default */
487
488 static int varnish_init (void) /* {{{ */
489 {
490         user_config_t *conf;
491         user_data_t ud;
492
493         if (have_instance)
494                 return (0);
495
496         conf = malloc (sizeof (*conf));
497         if (conf == NULL)
498                 return (ENOMEM);
499         memset (conf, 0, sizeof (*conf));
500
501         /* Default settings: */
502         conf->instance = NULL;
503
504         varnish_config_apply_default (conf);
505
506         ud.data = conf;
507         ud.free_func = varnish_config_free;
508
509         plugin_register_complex_read (/* group = */ "varnish",
510                         /* name      = */ "varnish/localhost",
511                         /* callback  = */ varnish_read,
512                         /* interval  = */ NULL,
513                         /* user data = */ &ud);
514
515         return (0);
516 } /* }}} int varnish_init */
517
518 static int varnish_config_instance (const oconfig_item_t *ci) /* {{{ */
519 {
520         user_config_t *conf;
521         user_data_t ud;
522         char callback_name[DATA_MAX_NAME_LEN];
523         int i;
524
525         conf = malloc (sizeof (*conf));
526         if (conf == NULL)
527                 return (ENOMEM);
528         memset (conf, 0, sizeof (*conf));
529         conf->instance = NULL;
530
531         varnish_config_apply_default (conf);
532
533         if (ci->values_num == 1)
534         {
535                 int status;
536
537                 status = cf_util_get_string (ci, &conf->instance);
538                 if (status != 0)
539                 {
540                         sfree (conf);
541                         return (status);
542                 }
543                 assert (conf->instance != NULL);
544
545                 if (strcmp ("localhost", conf->instance) == 0)
546                 {
547                         sfree (conf->instance);
548                         conf->instance = NULL;
549                 }
550         }
551         else if (ci->values_num > 1)
552         {
553                 WARNING ("Varnish plugin: \"Instance\" blocks accept only "
554                                 "one argument.");
555                 return (EINVAL);
556         }
557
558         for (i = 0; i < ci->children_num; i++)
559         {
560                 oconfig_item_t *child = ci->children + i;
561
562                 if (strcasecmp ("CollectCache", child->key) == 0)
563                         cf_util_get_boolean (child, &conf->collect_cache);
564                 else if (strcasecmp ("CollectConnections", child->key) == 0)
565                         cf_util_get_boolean (child, &conf->collect_connections);
566                 else if (strcasecmp ("CollectESI", child->key) == 0)
567                         cf_util_get_boolean (child, &conf->collect_esi);
568                 else if (strcasecmp ("CollectBackend", child->key) == 0)
569                         cf_util_get_boolean (child, &conf->collect_backend);
570                 else if (strcasecmp ("CollectFetch", child->key) == 0)
571                         cf_util_get_boolean (child, &conf->collect_fetch);
572                 else if (strcasecmp ("CollectHCB", child->key) == 0)
573                         cf_util_get_boolean (child, &conf->collect_hcb);
574                 else if (strcasecmp ("CollectSHM", child->key) == 0)
575                         cf_util_get_boolean (child, &conf->collect_shm);
576                 else if (strcasecmp ("CollectSMS", child->key) == 0)
577                         cf_util_get_boolean (child, &conf->collect_sms);
578 #if HAVE_VARNISH_V2
579                 else if (strcasecmp ("CollectSMA", child->key) == 0)
580                         cf_util_get_boolean (child, &conf->collect_sma);
581                 else if (strcasecmp ("CollectSM", child->key) == 0)
582                         cf_util_get_boolean (child, &conf->collect_sm);
583 #endif
584                 else if (strcasecmp ("CollectTotals", child->key) == 0)
585                         cf_util_get_boolean (child, &conf->collect_totals);
586                 else if (strcasecmp ("CollectWorkers", child->key) == 0)
587                         cf_util_get_boolean (child, &conf->collect_workers);
588                 else
589                 {
590                         WARNING ("Varnish plugin: Ignoring unknown "
591                                         "configuration option: \"%s\"",
592                                         child->key);
593                 }
594         }
595
596         if (!conf->collect_cache
597                         && !conf->collect_connections
598                         && !conf->collect_esi
599                         && !conf->collect_backend
600                         && !conf->collect_fetch
601                         && !conf->collect_hcb
602                         && !conf->collect_shm
603                         && !conf->collect_sms
604 #if HAVE_VARNISH_V2
605                         && !conf->collect_sma
606                         && !conf->collect_sm
607 #endif
608                         && !conf->collect_totals
609                         && !conf->collect_workers)
610         {
611                 WARNING ("Varnish plugin: No metric has been configured for "
612                                 "instance \"%s\". Disabling this instance.",
613                                 (conf->instance == NULL) ? "localhost" : conf->instance);
614                 return (EINVAL);
615         }
616
617         ssnprintf (callback_name, sizeof (callback_name), "varnish/%s",
618                         (conf->instance == NULL) ? "localhost" : conf->instance);
619
620         ud.data = conf;
621         ud.free_func = varnish_config_free;
622
623         plugin_register_complex_read (/* group = */ "varnish",
624                         /* name      = */ callback_name,
625                         /* callback  = */ varnish_read,
626                         /* interval  = */ NULL,
627                         /* user data = */ &ud);
628
629         have_instance = 1;
630
631         return (0);
632 } /* }}} int varnish_config_instance */
633
634 static int varnish_config (oconfig_item_t *ci) /* {{{ */
635 {
636         int i;
637
638         for (i = 0; i < ci->children_num; i++)
639         {
640                 oconfig_item_t *child = ci->children + i;
641
642                 if (strcasecmp ("Instance", child->key) == 0)
643                         varnish_config_instance (child);
644                 else
645                 {
646                         WARNING ("Varnish plugin: Ignoring unknown "
647                                         "configuration option: \"%s\"",
648                                         child->key);
649                 }
650         }
651
652         return (0);
653 } /* }}} int varnish_config */
654
655 void module_register (void) /* {{{ */
656 {
657         plugin_register_complex_config ("varnish", varnish_config);
658         plugin_register_init ("varnish", varnish_init);
659 } /* }}} */
660
661 /* vim: set sw=8 noet fdm=marker : */