More up to date CPU usage indicator

This commit is contained in:
Jakob Borg
2014-04-14 12:02:40 +02:00
parent 9d535b13cf
commit fb162ff529
3 changed files with 12 additions and 8 deletions

View File

@@ -155,7 +155,7 @@ func restGetNeed(m *Model, w http.ResponseWriter, params martini.Params) {
json.NewEncoder(w).Encode(gfs)
}
var cpuUsagePercent float64
var cpuUsagePercent [10]float64 // The last ten seconds
var cpuUsageLock sync.RWMutex
func restGetSystem(w http.ResponseWriter) {
@@ -168,8 +168,12 @@ func restGetSystem(w http.ResponseWriter) {
res["alloc"] = m.Alloc
res["sys"] = m.Sys
cpuUsageLock.RLock()
res["cpuPercent"] = cpuUsagePercent
var cpusum float64
for _, p := range cpuUsagePercent {
cpusum += p
}
cpuUsageLock.RUnlock()
res["cpuPercent"] = cpusum / 10
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(res)