WARNING("cpu plugin: sysctl: %s", STRERRNO);
return -1;
}
- /* #endif CAN_USE_SYSCTL */
+ /* #endif CAN_USE_SYSCTL */
#elif defined(HAVE_SYSCTLBYNAME)
/* Only on BSD varient */
"%i)",
numcpu);
#endif
- /* #endif HAVE_SYSCTLBYNAME */
+ /* #endif HAVE_SYSCTLBYNAME */
#elif defined(HAVE_LIBSTATGRAB)
-/* nothing to initialize */
-/* #endif HAVE_LIBSTATGRAB */
+ /* nothing to initialize */
+ /* #endif HAVE_LIBSTATGRAB */
#elif defined(HAVE_PERFSTAT)
/* nothing to initialize */
submit_value(cpu_num, cpu_state, "percent", (value_t){.gauge = value});
}
-static void submit_derive(int cpu_num, int cpu_state, derive_t value) {
- submit_value(cpu_num, cpu_state, "cpu", (value_t){.derive = value});
-}
-
/* Takes the zero-index number of a CPU and makes sure that the module-global
* cpu_states buffer is large enough. Returne ENOMEM on erorr. */
static int cpu_states_alloc(size_t cpu_num) /* {{{ */
/* Commits the number of cores */
static void cpu_commit_num_cpu(gauge_t value) /* {{{ */
{
- value_list_t vl = VALUE_LIST_INIT;
-
- vl.values = &(value_t){.gauge = value};
- vl.values_len = 1;
+ metric_family_t fam = {
+ .name = "cpu_count",
+ .type = VALUE_TYPE_GAUGE,
+ };
+ metric_family_metrics_append(&fam, (value_t){.gauge = value}, NULL, 0);
- sstrncpy(vl.plugin, "cpu", sizeof(vl.plugin));
- sstrncpy(vl.type, "count", sizeof(vl.type));
+ int status = plugin_dispatch_metric_family(&fam);
+ if (status != 0) {
+ ERROR("plugin_dispatch_metric_family failed: %s", STRERROR(status));
+ }
- plugin_dispatch_values(&vl);
+ metric_list_reset(&fam.metric);
+ return;
} /* }}} void cpu_commit_num_cpu */
/* Resets the internal aggregation. This is called by the read callback after
/* Legacy behavior: Dispatches the raw derive values without any aggregation. */
static void cpu_commit_without_aggregation(void) /* {{{ */
{
+ metric_family_t fam = {
+ .name = "cpu_usage_total",
+ .type = VALUE_TYPE_DERIVE,
+ };
for (int state = 0; state < COLLECTD_CPU_STATE_ACTIVE; state++) {
for (size_t cpu_num = 0; cpu_num < global_cpu_num; cpu_num++) {
cpu_state_t *s = get_cpu_state(cpu_num, state);
if (!s->has_value)
continue;
- submit_derive((int)cpu_num, (int)state, s->conv.last_value.derive);
+ char cpu_num_str[16];
+ snprintf(cpu_num_str, sizeof(cpu_num_str), "%zu", cpu_num);
+
+ label_t labels[] = {
+ {"cpu", cpu_num_str},
+ {"state", cpu_state_names[state]},
+ };
+
+ metric_family_metrics_append(
+ &fam, (value_t){.derive = s->conv.last_value.derive}, labels,
+ STATIC_ARRAY_SIZE(labels));
}
}
+
+ int status = plugin_dispatch_metric_family(&fam);
+ if (status != 0) {
+ ERROR("plugin_dispatch_metric_family failed: %s", STRERROR(status));
+ }
+
+ metric_list_reset(&fam.metric);
} /* }}} void cpu_commit_without_aggregation */
/* Aggregates the internal state and dispatches the metrics. */
cpu_stage(cpu, COLLECTD_CPU_STATE_IDLE,
(derive_t)cpu_info.cpu_ticks[CPU_STATE_IDLE], now);
}
- /* }}} #endif PROCESSOR_CPU_LOAD_INFO */
+ /* }}} #endif PROCESSOR_CPU_LOAD_INFO */
#elif defined(KERNEL_LINUX) /* {{{ */
int cpu;
cpu_stage(ksp[cpu]->ks_instance, COLLECTD_CPU_STATE_WAIT,
(derive_t)cs.cpu_sysinfo.cpu[CPU_WAIT], now);
}
- /* }}} #endif defined(HAVE_LIBKSTAT) */
+ /* }}} #endif defined(HAVE_LIBKSTAT) */
#elif CAN_USE_SYSCTL /* {{{ */
/* Only on (Open) BSD variant */
cpu_stage(i, COLLECTD_CPU_STATE_INTERRUPT, (derive_t)cpuinfo[i][CP_INTR],
now);
}
- /* }}} #endif CAN_USE_SYSCTL */
+ /* }}} #endif CAN_USE_SYSCTL */
#elif defined(HAVE_SYSCTLBYNAME) && defined(HAVE_SYSCTL_KERN_CP_TIMES) /* {{{ \
*/
cpu_stage(i, COLLECTD_CPU_STATE_INTERRUPT, (derive_t)cpuinfo[i][CP_INTR],
now);
}
- /* }}} #endif HAVE_SYSCTL_KERN_CP_TIMES */
+ /* }}} #endif HAVE_SYSCTL_KERN_CP_TIMES */
#elif defined(HAVE_SYSCTLBYNAME) /* {{{ */
/* Only on BSD variant */