mirror of
https://github.com/bingohuang/docker-labs.git
synced 2025-07-14 01:57:32 +08:00
24 lines
536 B
Go
24 lines
536 B
Go
package handlers
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
|
|
"github.com/franela/play-with-docker/config"
|
|
"github.com/shirou/gopsutil/load"
|
|
)
|
|
|
|
func Ping(rw http.ResponseWriter, req *http.Request) {
|
|
// Get system load average of the last 5 minutes and compare it against a threashold.
|
|
|
|
a, err := load.Avg()
|
|
if err != nil {
|
|
log.Println("Cannot get system load average!", err)
|
|
} else {
|
|
if a.Load5 > config.MaxLoadAvg {
|
|
log.Printf("System load average is too high [%f]\n", a.Load5)
|
|
rw.WriteHeader(http.StatusInsufficientStorage)
|
|
}
|
|
}
|
|
}
|