]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
df plugin: Populate the `unit` field.
authorFlorian Forster <octo@collectd.org>
Wed, 27 Dec 2023 08:35:45 +0000 (09:35 +0100)
committerFlorian Forster <octo@collectd.org>
Mon, 15 Jan 2024 19:26:04 +0000 (20:26 +0100)
This also changes the report of usage to a ratio, as recommended by
OpenTelemetry. Previously we reported a percentage.

src/df.c

index a4a7af7a48d440cedeb25f0f481a1d3dc43a6ae5..2f368071fd0d74b99c30e7ca9e7de0faa593e1ff 100644 (file)
--- a/src/df.c
+++ b/src/df.c
@@ -145,18 +145,22 @@ static int df_read(void) {
 #endif
   metric_family_t fam_usage = {
       .name = "system.filesystem.usage",
+      .unit = "By",
       .type = METRIC_TYPE_GAUGE,
   };
   metric_family_t fam_utilization = {
       .name = "system.filesystem.utilization",
+      .unit = "1",
       .type = METRIC_TYPE_GAUGE,
   };
   metric_family_t fam_inode_usage = {
       .name = "system.filesystem.inodes.usage",
+      .unit = "{inode}",
       .type = METRIC_TYPE_GAUGE,
   };
   metric_family_t fam_inode_utilization = {
       .name = "system.filesystem.inodes.utilization",
+      .unit = "1",
       .type = METRIC_TYPE_GAUGE,
   };
 
@@ -243,7 +247,7 @@ static int df_read(void) {
 
     if (values_percentage) {
       assert(statbuf.f_blocks != 0); // checked above
-      gauge_t f = 100.0 / (gauge_t)statbuf.f_blocks;
+      gauge_t f = 1.0 / (gauge_t)statbuf.f_blocks;
 
       metric_family_append(&fam_utilization, "state", "used",
                            (value_t){.gauge = blk_used * f}, &m);
@@ -269,7 +273,7 @@ static int df_read(void) {
 
       if (values_percentage) {
         if (statbuf.f_files > 0) {
-          gauge_t f = 100.0 / (gauge_t)statbuf.f_files;
+          gauge_t f = 1.0 / (gauge_t)statbuf.f_files;
 
           metric_family_append(&fam_inode_utilization, "state", "used",
                                (value_t){.gauge = inode_used * f}, &m);