From a6ea8a31f4f27655640f7a517d2b157fa8fc62d7 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Sat, 1 Jun 2013 09:19:07 +0200 Subject: [PATCH] df plugin: Rename the percent metrics. * Change type to "percent". * Use "-bytes" and "-inodes" as plugin instance. This way we're able to use "percent" for both. * Remove one level of indentation. * Make casting more explicit (e.g. don't divide a float by a size_t). --- src/df.c | 50 ++++++++++++++++++++++++++++---------------------- src/types.db | 2 -- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/df.c b/src/df.c index 9033f5a8..5ff3f59b 100644 --- a/src/df.c +++ b/src/df.c @@ -285,19 +285,22 @@ static int df_read (void) blk_reserved = (uint64_t) (statbuf.f_bfree - statbuf.f_bavail); blk_used = (uint64_t) (statbuf.f_blocks - statbuf.f_bfree); - if (report_percentage) + if (report_percentage && (statbuf.f_blocks > 0)) { - if (statbuf.f_files > 0) - { - df_submit_one (disk_name, "df_complex_pct", "free", - (gauge_t) ((float_t)(blk_free) / statbuf.f_blocks * 100)); - df_submit_one (disk_name, "df_complex_pct", "reserved", - (gauge_t) ((float_t)(blk_reserved) / statbuf.f_blocks * 100)); - df_submit_one (disk_name, "df_complex_pct", "used", - (gauge_t) ((float_t)(blk_used) / statbuf.f_blocks * 100)); - } + uint64_t blk_total = (uint64_t) statbuf.f_blocks; + char plugin_instance[DATA_MAX_NAME_LEN]; + + ssnprintf (plugin_instance, sizeof (plugin_instance), + "%s-bytes", disk_name); + + df_submit_one (plugin_instance, "percent", "free", + 100.0 * ((gauge_t) blk_free) / ((gauge_t) blk_total)); + df_submit_one (plugin_instance, "percent", "reserved", + 100.0 * ((gauge_t) blk_reserved) / ((gauge_t) blk_total)); + df_submit_one (plugin_instance, "percent", "used", + 100.0 * ((gauge_t) blk_used) / ((gauge_t) blk_total)); } - else + else if (!report_percentage) { df_submit_one (disk_name, "df_complex", "free", (gauge_t) (blk_free * blocksize)); @@ -324,19 +327,22 @@ static int df_read (void) inode_reserved = (uint64_t) (statbuf.f_ffree - statbuf.f_favail); inode_used = (uint64_t) (statbuf.f_files - statbuf.f_ffree); - if (report_percentage) + if (report_percentage && (statbuf.f_files > 0)) { - if (statbuf.f_files > 0) - { - df_submit_one (disk_name, "df_inodes_pct", "free", - (gauge_t) ((float_t)(inode_free) / statbuf.f_files * 100)); - df_submit_one (disk_name, "df_inodes_pct", "reserved", - (gauge_t) ((float_t)(inode_reserved) / statbuf.f_files * 100)); - df_submit_one (disk_name, "df_inodes_pct", "used", - (gauge_t) ((float_t)(inode_used) / statbuf.f_files * 100)); - } + uint64_t inode_total = (uint64_t) statbuf.f_files; + char plugin_instance[DATA_MAX_NAME_LEN]; + + ssnprintf (plugin_instance, sizeof (plugin_instance), + "%s-inodes", disk_name); + + df_submit_one (plugin_instance, "percent", "free", + 100.0 * ((gauge_t) inode_free) / ((gauge_t) inode_total)); + df_submit_one (plugin_instance, "percent", "reserved", + 100.0 * ((gauge_t) inode_reserved) / ((gauge_t) inode_total)); + df_submit_one (plugin_instance, "percent", "used", + 100.0 * ((gauge_t) inode_used) / ((gauge_t) inode_total)); } - else + else if (!report_percentage) { df_submit_one (disk_name, "df_inodes", "free", (gauge_t) inode_free); diff --git a/src/types.db b/src/types.db index 05b0e455..950f6b0d 100644 --- a/src/types.db +++ b/src/types.db @@ -30,8 +30,6 @@ delay value:GAUGE:-1000000:1000000 derive value:DERIVE:0:U df_complex value:GAUGE:0:U df_inodes value:GAUGE:0:U -df_complex_pct value:GAUGE:0:100.1 -df_inodes_pct value:GAUGE:0:100.1 df used:GAUGE:0:1125899906842623, free:GAUGE:0:1125899906842623 disk_latency read:GAUGE:0:U, write:GAUGE:0:U disk_merged read:DERIVE:0:U, write:DERIVE:0:U -- 2.11.0