Skip to content

Commit

Permalink
Merge pull request collectd#4219 from octo/6/memory
Browse files Browse the repository at this point in the history
[collectd 6] memory plugin: Align metrics with OpenTelemetry recommendations.
  • Loading branch information
octo committed Jan 3, 2024
2 parents ad5b7ea + 4616f83 commit e7dab5c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ static int memory_config(oconfig_item_t *ci) /* {{{ */
static int memory_dispatch(gauge_t values[COLLECTD_MEMORY_TYPE_MAX]) {
metric_family_t fam_absolute = {
.name = "system.memory.usage",
.help = "Reports memory in use by state",
.unit = "By",
.type = METRIC_TYPE_GAUGE,
};
gauge_t total = 0;
Expand All @@ -180,8 +182,9 @@ static int memory_dispatch(gauge_t values[COLLECTD_MEMORY_TYPE_MAX]) {
total += values[i];

if (values_absolute) {
metric_family_append(&fam_absolute, "state", memory_type_names[i],
(value_t){.gauge = values[i]}, NULL);
metric_family_append(&fam_absolute, "system.memory.state",
memory_type_names[i], (value_t){.gauge = values[i]},
NULL);
}
}

Expand All @@ -206,14 +209,17 @@ static int memory_dispatch(gauge_t values[COLLECTD_MEMORY_TYPE_MAX]) {

metric_family_t fam_percent = {
.name = "system.memory.utilization",
.help = "Reports memory in use by state",
.unit = "1",
.type = METRIC_TYPE_GAUGE,
};
for (size_t i = 0; i < COLLECTD_MEMORY_TYPE_MAX; i++) {
if (isnan(values[i])) {
continue;
}

metric_family_append(&fam_percent, "state", memory_type_names[i],
metric_family_append(&fam_percent, "system.memory.state",
memory_type_names[i],
(value_t){.gauge = 100.0 * values[i] / total}, NULL);
}

Expand Down

0 comments on commit e7dab5c

Please sign in to comment.