[STATE_WAIT] = "wait", [STATE_ACTIVE] = "active",
};
+#define USAGE_UNAVAILABLE -1
+
typedef struct {
gauge_t rate;
bool has_rate;
} else {
size_t index = (cpu * STATE_MAX) + state;
if (index >= u->states_num) {
- return -1;
+ return NAN;
}
us = u->states[index];
}
} else {
size_t index = (cpu * STATE_MAX) + state;
if (index >= u->states_num) {
- return -1;
+ return USAGE_UNAVAILABLE;
}
us = u->states[index];
}
- return us.has_count ? us.count : -1;
+ return us.has_count ? us.count : USAGE_UNAVAILABLE;
}
/* Commits the number of cores */
if (report_by_state) {
for (state_t state = 0; state < STATE_ACTIVE; state++) {
derive_t usage = usage_count(u, cpu_num, state);
- if (usage == -1) {
+ if (usage == USAGE_UNAVAILABLE) {
continue;
}
metric_family_append(&fam, label_state, cpu_state_names[state],
}
} else {
derive_t usage = usage_count(u, cpu_num, STATE_ACTIVE);
- metric_family_append(&fam, label_state, cpu_state_names[STATE_ACTIVE],
- (value_t){.derive = usage}, &m);
+ if (usage != USAGE_UNAVAILABLE) {
+ metric_family_append(&fam, label_state, cpu_state_names[STATE_ACTIVE],
+ (value_t){.derive = usage}, &m);
+ }
}
int status = plugin_dispatch_metric_family(&fam);
if (!report_by_state) {
gauge_t ratio = usage_ratio(u, cpu_num, STATE_ACTIVE);
- metric_family_append(&fam, label_state, cpu_state_names[STATE_ACTIVE],
- (value_t){.gauge = ratio}, &m);
+ if (!isnan(ratio)) {
+ metric_family_append(&fam, label_state, cpu_state_names[STATE_ACTIVE],
+ (value_t){.gauge = ratio}, &m);
+ }
} else {
for (state_t state = 0; state < STATE_ACTIVE; state++) {
gauge_t ratio = usage_ratio(u, cpu_num, state);