From: Vedran Bartonicek Date: Fri, 31 May 2013 10:40:59 +0000 (+0300) Subject: Plugin df: ReportPercentage X-Git-Tag: collectd-5.4.0~32^2~3 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=c07ccc0a97187cf6e7a9c95a2b1dd01a6f19e205;p=collectd.git Plugin df: ReportPercentage --- diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 432efb83..57342159 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -1511,6 +1511,15 @@ Enable this option if inodes are a scarce resource for you, usually because many small files are stored on the disk. This is a usual scenario for mail transfer agents and web caches. +=item B B|B + +Enables or disables reporting of memory and memory in percentage. Defaults to +false. + +This is useful for deploying collectd on the cloud, where machines with +different disk size may exist. Then it is more practical to configure thresholds +based on relative disk size. + =back =head2 Plugin C diff --git a/src/df.c b/src/df.c index abb6418a..03b02cea 100644 --- a/src/df.c +++ b/src/df.c @@ -55,7 +55,7 @@ static const char *config_keys[] = "ReportByDevice", "ReportReserved", "ReportInodes", - "FreePercentage" + "ReportPercentage" }; static int config_keys_num = STATIC_ARRAY_SIZE (config_keys); @@ -65,7 +65,7 @@ static ignorelist_t *il_fstype = NULL; static _Bool by_device = 0; static _Bool report_inodes = 0; -static _Bool report_free_percentage = 0; +static _Bool report_percentage = 0; static int df_init (void) { @@ -134,12 +134,12 @@ static int df_config (const char *key, const char *value) return (0); } - else if (strcasecmp (key, "FreePercentage") == 0) + else if (strcasecmp (key, "ReportPercentage") == 0) { if (IS_TRUE (value)) - report_free_percentage = 1; + report_percentage = 1; else - report_free_percentage = 0; + report_percentage = 0; return (0); } @@ -197,7 +197,6 @@ static int df_read (void) uint64_t blk_free; uint64_t blk_reserved; uint64_t blk_used; - float blk_free_percentage; if (ignorelist_match (il_device, (mnt_ptr->spec_device != NULL) @@ -286,23 +285,28 @@ 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); - df_submit_one (disk_name, "df_complex", "free", + if (report_percentage) + { + 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)); + } + } + else + { + df_submit_one (disk_name, "df_complex", "free", (gauge_t) (blk_free * blocksize)); - df_submit_one (disk_name, "df_complex", "reserved", + df_submit_one (disk_name, "df_complex", "reserved", (gauge_t) (blk_reserved * blocksize)); - df_submit_one (disk_name, "df_complex", "used", + df_submit_one (disk_name, "df_complex", "used", (gauge_t) (blk_used * blocksize)); - - - if (report_free_percentage) - { - blk_free_percentage = (float)((statbuf.f_blocks - statbuf.f_bfree) / statbuf.f_blocks * 100); - float diff = statbuf.f_blocks - statbuf.f_bfree; - float div = diff/statbuf.f_blocks ; - - df_submit_one (disk_name, "df_complex", "free_percentage", - (gauge_t) (div * 100)); } + /* inode handling */ if (report_inodes) { @@ -315,17 +319,32 @@ static int df_read (void) statbuf.f_ffree = statbuf.f_favail; if (statbuf.f_files < statbuf.f_ffree) statbuf.f_files = statbuf.f_ffree; - + inode_free = (uint64_t) statbuf.f_favail; inode_reserved = (uint64_t) (statbuf.f_ffree - statbuf.f_favail); inode_used = (uint64_t) (statbuf.f_files - statbuf.f_ffree); - - df_submit_one (disk_name, "df_inodes", "free", - (gauge_t) inode_free); - df_submit_one (disk_name, "df_inodes", "reserved", - (gauge_t) inode_reserved); - df_submit_one (disk_name, "df_inodes", "used", - (gauge_t) inode_used); + + if (report_percentage) + { + 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)); + } + } + else + { + df_submit_one (disk_name, "df_inodes", "free", + (gauge_t) inode_free); + df_submit_one (disk_name, "df_inodes", "reserved", + (gauge_t) inode_reserved); + df_submit_one (disk_name, "df_inodes", "used", + (gauge_t) inode_used); + } } } diff --git a/src/types.db b/src/types.db index 950f6b0d..05b0e455 100644 --- a/src/types.db +++ b/src/types.db @@ -30,6 +30,8 @@ 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