vl.values = &value;
vl.values_len = 1;
- sstrncpy(vl.host, hostname_g, sizeof(vl.host));
-
sstrncpy(vl.plugin, "varnish", sizeof(vl.plugin));
if (plugin_instance == NULL)
plugin_instance = "default";
-
- ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s-%s",
- plugin_instance, category);
+ snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s-%s",
+ plugin_instance, category);
sstrncpy(vl.type, type, sizeof(vl.type));
if (type_instance != NULL)
sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance));
- return (plugin_dispatch_values(&vl));
+ return plugin_dispatch_values(&vl);
} /* }}} int varnish_submit */
static int varnish_submit_gauge(const char *plugin_instance, /* {{{ */
const char *category, const char *type,
const char *type_instance,
uint64_t gauge_value) {
- value_t value;
-
- value.gauge = (gauge_t)gauge_value;
-
- return (
- varnish_submit(plugin_instance, category, type, type_instance, value));
+ return varnish_submit(plugin_instance, category, type, type_instance,
+ (value_t){
+ .gauge = (gauge_t)gauge_value,
+ });
} /* }}} int varnish_submit_gauge */
static int varnish_submit_derive(const char *plugin_instance, /* {{{ */
const char *category, const char *type,
const char *type_instance,
uint64_t derive_value) {
- value_t value;
-
- value.derive = (derive_t)derive_value;
-
- return (
- varnish_submit(plugin_instance, category, type, type_instance, value));
+ return varnish_submit(plugin_instance, category, type, type_instance,
+ (value_t){
+ .derive = (derive_t)derive_value,
+ });
} /* }}} int varnish_submit_derive */
#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
const char *name;
if (pt == NULL)
- return (0);
+ return 0;
conf = priv;
name = pt->desc->name;
if (strcmp(class, "MAIN") != 0)
- return (0);
+ return 0;
#elif HAVE_VARNISH_V3
class = pt->class;
name = pt->name;
if (strcmp(class, "") != 0)
- return (0);
+ return 0;
#endif
val = *(const volatile uint64_t *)pt->ptr;
}
#endif
- return (0);
+ return 0;
} /* }}} static int varnish_monitor */
#else /* if HAVE_VARNISH_V2 */
user_config_t *conf;
if ((ud == NULL) || (ud->data == NULL))
- return (EINVAL);
+ return EINVAL;
conf = ud->data;
ERROR("varnish plugin: VSM_n_Arg (\"%s\") failed "
"with status %i.",
conf->instance, status);
- return (-1);
+ return -1;
}
}
VSM_Delete(vd);
ERROR("varnish plugin: Unable to open connection.");
- return (-1);
+ return -1;
}
#if HAVE_VARNISH_V3
VSM_Delete(vd);
ERROR("varnish plugin: Unable to get statistics.");
- return (-1);
+ return -1;
}
#if HAVE_VARNISH_V3
#endif
VSM_Delete(vd);
- return (0);
+ return 0;
} /* }}} */
#else /* if HAVE_VARNISH_V2 */
static int varnish_read(user_data_t *ud) /* {{{ */
user_config_t *conf;
if ((ud == NULL) || (ud->data == NULL))
- return (EINVAL);
+ return EINVAL;
conf = ud->data;
if (stats == NULL) {
ERROR("Varnish plugin : unable to load statistics");
- return (-1);
+ return -1;
}
varnish_monitor(conf, stats);
- return (0);
+ return 0;
} /* }}} */
#endif
static int varnish_config_apply_default(user_config_t *conf) /* {{{ */
{
if (conf == NULL)
- return (EINVAL);
+ return EINVAL;
conf->collect_backend = 1;
conf->collect_cache = 1;
conf->collect_vsm = 0;
#endif
- return (0);
+ return 0;
} /* }}} int varnish_config_apply_default */
static int varnish_init(void) /* {{{ */
user_config_t *conf;
if (have_instance)
- return (0);
+ return 0;
conf = calloc(1, sizeof(*conf));
if (conf == NULL)
- return (ENOMEM);
+ return ENOMEM;
/* Default settings: */
conf->instance = NULL;
varnish_config_apply_default(conf);
- user_data_t ud = {.data = conf, .free_func = varnish_config_free};
-
- plugin_register_complex_read(/* group = */ "varnish",
- /* name = */ "varnish/localhost",
- /* callback = */ varnish_read,
- /* interval = */ 0,
- /* user data = */ &ud);
+ plugin_register_complex_read(
+ /* group = */ "varnish",
+ /* name = */ "varnish/localhost",
+ /* callback = */ varnish_read,
+ /* interval = */ 0,
+ &(user_data_t){
+ .data = conf, .free_func = varnish_config_free,
+ });
- return (0);
+ return 0;
} /* }}} int varnish_init */
static int varnish_config_instance(const oconfig_item_t *ci) /* {{{ */
{
user_config_t *conf;
- user_data_t ud;
char callback_name[DATA_MAX_NAME_LEN];
conf = calloc(1, sizeof(*conf));
if (conf == NULL)
- return (ENOMEM);
+ return ENOMEM;
conf->instance = NULL;
varnish_config_apply_default(conf);
status = cf_util_get_string(ci, &conf->instance);
if (status != 0) {
sfree(conf);
- return (status);
+ return status;
}
assert(conf->instance != NULL);
WARNING("Varnish plugin: \"Instance\" blocks accept only "
"one argument.");
sfree(conf);
- return (EINVAL);
+ return EINVAL;
}
for (int i = 0; i < ci->children_num; i++) {
"instance \"%s\". Disabling this instance.",
(conf->instance == NULL) ? "localhost" : conf->instance);
sfree(conf);
- return (EINVAL);
+ return EINVAL;
}
- ssnprintf(callback_name, sizeof(callback_name), "varnish/%s",
- (conf->instance == NULL) ? "localhost" : conf->instance);
+ snprintf(callback_name, sizeof(callback_name), "varnish/%s",
+ (conf->instance == NULL) ? "localhost" : conf->instance);
- ud.data = conf;
- ud.free_func = varnish_config_free;
-
- plugin_register_complex_read(/* group = */ "varnish",
- /* name = */ callback_name,
- /* callback = */ varnish_read,
- /* interval = */ 0,
- /* user data = */ &ud);
+ plugin_register_complex_read(
+ /* group = */ "varnish",
+ /* name = */ callback_name,
+ /* callback = */ varnish_read,
+ /* interval = */ 0,
+ &(user_data_t){
+ .data = conf, .free_func = varnish_config_free,
+ });
have_instance = 1;
- return (0);
+ return 0;
} /* }}} int varnish_config_instance */
static int varnish_config(oconfig_item_t *ci) /* {{{ */
}
}
- return (0);
+ return 0;
} /* }}} int varnish_config */
void module_register(void) /* {{{ */
plugin_register_complex_config("varnish", varnish_config);
plugin_register_init("varnish", varnish_init);
} /* }}} */
-
-/* vim: set sw=8 noet fdm=marker : */