commit before applying 2p patch
This commit is contained in:
@@ -20,15 +20,19 @@ func (a *Server) instances() []hash {
|
||||
now := time.Now()
|
||||
for _, v := range a.feta.manager.ListInstances() {
|
||||
i := make(hash)
|
||||
// TODO move this locking onto a method on Instance that just
|
||||
// returns a new hash
|
||||
// FIXME figure out why a very short lock here deadlocks
|
||||
v.Lock()
|
||||
i["hostname"] = v.Hostname
|
||||
i["uuid"] = v.UUID.String()
|
||||
i["nextCheck"] = v.NextFetch.UTC().Format(time.RFC3339)
|
||||
i["nextCheckAfter"] = (-1 * now.Sub(v.NextFetch)).String()
|
||||
i["successCount"] = v.SuccessCount
|
||||
i["errorCount"] = v.ErrorCount
|
||||
i["identified"] = v.Identified
|
||||
i["status"] = v.Status() //FIXME maybe this is why
|
||||
//this only locks the FSM, not the whole instance struct
|
||||
i["status"] = v.Status()
|
||||
i["software"] = "unknown"
|
||||
i["version"] = "unknown"
|
||||
if v.Identified {
|
||||
@@ -38,6 +42,14 @@ func (a *Server) instances() []hash {
|
||||
v.Unlock()
|
||||
resp = append(resp, i)
|
||||
}
|
||||
|
||||
for _, item := range resp {
|
||||
count, err := a.feta.dbm.TootCountForHostname(item["hostname"].(string))
|
||||
item["tootCount"] = 0
|
||||
if err != nil {
|
||||
item["tootCount"] = count
|
||||
}
|
||||
}
|
||||
return resp
|
||||
}
|
||||
|
||||
@@ -75,10 +87,27 @@ func (a *Server) getInstanceListHandler() http.HandlerFunc {
|
||||
}
|
||||
*/
|
||||
|
||||
func (a *Server) instanceHandler(c echo.Context) error {
|
||||
tu := c.Param("uuid")
|
||||
u, err := uuid.Parse(tu)
|
||||
if err != nil {
|
||||
return c.String(http.StatusNotFound, "404 not found")
|
||||
}
|
||||
|
||||
|
||||
i := a.feta.manager.ListInstances() {
|
||||
tc := pongo2.Context{
|
||||
"instance": i,
|
||||
}
|
||||
|
||||
return c.Render(http.StatusOK, "instance.html", tc)
|
||||
}
|
||||
|
||||
func (a *Server) indexHandler(c echo.Context) error {
|
||||
tc := pongo2.Context{
|
||||
"time": time.Now().UTC().Format(time.RFC3339Nano),
|
||||
"gitrev": a.feta.version,
|
||||
"time": time.Now().UTC().Format(time.RFC3339Nano),
|
||||
"gitrev": a.feta.version,
|
||||
"instances": a.instances(),
|
||||
}
|
||||
return c.Render(http.StatusOK, "index.html", tc)
|
||||
}
|
||||
|
||||
@@ -95,6 +95,7 @@ func (s *Server) initRouter() {
|
||||
|
||||
// Routes
|
||||
s.e.GET("/", s.indexHandler)
|
||||
s.e.GET("/instance/:uuid", s.instanceHandler)
|
||||
s.e.GET("/stats.json", s.statsHandler)
|
||||
s.e.GET("/.well-known/healthcheck.json", s.healthCheckHandler)
|
||||
//a.e.GET("/about", s.aboutHandler)
|
||||
|
||||
Reference in New Issue
Block a user