Added some docs

This commit is contained in:
Diptanu Choudhury
2016-05-20 11:38:15 -07:00
parent b7158be541
commit df68129e5a
2 changed files with 5 additions and 0 deletions

View File

@@ -130,6 +130,7 @@ type ProcessState struct {
Time time.Time
}
// NomadPid holds a pid and it's cpu percentage calculator
type NomadPid struct {
pid int
cpuStats *stats.CpuStats

View File

@@ -6,6 +6,7 @@ import (
"time"
)
// CpuStats calculates cpu usage percentage
type CpuStats struct {
prevProcessUsage float64
prevTime time.Time
@@ -14,11 +15,14 @@ type CpuStats struct {
logger *log.Logger
}
// NewCpuStats returns a cpu stats calculator
func NewCpuStats(logger *log.Logger) *CpuStats {
numCpus := runtime.NumCPU()
return &CpuStats{totalCpus: numCpus, logger: logger}
}
// Percent calculates the cpu usage percentage based on the current cpu usage
// and the previous cpu usage
func (c *CpuStats) Percent(currentProcessUsage float64) float64 {
now := time.Now()