Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Merge pull request #31 from marcintao/fix-NaN-values-in-metrics
Browse files Browse the repository at this point in the history
Fix NaN values in metrics
  • Loading branch information
marcintao authored Dec 15, 2016
2 parents 7a792eb + 5ddbc1c commit 82024b1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
20 changes: 7 additions & 13 deletions df/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const (
// PluginName df collector plugin name
PluginName = "df"
// Version of plugin
Version = 5
Version = 6

nsVendor = "intel"
nsClass = "procfs"
Expand Down Expand Up @@ -278,11 +278,11 @@ func fillMetric(kind string, dfm dfMetric, metric *plugin.MetricType) {
case "space_used":
metric.Data_ = dfm.Used
case "space_percent_free":
metric.Data_ = 100 * float64(dfm.Available) / float64(dfm.Blocks)
metric.Data_ = ceilPercent(dfm.Available, dfm.Blocks)
case "space_percent_reserved":
metric.Data_ = 100 * float64(dfm.Blocks-(dfm.Used+dfm.Available)) / float64(dfm.Blocks)
metric.Data_ = ceilPercent(dfm.Blocks-(dfm.Used+dfm.Available), dfm.Blocks)
case "space_percent_used":
metric.Data_ = 100 * float64(dfm.Used) / float64(dfm.Blocks)
metric.Data_ = ceilPercent(dfm.Used, dfm.Blocks)
case "device_name":
metric.Data_ = dfm.Filesystem
case "device_type":
Expand All @@ -294,11 +294,11 @@ func fillMetric(kind string, dfm dfMetric, metric *plugin.MetricType) {
case "inodes_used":
metric.Data_ = dfm.IUsed
case "inodes_percent_free":
metric.Data_ = 100 * float64(dfm.IFree) / float64(dfm.Inodes)
metric.Data_ = ceilPercent(dfm.IFree, dfm.Inodes)
case "inodes_percent_reserved":
metric.Data_ = 100 * float64(dfm.Inodes-(dfm.IUsed+dfm.IFree)) / float64(dfm.Inodes)
metric.Data_ = ceilPercent(dfm.Inodes-(dfm.IUsed+dfm.IFree), dfm.Inodes)
case "inodes_percent_used":
metric.Data_ = 100 * float64(dfm.IUsed) / float64(dfm.Inodes)
metric.Data_ = ceilPercent(dfm.IUsed, dfm.Inodes)
}
}

Expand Down Expand Up @@ -367,12 +367,10 @@ type dfCollector struct {
type dfMetric struct {
Filesystem string
Used, Available, Blocks uint64
Capacity float64
FsType string
MountPoint string
UnchangedMountPoint string
Inodes, IUsed, IFree uint64
IUse float64
}

type collector interface {
Expand Down Expand Up @@ -446,14 +444,10 @@ func (dfs *dfStats) collect(procPath string, excluded_fs_names []string, exclude
dfm.Available = (stat.Bavail * uint64(stat.Bsize)) / 1024
xFree := (stat.Bfree * uint64(stat.Bsize)) / 1024
dfm.Used = dfm.Blocks - xFree
percentAvailable := ceilPercent(dfm.Used, dfm.Used+dfm.Available)
dfm.Capacity = percentAvailable / 100.0
// Inodes
dfm.Inodes = stat.Files
dfm.IFree = stat.Ffree
dfm.IUsed = dfm.Inodes - dfm.IFree
percentIUsed := ceilPercent(dfm.IUsed, dfm.Inodes)
dfm.IUse = percentIUsed / 100.0
dfms = append(dfms, dfm)
}
return dfms, nil
Expand Down
8 changes: 0 additions & 8 deletions df/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,55 +46,47 @@ func (dfp *DfPluginSuite) SetupSuite() {
Blocks: 100,
Used: 50,
Available: 40,
Capacity: 0.5,
FsType: "ext4",
Filesystem: "/dev/sda1",
MountPoint: "rootfs",
Inodes: 1000,
IUsed: 500,
IFree: 400,
IUse: 0.5,
},
dfMetric{
Blocks: 200,
Used: 110,
Available: 80,
Capacity: 0.3,
FsType: "ext4",
Filesystem: "/dev/sda2",
MountPoint: "big",
Inodes: 2000,
IUsed: 1000,
IFree: 800,
IUse: 0.5,
},
}
dfms_unchanged := []dfMetric{
dfMetric{
Blocks: 100,
Used: 50,
Available: 40,
Capacity: 0.5,
FsType: "ext4",
Filesystem: "/dev/sda1",
MountPoint: "/",
Inodes: 1000,
IUsed: 500,
IFree: 400,
IUse: 0.5,
},
dfMetric{
Blocks: 200,
Used: 110,
Available: 80,
Capacity: 0.3,
FsType: "ext4",
Filesystem: "/dev/sda2",
MountPoint: "/big",
Inodes: 2000,
IUsed: 1000,
IFree: 800,
IUse: 0.5,
},
}
mc := &MockCollector{}
Expand Down

0 comments on commit 82024b1

Please sign in to comment.