Merge branch 'master' into next

This commit is contained in:
Jonathan Leibiusky @xetorthio
2017-10-31 16:28:31 -03:00
7 changed files with 53 additions and 16 deletions

View File

@@ -101,6 +101,7 @@ func Register(extend HandlerExtender) {
IdleTimeout: 30 * time.Second,
ReadHeaderTimeout: 5 * time.Second,
}
if config.UseLetsEncrypt {
certManager := autocert.Manager{
Prompt: autocert.AcceptTOS,
@@ -127,7 +128,6 @@ func Register(extend HandlerExtender) {
log.Println("Listening on port " + config.PortNumber)
log.Fatal(httpServer.ListenAndServe())
}
}
func RegisterEvents(s *socketio.Server) {

View File

@@ -1,6 +1,41 @@
package handlers
import "net/http"
import (
"context"
"log"
"net/http"
"time"
"github.com/docker/docker/client"
"github.com/play-with-docker/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.
c, err := client.NewEnvClient()
if err != nil {
rw.WriteHeader(http.StatusInternalServerError)
return
}
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if _, err := c.Info(ctx); err != nil && err == context.DeadlineExceeded {
log.Printf("Docker info took to long to respond\n")
rw.WriteHeader(http.StatusGatewayTimeout)
}
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)
}
}
}

View File

@@ -21,6 +21,7 @@ func WS(so socketio.Socket) {
session := core.SessionGet(sessionId)
if session == nil {
log.Printf("Session with id [%s] does not exist!\n", sessionId)
so.Disconnect()
return
}