add percent helper method to metrics

This commit is contained in:
Bradley Cicenas
2017-06-10 13:00:54 +00:00
parent b49e174483
commit 389dee0f3c
5 changed files with 20 additions and 11 deletions

View File

@@ -22,14 +22,14 @@ type Metrics struct {
func NewMetrics() Metrics {
return Metrics{
CPUUtil: -1,
NetTx: -1,
NetRx: -1,
MemUsage: -1,
MemPercent: -1,
IOBytesRead: -1,
IOBytesWrite: -1,
Pids: -1,
CPUUtil: -1,
NetTx: -1,
NetRx: -1,
MemUsage: -1,
MemPercent: -1,
IOBytesRead: -1,
IOBytesWrite: -1,
Pids: -1,
}
}
@@ -43,3 +43,11 @@ type Collector interface {
func round(num float64) int {
return int(num + math.Copysign(0.5, num))
}
// return rounded percentage
func percent(val float64, total float64) int {
if total <= 0 {
return 0
}
return round((val / total) * 100)
}