varnish plugin: Closed VSM
[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 #if HAVE_VARNISH_V3
137         #include <varnish/vsc.h>
138     #define STAT_STRUCT VSC_C_main
139 #endif
140
141 #if HAVE_VARNISH_V2
142         #define STAT_STRUCT VSL_stats
143 #endif
144
145 /* {{{ user_config_s */
146 struct user_config_s {
147         char *instance;
148
149         _Bool collect_cache;
150         _Bool collect_connections;
151         _Bool collect_esi;
152         _Bool collect_backend;
153         _Bool collect_fetch;
154         _Bool collect_hcb;
155         _Bool collect_shm;
156         _Bool collect_sms;
157 #if HAVE_VARNISH_V2
158         _Bool collect_sm;
159         _Bool collect_sma;
160 #endif
161         _Bool collect_totals;
162         _Bool collect_workers;
163 };
164 typedef struct user_config_s user_config_t; /* }}} */
165
166 static _Bool have_instance = 0;
167
168 static int varnish_submit (const char *plugin_instance, /* {{{ */
169                 const char *category, const char *type, const char *type_instance, value_t value)
170 {
171         value_list_t vl = VALUE_LIST_INIT;
172
173         vl.values = &value;
174         vl.values_len = 1;
175
176         sstrncpy (vl.host, hostname_g, sizeof (vl.host));
177
178         sstrncpy (vl.plugin, "varnish", sizeof (vl.plugin));
179
180         if (plugin_instance == NULL)
181                 plugin_instance = "default";
182
183         ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance),
184                 "%s-%s", plugin_instance, category);
185
186         sstrncpy (vl.type, type, sizeof (vl.type));
187
188         if (type_instance != NULL)
189                 sstrncpy (vl.type_instance, type_instance,
190                                 sizeof (vl.type_instance));
191
192         return (plugin_dispatch_values (&vl));
193 } /* }}} int varnish_submit */
194
195 static int varnish_submit_gauge (const char *plugin_instance, /* {{{ */
196                 const char *category, const char *type, const char *type_instance,
197                 uint64_t gauge_value)
198 {
199         value_t value;
200
201         value.gauge = (gauge_t) gauge_value;
202
203         return (varnish_submit (plugin_instance, category, type, type_instance, value));
204 } /* }}} int varnish_submit_gauge */
205
206 static int varnish_submit_derive (const char *plugin_instance, /* {{{ */
207                 const char *category, const char *type, const char *type_instance,
208                 uint64_t derive_value)
209 {
210         value_t value;
211
212         value.derive = (derive_t) derive_value;
213
214         return (varnish_submit (plugin_instance, category, type, type_instance, value));
215 } /* }}} int varnish_submit_derive */
216
217 #if HAVE_VARNISH_V2
218 static void varnish_monitor (const user_config_t *conf, struct varnish_stats *VSL_stats) /* {{{ */
219 #endif
220 #if HAVE_VARNISH_V3
221 static void varnish_monitor (const user_config_t *conf, const struct VSC_C_main *VSC_C_main)
222 #endif
223 {
224         if (conf->collect_cache)
225         {
226                 /* Cache hits */
227                 varnish_submit_derive (conf->instance, "cache", "cache_result", "hit",     STAT_STRUCT->cache_hit);
228                 /* Cache misses */
229                 varnish_submit_derive (conf->instance, "cache", "cache_result", "miss",    STAT_STRUCT->cache_miss);
230                 /* Cache hits for pass */
231                 varnish_submit_derive (conf->instance, "cache", "cache_result", "hitpass", STAT_STRUCT->cache_hitpass);
232         }
233
234         if (conf->collect_connections)
235         {
236                 /* Client connections accepted */
237                 varnish_submit_derive (conf->instance, "connections", "connections", "accepted", STAT_STRUCT->client_conn);
238                 /* Connection dropped, no sess */
239                 varnish_submit_derive (conf->instance, "connections", "connections", "dropped" , STAT_STRUCT->client_drop);
240                 /* Client requests received    */
241                 varnish_submit_derive (conf->instance, "connections", "connections", "received", STAT_STRUCT->client_req);
242         }
243
244         if (conf->collect_esi)
245         {
246 #if HAVE_VARNISH_V2
247                 /* Objects ESI parsed (unlock) */
248                 varnish_submit_derive (conf->instance, "esi", "total_operations", "parsed", STAT_STRUCT->esi_parse);
249 #endif
250                 /* ESI parse errors (unlock)   */
251                 varnish_submit_derive (conf->instance, "esi", "total_operations", "error",  STAT_STRUCT->esi_errors);
252         }
253
254         if (conf->collect_backend)
255         {
256                 /* Backend conn. success       */
257                 varnish_submit_derive (conf->instance, "backend", "connections", "success"      , STAT_STRUCT->backend_conn);
258                 /* Backend conn. not attempted */
259                 varnish_submit_derive (conf->instance, "backend", "connections", "not-attempted", STAT_STRUCT->backend_unhealthy);
260                 /* Backend conn. too many      */
261                 varnish_submit_derive (conf->instance, "backend", "connections", "too-many"     , STAT_STRUCT->backend_busy);
262                 /* Backend conn. failures      */
263                 varnish_submit_derive (conf->instance, "backend", "connections", "failures"     , STAT_STRUCT->backend_fail);
264                 /* Backend conn. reuses        */
265                 varnish_submit_derive (conf->instance, "backend", "connections", "reuses"       , STAT_STRUCT->backend_reuse);
266                 /* Backend conn. was closed    */
267                 varnish_submit_derive (conf->instance, "backend", "connections", "was-closed"   , STAT_STRUCT->backend_toolate);
268                 /* Backend conn. recycles      */
269                 varnish_submit_derive (conf->instance, "backend", "connections", "recycled"     , STAT_STRUCT->backend_recycle);
270 #if HAVE_VARNISH_V2
271                 /* Backend conn. unused        */
272                 varnish_submit_derive (conf->instance, "backend", "connections", "unused"       , STAT_STRUCT->backend_unused);
273 #endif
274         }
275
276         if (conf->collect_fetch)
277         {
278                 /* Fetch head                */
279                 varnish_submit_derive (conf->instance, "fetch", "http_requests", "head"       , STAT_STRUCT->fetch_head);
280                 /* Fetch with length         */
281                 varnish_submit_derive (conf->instance, "fetch", "http_requests", "length"     , STAT_STRUCT->fetch_length);
282                 /* Fetch chunked             */
283                 varnish_submit_derive (conf->instance, "fetch", "http_requests", "chunked"    , STAT_STRUCT->fetch_chunked);
284                 /* Fetch EOF                 */
285                 varnish_submit_derive (conf->instance, "fetch", "http_requests", "eof"        , STAT_STRUCT->fetch_eof);
286                 /* Fetch bad headers         */
287                 varnish_submit_derive (conf->instance, "fetch", "http_requests", "bad_headers", STAT_STRUCT->fetch_bad);
288                 /* Fetch wanted close        */
289                 varnish_submit_derive (conf->instance, "fetch", "http_requests", "close"      , STAT_STRUCT->fetch_close);
290                 /* Fetch pre HTTP/1.1 closed */
291                 varnish_submit_derive (conf->instance, "fetch", "http_requests", "oldhttp"    , STAT_STRUCT->fetch_oldhttp);
292                 /* Fetch zero len            */
293                 varnish_submit_derive (conf->instance, "fetch", "http_requests", "zero"       , STAT_STRUCT->fetch_zero);
294                 /* Fetch failed              */
295                 varnish_submit_derive (conf->instance, "fetch", "http_requests", "failed"     , STAT_STRUCT->fetch_failed);
296         }
297
298         if (conf->collect_hcb)
299         {
300                 /* HCB Lookups without lock */
301                 varnish_submit_derive (conf->instance, "hcb", "cache_operation", "lookup_nolock", STAT_STRUCT->hcb_nolock);
302                 /* HCB Lookups with lock    */
303                 varnish_submit_derive (conf->instance, "hcb", "cache_operation", "lookup_lock",   STAT_STRUCT->hcb_lock);
304                 /* HCB Inserts              */
305                 varnish_submit_derive (conf->instance, "hcb", "cache_operation", "insert",        STAT_STRUCT->hcb_insert);
306         }
307
308         if (conf->collect_shm)
309         {
310                 /* SHM records                 */
311                 varnish_submit_derive (conf->instance, "shm", "total_operations", "records"   , STAT_STRUCT->shm_records);
312                 /* SHM writes                  */
313                 varnish_submit_derive (conf->instance, "shm", "total_operations", "writes"    , STAT_STRUCT->shm_writes);
314                 /* SHM flushes due to overflow */
315                 varnish_submit_derive (conf->instance, "shm", "total_operations", "flushes"   , STAT_STRUCT->shm_flushes);
316                 /* SHM MTX contention          */
317                 varnish_submit_derive (conf->instance, "shm", "total_operations", "contention", STAT_STRUCT->shm_cont);
318                 /* SHM cycles through buffer   */
319                 varnish_submit_derive (conf->instance, "shm", "total_operations", "cycles"    , STAT_STRUCT->shm_cycles);
320         }
321
322 #if HAVE_VARNISH_V2
323         if (conf->collect_sm)
324         {
325                 /* allocator requests */
326                 varnish_submit_derive (conf->instance, "sm", "total_requests", "nreq",  STAT_STRUCT->sm_nreq);
327                 /* outstanding allocations */
328                 varnish_submit_gauge (conf->instance,  "sm", "requests", "outstanding", STAT_STRUCT->sm_nobj);
329                 /* bytes allocated */
330                 varnish_submit_derive (conf->instance,  "sm", "total_bytes", "allocated",      STAT_STRUCT->sm_balloc);
331                 /* bytes free */
332                 varnish_submit_derive (conf->instance,  "sm", "total_bytes", "free",           STAT_STRUCT->sm_bfree);
333         }
334
335         if (conf->collect_sma)
336         {
337                 /* SMA allocator requests */
338                 varnish_submit_derive (conf->instance, "sma", "total_requests", "nreq",  STAT_STRUCT->sma_nreq);
339                 /* SMA outstanding allocations */
340                 varnish_submit_gauge (conf->instance,  "sma", "requests", "outstanding", STAT_STRUCT->sma_nobj);
341                 /* SMA outstanding bytes */
342                 varnish_submit_gauge (conf->instance,  "sma", "bytes", "outstanding",    STAT_STRUCT->sma_nbytes);
343                 /* SMA bytes allocated */
344                 varnish_submit_derive (conf->instance,  "sma", "total_bytes", "allocated",      STAT_STRUCT->sma_balloc);
345                 /* SMA bytes free */
346                 varnish_submit_derive (conf->instance,  "sma", "total_bytes", "free" ,          STAT_STRUCT->sma_bfree);
347         }
348 #endif
349
350         if (conf->collect_sms)
351         {
352                 /* SMS allocator requests */
353                 varnish_submit_derive (conf->instance, "sms", "total_requests", "allocator", STAT_STRUCT->sms_nreq);
354                 /* SMS outstanding allocations */
355                 varnish_submit_gauge (conf->instance,  "sms", "requests", "outstanding",     STAT_STRUCT->sms_nobj);
356                 /* SMS outstanding bytes */
357                 varnish_submit_gauge (conf->instance,  "sms", "bytes", "outstanding",        STAT_STRUCT->sms_nbytes);
358                 /* SMS bytes allocated */
359                 varnish_submit_derive (conf->instance,  "sms", "total_bytes", "allocated",          STAT_STRUCT->sms_balloc);
360                 /* SMS bytes freed */
361                 varnish_submit_derive (conf->instance,  "sms", "total_bytes", "free",               STAT_STRUCT->sms_bfree);
362         }
363
364         if (conf->collect_totals)
365         {
366                 /* Total Sessions */
367                 varnish_submit_derive (conf->instance, "totals", "total_sessions", "sessions",  STAT_STRUCT->s_sess);
368                 /* Total Requests */
369                 varnish_submit_derive (conf->instance, "totals", "total_requests", "requests",  STAT_STRUCT->s_req);
370                 /* Total pipe */
371                 varnish_submit_derive (conf->instance, "totals", "total_operations", "pipe",    STAT_STRUCT->s_pipe);
372                 /* Total pass */
373                 varnish_submit_derive (conf->instance, "totals", "total_operations", "pass",    STAT_STRUCT->s_pass);
374                 /* Total fetch */
375                 varnish_submit_derive (conf->instance, "totals", "total_operations", "fetches", STAT_STRUCT->s_fetch);
376                 /* Total header bytes */
377                 varnish_submit_derive (conf->instance, "totals", "total_bytes", "header-bytes", STAT_STRUCT->s_hdrbytes);
378                 /* Total body byte */
379                 varnish_submit_derive (conf->instance, "totals", "total_bytes", "body-bytes",   STAT_STRUCT->s_bodybytes);
380         }
381
382         if (conf->collect_workers)
383         {
384                 /* worker threads */
385                 varnish_submit_gauge (conf->instance, "workers", "threads", "worker",            STAT_STRUCT->n_wrk);
386                 /* worker threads created */
387                 varnish_submit_derive (conf->instance, "workers", "total_threads", "created",     STAT_STRUCT->n_wrk_create);
388                 /* worker threads not created */
389                 varnish_submit_derive (conf->instance, "workers", "total_threads", "failed",      STAT_STRUCT->n_wrk_failed);
390                 /* worker threads limited */
391                 varnish_submit_derive (conf->instance, "workers", "total_threads", "limited",     STAT_STRUCT->n_wrk_max);
392 #ifdef HAVE_VARNISH_V2
393                 /* queued work requests */
394                 varnish_submit_derive (conf->instance, "workers", "total_requests", "queued",     STAT_STRUCT->n_wrk_queue);
395                 /* overflowed work requests */
396                 varnish_submit_derive (conf->instance, "workers", "total_requests", "overflowed", STAT_STRUCT->n_wrk_overflow);
397 #endif
398                 /* dropped work requests */
399                 varnish_submit_derive (conf->instance, "workers", "total_requests", "dropped",    STAT_STRUCT->n_wrk_drop);
400         }
401 } /* }}} void varnish_monitor */
402
403 static int varnish_read (user_data_t *ud) /* {{{ */
404 {
405 #ifdef HAVE_VARNISH_V2
406         struct varnish_stats *VSL_stats;
407 #endif
408
409 #ifdef HAVE_VARNISH_V3
410     struct VSM_data *vd;
411         const struct VSC_C_main *VSC_C_main;
412 #endif
413
414         user_config_t *conf;
415
416         if ((ud == NULL) || (ud->data == NULL))
417                 return (EINVAL);
418
419         conf = ud->data;
420
421 #ifdef HAVE_VARNISH_V2
422         VSL_stats = VSL_OpenStats (conf->instance);
423         if (VSL_stats == NULL)
424         {
425                 ERROR ("Varnish plugin : unable to load statistics");
426
427                 return (-1);
428         }
429
430         varnish_monitor (conf, VSL_stats);
431 #endif
432
433 #ifdef HAVE_VARNISH_V3
434         vd = VSM_New();
435         VSC_Setup(vd);
436         if (VSC_Open(vd, 1))
437         {
438                 ERROR ("Varnish plugin : unable to load statistics");
439
440                 return (-1);
441         }
442
443         VSC_C_main = VSC_Main(vd);
444
445         varnish_monitor (conf, VSC_C_main);
446         VSM_Close(vd);
447 #endif
448
449     return (0);
450 } /* }}} */
451
452 static void varnish_config_free (void *ptr) /* {{{ */
453 {
454         user_config_t *conf = ptr;
455
456         if (conf == NULL)
457                 return;
458
459         sfree (conf->instance);
460         sfree (conf);
461 } /* }}} */
462
463 static int varnish_config_apply_default (user_config_t *conf) /* {{{ */
464 {
465         if (conf == NULL)
466                 return (EINVAL);
467
468         conf->collect_backend     = 1;
469         conf->collect_cache       = 1;
470         conf->collect_connections = 1;
471         conf->collect_esi         = 0;
472         conf->collect_fetch       = 0;
473         conf->collect_hcb         = 0;
474         conf->collect_shm         = 1;
475 #if HAVE_VARNISH_V2
476         conf->collect_sm          = 0;
477         conf->collect_sma         = 0;
478 #endif
479         conf->collect_sms         = 0;
480         conf->collect_totals      = 0;
481
482         return (0);
483 } /* }}} int varnish_config_apply_default */
484
485 static int varnish_init (void) /* {{{ */
486 {
487         user_config_t *conf;
488         user_data_t ud;
489
490         if (have_instance)
491                 return (0);
492
493         conf = malloc (sizeof (*conf));
494         if (conf == NULL)
495                 return (ENOMEM);
496         memset (conf, 0, sizeof (*conf));
497
498         /* Default settings: */
499         conf->instance = NULL;
500
501         varnish_config_apply_default (conf);
502
503         ud.data = conf;
504         ud.free_func = varnish_config_free;
505
506         plugin_register_complex_read (/* group = */ "varnish",
507                         /* name      = */ "varnish/localhost",
508                         /* callback  = */ varnish_read,
509                         /* interval  = */ NULL,
510                         /* user data = */ &ud);
511
512         return (0);
513 } /* }}} int varnish_init */
514
515 static int varnish_config_instance (const oconfig_item_t *ci) /* {{{ */
516 {
517         user_config_t *conf;
518         user_data_t ud;
519         char callback_name[DATA_MAX_NAME_LEN];
520         int i;
521
522         conf = malloc (sizeof (*conf));
523         if (conf == NULL)
524                 return (ENOMEM);
525         memset (conf, 0, sizeof (*conf));
526         conf->instance = NULL;
527
528         varnish_config_apply_default (conf);
529
530         if (ci->values_num == 1)
531         {
532                 int status;
533
534                 status = cf_util_get_string (ci, &conf->instance);
535                 if (status != 0)
536                 {
537                         sfree (conf);
538                         return (status);
539                 }
540                 assert (conf->instance != NULL);
541
542                 if (strcmp ("localhost", conf->instance) == 0)
543                 {
544                         sfree (conf->instance);
545                         conf->instance = NULL;
546                 }
547         }
548         else if (ci->values_num > 1)
549         {
550                 WARNING ("Varnish plugin: \"Instance\" blocks accept only "
551                                 "one argument.");
552                 return (EINVAL);
553         }
554
555         for (i = 0; i < ci->children_num; i++)
556         {
557                 oconfig_item_t *child = ci->children + i;
558
559                 if (strcasecmp ("CollectCache", child->key) == 0)
560                         cf_util_get_boolean (child, &conf->collect_cache);
561                 else if (strcasecmp ("CollectConnections", child->key) == 0)
562                         cf_util_get_boolean (child, &conf->collect_connections);
563                 else if (strcasecmp ("CollectESI", child->key) == 0)
564                         cf_util_get_boolean (child, &conf->collect_esi);
565                 else if (strcasecmp ("CollectBackend", child->key) == 0)
566                         cf_util_get_boolean (child, &conf->collect_backend);
567                 else if (strcasecmp ("CollectFetch", child->key) == 0)
568                         cf_util_get_boolean (child, &conf->collect_fetch);
569                 else if (strcasecmp ("CollectHCB", child->key) == 0)
570                         cf_util_get_boolean (child, &conf->collect_hcb);
571                 else if (strcasecmp ("CollectSHM", child->key) == 0)
572                         cf_util_get_boolean (child, &conf->collect_shm);
573                 else if (strcasecmp ("CollectSMS", child->key) == 0)
574                         cf_util_get_boolean (child, &conf->collect_sms);
575 #if HAVE_VARNISH_V2
576                 else if (strcasecmp ("CollectSMA", child->key) == 0)
577                         cf_util_get_boolean (child, &conf->collect_sma);
578                 else if (strcasecmp ("CollectSM", child->key) == 0)
579                         cf_util_get_boolean (child, &conf->collect_sm);
580 #endif
581                 else if (strcasecmp ("CollectTotals", child->key) == 0)
582                         cf_util_get_boolean (child, &conf->collect_totals);
583                 else if (strcasecmp ("CollectWorkers", child->key) == 0)
584                         cf_util_get_boolean (child, &conf->collect_workers);
585                 else
586                 {
587                         WARNING ("Varnish plugin: Ignoring unknown "
588                                         "configuration option: \"%s\"",
589                                         child->key);
590                 }
591         }
592
593         if (!conf->collect_cache
594                         && !conf->collect_connections
595                         && !conf->collect_esi
596                         && !conf->collect_backend
597                         && !conf->collect_fetch
598                         && !conf->collect_hcb
599                         && !conf->collect_shm
600                         && !conf->collect_sms
601 #if HAVE_VARNISH_V2
602                         && !conf->collect_sma
603                         && !conf->collect_sm
604 #endif
605                         && !conf->collect_totals
606                         && !conf->collect_workers)
607         {
608                 WARNING ("Varnish plugin: No metric has been configured for "
609                                 "instance \"%s\". Disabling this instance.",
610                                 (conf->instance == NULL) ? "localhost" : conf->instance);
611                 return (EINVAL);
612         }
613
614         ssnprintf (callback_name, sizeof (callback_name), "varnish/%s",
615                         (conf->instance == NULL) ? "localhost" : conf->instance);
616
617         ud.data = conf;
618         ud.free_func = varnish_config_free;
619
620         plugin_register_complex_read (/* group = */ "varnish",
621                         /* name      = */ callback_name,
622                         /* callback  = */ varnish_read,
623                         /* interval  = */ NULL,
624                         /* user data = */ &ud);
625
626         have_instance = 1;
627
628         return (0);
629 } /* }}} int varnish_config_instance */
630
631 static int varnish_config (oconfig_item_t *ci) /* {{{ */
632 {
633         int i;
634
635         for (i = 0; i < ci->children_num; i++)
636         {
637                 oconfig_item_t *child = ci->children + i;
638
639                 if (strcasecmp ("Instance", child->key) == 0)
640                         varnish_config_instance (child);
641                 else
642                 {
643                         WARNING ("Varnish plugin: Ignoring unknown "
644                                         "configuration option: \"%s\"",
645                                         child->key);
646                 }
647         }
648
649         return (0);
650 } /* }}} int varnish_config */
651
652 void module_register (void) /* {{{ */
653 {
654         plugin_register_complex_config ("varnish", varnish_config);
655         plugin_register_init ("varnish", varnish_init);
656 } /* }}} */
657
658 /* vim: set sw=8 noet fdm=marker : */