diff --git a/chasquid.go b/chasquid.go index bbbccff..dbd16a6 100644 --- a/chasquid.go +++ b/chasquid.go @@ -91,7 +91,7 @@ func main() { go signalHandler() if conf.MonitoringAddress != "" { - launchMonitoringServer(conf.MonitoringAddress) + launchMonitoringServer(conf) } s := smtpsrv.NewServer() diff --git a/monitoring.go b/monitoring.go index f91b54c..dbb0371 100644 --- a/monitoring.go +++ b/monitoring.go @@ -5,25 +5,33 @@ import ( "fmt" "html/template" "net/http" + "os" "time" + "blitiri.com.ar/go/chasquid/internal/config" "blitiri.com.ar/go/log" // To enable live profiling in the monitoring server. _ "net/http/pprof" ) -func launchMonitoringServer(addr string) { - log.Infof("Monitoring HTTP server listening on %s", addr) +func launchMonitoringServer(conf *config.Config) { + log.Infof("Monitoring HTTP server listening on %s", conf.MonitoringAddress) + + osHostname, _ := os.Hostname() indexData := struct { Version string SourceDate time.Time StartTime time.Time + Config *config.Config + Hostname string }{ Version: version, SourceDate: sourceDate, StartTime: time.Now(), + Config: conf, + Hostname: osHostname, } http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { @@ -36,70 +44,86 @@ func launchMonitoringServer(addr string) { } }) - flags := dumpFlags() - http.HandleFunc("/debug/flags", func(w http.ResponseWriter, r *http.Request) { - _, _ = w.Write([]byte(flags)) - }) + http.HandleFunc("/debug/flags", debugFlagsHandler) - go http.ListenAndServe(addr, nil) + go http.ListenAndServe(conf.MonitoringAddress, nil) +} + +// Functions available inside the templates. +var tmplFuncs = template.FuncMap{ + "since": time.Since, + "roundDuration": roundDuration, } // Static index for the monitoring website. -var monitoringHTMLIndex = template.Must(template.New("index").Funcs( - template.FuncMap{"since": time.Since}).Parse( - ` +var monitoringHTMLIndex = template.Must( + template.New("index").Funcs(tmplFuncs).Parse( + ` -
-+
+ ++ + +
+
+
+started {{.StartTime.Format "Mon, 2006-01-02 15:04:05 -0700"}}
+up for {{.StartTime | since | roundDuration}}
+os hostname {{.Hostname}}
+ +