/
monitoring_controller.go
56 lines (44 loc) · 1.07 KB
/
monitoring_controller.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package front
import (
"github.com/gin-gonic/gin"
// "github.com/gotoolz/env"
"github.com/karhuteam/karhu/models"
"github.com/karhuteam/karhu/web"
"net/http"
)
type MonitoringController struct {
}
func NewMonitoringController(s *web.Server) *MonitoringController {
ctl := &MonitoringController{}
s.GET("/monitoring", ctl.getMonitoringAction)
return ctl
}
func (pc *MonitoringController) getMonitoringAction(c *gin.Context) {
host := c.Query("host")
stat := c.DefaultQuery("stat", "all")
t := c.DefaultQuery("time", "last1800")
hosts, err := models.NodeMapper.FetchAll()
if err != nil {
panic(err)
}
var graphs models.Graphs
var target []string
if host != "" {
target = []string{host}
} else {
for _, h := range hosts {
target = append(target, h.Hostname)
}
}
if graphs, err = models.GraphMapper.FetchAll(target, stat, t); err != nil {
panic(err)
}
c.HTML(http.StatusOK, "monitoring_show.html", map[string]interface{}{
"host": host,
"stat": stat,
"time": t,
"hosts": hosts,
"stats": models.GraphStats,
"graphs": graphs,
})
}