예제 #1
0
func loadavgHandler(w http.ResponseWriter, r *http.Request) {

	enc := json.NewEncoder(w)
	loadavg := cpu.LoadAvg()
	numCores := cpu.Count()
	var response = map[string]string{
		"OneMinute":      strconv.FormatFloat(float64(loadavg.OneMinute), 'f', 0, 32),
		"FiveMinute":     strconv.FormatFloat(float64(loadavg.FiveMinute), 'f', 0, 32),
		"FifteenMinute":  strconv.FormatFloat(float64(loadavg.FifteenMinute), 'f', 0, 32),
		"OneMinute%":     strconv.FormatFloat(float64(loadavg.OneMinute)*100/float64(numCores), 'f', 0, 32),
		"FiveMinute%":    strconv.FormatFloat(float64(loadavg.FiveMinute)*100/float64(numCores), 'f', 0, 32),
		"FifteenMinute%": strconv.FormatFloat(float64(loadavg.FifteenMinute)*100/float64(numCores), 'f', 0, 32),
	}
	enc.Encode(response)
}
예제 #2
0
func numberOfCoresHandler(w http.ResponseWriter, r *http.Request) {
	count := cpu.Count()
	countString := strconv.Itoa(count)
	enc := json.NewEncoder(w)
	enc.Encode(countString)
}