-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package inspector | ||
|
||
import ( | ||
"strconv" | ||
"strings" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
// LoadAvgMetrics : Metrics used by LoadAvg | ||
type LoadAvgMetrics struct { | ||
Load1M float64 | ||
Load5M float64 | ||
Load15M float64 | ||
} | ||
|
||
// LoadAvg : Parsing the /proc/loadavg output for disk monitoring | ||
type LoadAvg struct { | ||
fields | ||
Values LoadAvgMetrics | ||
} | ||
|
||
// Parse : run custom parsing on output of the command | ||
func (i *LoadAvg) Parse(output string) { | ||
var err error | ||
log.Debug("Parsing ouput string in LoadAvg inspector") | ||
columns := strings.Fields(output) | ||
Load1M, err := strconv.ParseFloat(columns[0], 64) | ||
Load5M, err := strconv.ParseFloat(columns[1], 64) | ||
Load15M, err := strconv.ParseFloat(columns[2], 64) | ||
if err != nil { | ||
log.Fatalf(`Error Parsing LoadAvg: %s `, err) | ||
} | ||
|
||
i.Values = LoadAvgMetrics{ | ||
Load1M, | ||
Load5M, | ||
Load15M, | ||
} | ||
} | ||
|
||
// NewLoadAvg : Initialize a new LoadAvg instance | ||
func NewLoadAvg() *LoadAvg { | ||
return &LoadAvg{ | ||
fields: fields{ | ||
Type: File, | ||
FilePath: `/proc/loadavg`, | ||
}, | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// +build !windows | ||
|
||
package inspector | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestLoadAvg(t *testing.T) { | ||
d := NewLoadAvg() | ||
if d.Type != File || d.FilePath != `/proc/loadavg` { | ||
t.Error("Initialized loadavg wrongly") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters