WIP: prep for 1.0 #1
@ -9,7 +9,6 @@ import (
|
|||||||
|
|
||||||
u "git.eeqj.de/sneak/goutil"
|
u "git.eeqj.de/sneak/goutil"
|
||||||
"github.com/flosch/pongo2"
|
"github.com/flosch/pongo2"
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/labstack/echo"
|
"github.com/labstack/echo"
|
||||||
)
|
)
|
||||||
@ -23,7 +22,12 @@ func (a *Server) instances() []hash {
|
|||||||
i := make(hash)
|
i := make(hash)
|
||||||
// TODO move this locking onto a method on Instance that just
|
// TODO move this locking onto a method on Instance that just
|
||||||
// returns a new hash
|
// returns a new hash
|
||||||
// FIXME figure out why a very short lock here deadlocks
|
|
||||||
|
//this only locks the FSM, not the whole instance struct
|
||||||
|
i["status"] = v.Status()
|
||||||
|
|
||||||
|
// now do a quick lock of the whole instance just to copy out the
|
||||||
|
// attrs
|
||||||
v.Lock()
|
v.Lock()
|
||||||
i["hostname"] = v.Hostname
|
i["hostname"] = v.Hostname
|
||||||
i["uuid"] = v.UUID.String()
|
i["uuid"] = v.UUID.String()
|
||||||
@ -31,9 +35,8 @@ func (a *Server) instances() []hash {
|
|||||||
i["nextCheckAfter"] = (-1 * now.Sub(v.NextFetch)).String()
|
i["nextCheckAfter"] = (-1 * now.Sub(v.NextFetch)).String()
|
||||||
i["successCount"] = v.SuccessCount
|
i["successCount"] = v.SuccessCount
|
||||||
i["errorCount"] = v.ErrorCount
|
i["errorCount"] = v.ErrorCount
|
||||||
|
i["consecutiveErrorCount"] = v.ConsecutiveErrorCount
|
||||||
i["identified"] = v.Identified
|
i["identified"] = v.Identified
|
||||||
//this only locks the FSM, not the whole instance struct
|
|
||||||
i["status"] = v.Status()
|
|
||||||
i["software"] = "unknown"
|
i["software"] = "unknown"
|
||||||
i["version"] = "unknown"
|
i["version"] = "unknown"
|
||||||
if v.Identified {
|
if v.Identified {
|
||||||
@ -41,6 +44,7 @@ func (a *Server) instances() []hash {
|
|||||||
i["version"] = v.ServerVersionString
|
i["version"] = v.ServerVersionString
|
||||||
}
|
}
|
||||||
v.Unlock()
|
v.Unlock()
|
||||||
|
|
||||||
resp = append(resp, i)
|
resp = append(resp, i)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,7 +58,7 @@ func (a *Server) instances() []hash {
|
|||||||
return resp
|
return resp
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Server) instanceSummary() map[string]int {
|
func (a *Server) instanceStatusSummary() map[string]int {
|
||||||
resp := make(map[string]int)
|
resp := make(map[string]int)
|
||||||
for _, v := range a.feta.manager.ListInstances() {
|
for _, v := range a.feta.manager.ListInstances() {
|
||||||
v.Lock()
|
v.Lock()
|
||||||
@ -68,26 +72,6 @@ func (a *Server) instanceSummary() map[string]int {
|
|||||||
return resp
|
return resp
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
func (a *Server) getInstanceListHandler() http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
|
|
||||||
result := &gin.H{
|
|
||||||
"instances": a.instances(),
|
|
||||||
}
|
|
||||||
|
|
||||||
json, err := json.Marshal(result)
|
|
||||||
if err != nil {
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
w.Write(json)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
func (a *Server) notFoundHandler(c echo.Context) error {
|
func (a *Server) notFoundHandler(c echo.Context) error {
|
||||||
return c.String(http.StatusNotFound, "404 not found")
|
return c.String(http.StatusNotFound, "404 not found")
|
||||||
}
|
}
|
||||||
@ -117,17 +101,33 @@ func (a *Server) instanceHandler(c echo.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *Server) indexHandler(c echo.Context) error {
|
func (a *Server) indexHandler(c echo.Context) error {
|
||||||
|
count, err := a.feta.dbm.TotalTootCount()
|
||||||
|
if err != nil {
|
||||||
|
count = 0
|
||||||
|
}
|
||||||
tc := pongo2.Context{
|
tc := pongo2.Context{
|
||||||
"time": time.Now().UTC().Format(time.RFC3339Nano),
|
"time": time.Now().UTC().Format(time.RFC3339Nano),
|
||||||
"gitrev": a.feta.version,
|
"gitrev": a.feta.version,
|
||||||
|
"tootCount": count,
|
||||||
"instances": a.instances(),
|
"instances": a.instances(),
|
||||||
|
"instanceStatusSummary": a.instanceStatusSummary(),
|
||||||
}
|
}
|
||||||
return c.Render(http.StatusOK, "index.html", tc)
|
return c.Render(http.StatusOK, "index.html", tc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *Server) instanceListHandler(c echo.Context) error {
|
||||||
|
il := a.instances()
|
||||||
|
tc := pongo2.Context{
|
||||||
|
"time": time.Now().UTC().Format(time.RFC3339Nano),
|
||||||
|
"gitrev": a.feta.version,
|
||||||
|
"instances": il,
|
||||||
|
}
|
||||||
|
return c.Render(http.StatusOK, "instancelist.html", tc)
|
||||||
|
}
|
||||||
|
|
||||||
func (a *Server) statsHandler(c echo.Context) error {
|
func (a *Server) statsHandler(c echo.Context) error {
|
||||||
index := &gin.H{
|
index := &hash{
|
||||||
"server": &gin.H{
|
"server": &hash{
|
||||||
"now": time.Now().UTC().Format(time.RFC3339),
|
"now": time.Now().UTC().Format(time.RFC3339),
|
||||||
"uptime": a.feta.uptime().String(),
|
"uptime": a.feta.uptime().String(),
|
||||||
"goroutines": runtime.NumGoroutine(),
|
"goroutines": runtime.NumGoroutine(),
|
||||||
@ -135,14 +135,14 @@ func (a *Server) statsHandler(c echo.Context) error {
|
|||||||
"version": a.feta.version,
|
"version": a.feta.version,
|
||||||
"buildarch": a.feta.buildarch,
|
"buildarch": a.feta.buildarch,
|
||||||
},
|
},
|
||||||
"instanceSummary": a.instanceSummary(),
|
"instanceStatusSummary": a.instanceStatusSummary(),
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSONPretty(http.StatusOK, index, " ")
|
return c.JSONPretty(http.StatusOK, index, " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Server) healthCheckHandler(c echo.Context) error {
|
func (a *Server) healthCheckHandler(c echo.Context) error {
|
||||||
resp := &gin.H{
|
resp := &hash{
|
||||||
"status": "ok",
|
"status": "ok",
|
||||||
"now": time.Now().UTC().Format(time.RFC3339),
|
"now": time.Now().UTC().Format(time.RFC3339),
|
||||||
"uptime": a.feta.uptime().String(),
|
"uptime": a.feta.uptime().String(),
|
||||||
|
Loading…
Reference in New Issue
Block a user