return strcmp(rf->rf_group, (const char *)group);
} /* }}} int compare_read_func_group */
-static int metric_family_name(strbuf_t *buf, value_list_t const *vl,
- data_source_t const *dsrc) {
- int status = strbuf_print(buf, "collectd");
-
- if (strcmp(vl->plugin, vl->type) != 0) {
- status = status || strbuf_print(buf, "_");
- status = status || strbuf_print(buf, vl->plugin);
- }
-
- status = status || strbuf_print(buf, "_");
- status = status || strbuf_print(buf, vl->type);
-
- if (strcmp("value", dsrc->name) != 0) {
- status = status || strbuf_print(buf, "_");
- status = status || strbuf_print(buf, dsrc->name);
- }
-
- if ((dsrc->type == DS_TYPE_COUNTER) || (dsrc->type == DS_TYPE_DERIVE)) {
- status = status || strbuf_print(buf, "_total");
- }
-
- return status;
-}
-
-metric_family_t *plugin_value_list_to_metric_family(value_list_t const *vl,
- data_set_t const *ds,
- size_t index) {
- if ((vl == NULL) || (ds == NULL)) {
- errno = EINVAL;
- return NULL;
- }
-
- metric_family_t *fam = calloc(1, sizeof(*fam));
- if (fam == NULL) {
- return NULL;
- }
-
- data_source_t const *dsrc = ds->ds + index;
- strbuf_t name = STRBUF_CREATE;
- int status = metric_family_name(&name, vl, dsrc);
- if (status != 0) {
- STRBUF_DESTROY(name);
- metric_family_free(fam);
- errno = status;
- return NULL;
- }
- fam->name = name.ptr;
- name = (strbuf_t){0};
-
- fam->type =
- (dsrc->type == DS_TYPE_GAUGE) ? METRIC_TYPE_GAUGE : METRIC_TYPE_COUNTER;
-
- metric_t m = {
- .family = fam,
- .value = vl->values[index],
- .time = vl->time,
- .interval = vl->interval,
- };
-
- status = metric_label_set(&m, "instance",
- (strlen(vl->host) != 0) ? vl->host : hostname_g);
- if (strlen(vl->plugin_instance) != 0) {
- status = status || metric_label_set(&m, vl->plugin, vl->plugin_instance);
- }
- if (strlen(vl->type_instance) != 0) {
- char const *name = "type";
- if (strlen(vl->plugin_instance) == 0) {
- name = vl->plugin;
- }
- status = status || metric_label_set(&m, name, vl->type_instance);
- }
-
- status = status || metric_family_metric_append(fam, m);
- if (status != 0) {
- metric_reset(&m);
- metric_family_free(fam);
- errno = status;
- return NULL;
- }
-
- return fam;
-}
-
EXPORT int plugin_unregister_read_group(const char *group) /* {{{ */
{
llentry_t *le;
*/
void plugin_log_available_writers(void);
-/* plugin_value_list_to_metric_family converts a value in a value_list_t to a
- * metric_family_t. In case of error, errno is set and NULL is returned. The
- * returned pointer must be freed using metric_family_free(). */
-metric_family_t *plugin_value_list_to_metric_family(value_list_t const *vl,
- data_set_t const *ds,
- size_t index);
-
/*
* NAME
* plugin_dispatch_values
return fam->metric.ptr;
}
+static int metric_family_name(strbuf_t *buf, value_list_t const *vl,
+ data_source_t const *dsrc) {
+ int status = strbuf_print(buf, "collectd");
+
+ if (strcmp(vl->plugin, vl->type) != 0) {
+ status = status || strbuf_print(buf, "_");
+ status = status || strbuf_print(buf, vl->plugin);
+ }
+
+ status = status || strbuf_print(buf, "_");
+ status = status || strbuf_print(buf, vl->type);
+
+ if (strcmp("value", dsrc->name) != 0) {
+ status = status || strbuf_print(buf, "_");
+ status = status || strbuf_print(buf, dsrc->name);
+ }
+
+ if ((dsrc->type == DS_TYPE_COUNTER) || (dsrc->type == DS_TYPE_DERIVE)) {
+ status = status || strbuf_print(buf, "_total");
+ }
+
+ return status;
+}
+
+metric_family_t *plugin_value_list_to_metric_family(value_list_t const *vl,
+ data_set_t const *ds,
+ size_t index) {
+ if ((vl == NULL) || (ds == NULL)) {
+ errno = EINVAL;
+ return NULL;
+ }
+
+ metric_family_t *fam = calloc(1, sizeof(*fam));
+ if (fam == NULL) {
+ return NULL;
+ }
+
+ data_source_t const *dsrc = ds->ds + index;
+ strbuf_t name = STRBUF_CREATE;
+ int status = metric_family_name(&name, vl, dsrc);
+ if (status != 0) {
+ STRBUF_DESTROY(name);
+ metric_family_free(fam);
+ errno = status;
+ return NULL;
+ }
+ fam->name = name.ptr;
+ name = (strbuf_t){0};
+
+ fam->type =
+ (dsrc->type == DS_TYPE_GAUGE) ? METRIC_TYPE_GAUGE : METRIC_TYPE_COUNTER;
+
+ metric_t m = {
+ .family = fam,
+ .value = vl->values[index],
+ .time = vl->time,
+ .interval = vl->interval,
+ };
+
+ status = metric_label_set(&m, "instance",
+ (strlen(vl->host) != 0) ? vl->host : hostname_g);
+ if (strlen(vl->plugin_instance) != 0) {
+ status = status || metric_label_set(&m, vl->plugin, vl->plugin_instance);
+ }
+ if (strlen(vl->type_instance) != 0) {
+ char const *name = "type";
+ if (strlen(vl->plugin_instance) == 0) {
+ name = vl->plugin;
+ }
+ status = status || metric_label_set(&m, name, vl->type_instance);
+ }
+
+ status = status || metric_family_metric_append(fam, m);
+ if (status != 0) {
+ metric_reset(&m);
+ metric_family_free(fam);
+ errno = status;
+ return NULL;
+ }
+
+ return fam;
+}
+
int parse_value(const char *value_orig, value_t *ret_value, int ds_type) {
char *value;
char *endptr = NULL;
* "host/plugin/type" and converts it to a metric_t. */
metric_t *parse_legacy_identifier(char const *s);
+/* plugin_value_list_to_metric_family converts a value in a value_list_t to a
+ * metric_family_t. In case of error, errno is set and NULL is returned. The
+ * returned pointer must be freed using metric_family_free(). */
+metric_family_t *plugin_value_list_to_metric_family(value_list_t const *vl,
+ data_set_t const *ds,
+ size_t index);
+
int parse_value(const char *value, value_t *ret_value, int ds_type);
int parse_values(char *buffer, value_list_t *vl, const data_set_t *ds);