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