summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f536639)
raw | patch | inline | side by side (parent: f536639)
author | Vedran Bartonicek <vbartoni@gmail.com> | |
Fri, 31 May 2013 10:40:59 +0000 (13:40 +0300) | ||
committer | Florian Forster <octo@collectd.org> | |
Fri, 31 May 2013 16:17:23 +0000 (18:17 +0200) |
src/collectd.conf.pod | patch | blob | history | |
src/df.c | patch | blob | history | |
src/types.db | patch | blob | history |
diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod
index 432efb830fe98683b9b618e4f9b9d9bb231d2941..5734215963bb26210912694dd9c176dce477e4c6 100644 (file)
--- a/src/collectd.conf.pod
+++ b/src/collectd.conf.pod
many small files are stored on the disk. This is a usual scenario for mail
transfer agents and web caches.
+=item B<ReportPercentage> B<true>|B<false>
+
+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<disk>
diff --git a/src/df.c b/src/df.c
index abb6418ae00c8dd13f20219a32c6ab57aca1b2d3..03b02ceaf06e9d585c57541bd9feed44f58fead3 100644 (file)
--- a/src/df.c
+++ b/src/df.c
"ReportByDevice",
"ReportReserved",
"ReportInodes",
- "FreePercentage"
+ "ReportPercentage"
};
static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
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)
{
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);
}
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)
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)
{
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 950f6b0d842dd087b9db3e7b012d280da6ec417b..05b0e45555aaa487d31b4a8a8a514ccba0b7cbe4 100644 (file)
--- a/src/types.db
+++ b/src/types.db
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