mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-23 15:37:01 +00:00
monitoring: Reorganize index structure
This patch improves the organization of the monitoring index page: - Include the hostname (both OS and configured) for convenience. - Round the uptime presentation for readability. - Add a tiny CSS for consistency with the traces. - Re-arrange the list of links for readability.
This commit is contained in:
@@ -91,7 +91,7 @@ func main() {
|
|||||||
go signalHandler()
|
go signalHandler()
|
||||||
|
|
||||||
if conf.MonitoringAddress != "" {
|
if conf.MonitoringAddress != "" {
|
||||||
launchMonitoringServer(conf.MonitoringAddress)
|
launchMonitoringServer(conf)
|
||||||
}
|
}
|
||||||
|
|
||||||
s := smtpsrv.NewServer()
|
s := smtpsrv.NewServer()
|
||||||
|
|||||||
110
monitoring.go
110
monitoring.go
@@ -5,25 +5,33 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"blitiri.com.ar/go/chasquid/internal/config"
|
||||||
"blitiri.com.ar/go/log"
|
"blitiri.com.ar/go/log"
|
||||||
|
|
||||||
// To enable live profiling in the monitoring server.
|
// To enable live profiling in the monitoring server.
|
||||||
_ "net/http/pprof"
|
_ "net/http/pprof"
|
||||||
)
|
)
|
||||||
|
|
||||||
func launchMonitoringServer(addr string) {
|
func launchMonitoringServer(conf *config.Config) {
|
||||||
log.Infof("Monitoring HTTP server listening on %s", addr)
|
log.Infof("Monitoring HTTP server listening on %s", conf.MonitoringAddress)
|
||||||
|
|
||||||
|
osHostname, _ := os.Hostname()
|
||||||
|
|
||||||
indexData := struct {
|
indexData := struct {
|
||||||
Version string
|
Version string
|
||||||
SourceDate time.Time
|
SourceDate time.Time
|
||||||
StartTime time.Time
|
StartTime time.Time
|
||||||
|
Config *config.Config
|
||||||
|
Hostname string
|
||||||
}{
|
}{
|
||||||
Version: version,
|
Version: version,
|
||||||
SourceDate: sourceDate,
|
SourceDate: sourceDate,
|
||||||
StartTime: time.Now(),
|
StartTime: time.Now(),
|
||||||
|
Config: conf,
|
||||||
|
Hostname: osHostname,
|
||||||
}
|
}
|
||||||
|
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -36,70 +44,86 @@ func launchMonitoringServer(addr string) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
flags := dumpFlags()
|
http.HandleFunc("/debug/flags", debugFlagsHandler)
|
||||||
http.HandleFunc("/debug/flags", func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
_, _ = w.Write([]byte(flags))
|
|
||||||
})
|
|
||||||
|
|
||||||
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.
|
// Static index for the monitoring website.
|
||||||
var monitoringHTMLIndex = template.Must(template.New("index").Funcs(
|
var monitoringHTMLIndex = template.Must(
|
||||||
template.FuncMap{"since": time.Since}).Parse(
|
template.New("index").Funcs(tmplFuncs).Parse(
|
||||||
`<!DOCTYPE html>
|
`<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
|
||||||
<title>chasquid monitoring</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>chasquid monitoring</h1>
|
|
||||||
|
|
||||||
chasquid {{.Version}}<br>
|
<head>
|
||||||
source date {{.SourceDate.Format "2006-01-02 15:04:05 -0700"}}<p>
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<title>{{.Hostname}}: chasquid monitoring</title>
|
||||||
|
|
||||||
started {{.StartTime.Format "Mon, 2006-01-02 15:04:05 -0700"}}<br>
|
<style type="text/css">
|
||||||
up since {{.StartTime | since}}<p>
|
body {
|
||||||
|
font-family: sans-serif;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>chasquid @{{.Config.Hostname}}</h1>
|
||||||
|
|
||||||
|
chasquid {{.Version}}<br>
|
||||||
|
source date {{.SourceDate.Format "2006-01-02 15:04:05 -0700"}}<p>
|
||||||
|
|
||||||
|
started {{.StartTime.Format "Mon, 2006-01-02 15:04:05 -0700"}}<br>
|
||||||
|
up for {{.StartTime | since | roundDuration}}<br>
|
||||||
|
os hostname <i>{{.Hostname}}</i><p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><a href="/debug/queue">queue</a>
|
||||||
|
<li>monitoring
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="/debug/queue">queue</a>
|
<li><a href="/debug/requests?exp=1">requests (short-lived)</a>
|
||||||
|
<li><a href="/debug/events?exp=1">events (long-lived)</a>
|
||||||
<li><a href="/debug/vars">exported variables</a>
|
<li><a href="/debug/vars">exported variables</a>
|
||||||
<small><a href="https://golang.org/pkg/expvar/">(ref)</a></small>
|
<small><a href="https://golang.org/pkg/expvar/">(ref)</a></small>
|
||||||
<li>traces <small><a href="https://godoc.org/golang.org/x/net/trace">
|
|
||||||
(ref)</a></small>
|
|
||||||
<ul>
|
|
||||||
<li><a href="/debug/requests?exp=1">requests (short-lived)</a>
|
|
||||||
<li><a href="/debug/events?exp=1">events (long-lived)</a>
|
|
||||||
</ul>
|
|
||||||
<li><a href="/debug/flags">flags</a>
|
|
||||||
<li><a href="/debug/pprof">pprof</a>
|
|
||||||
<small><a href="https://golang.org/pkg/net/http/pprof/">
|
|
||||||
(ref)</a></small>
|
|
||||||
<ul>
|
|
||||||
<li><a href="/debug/pprof/goroutine?debug=1">goroutines</a>
|
|
||||||
</ul>
|
|
||||||
</ul>
|
</ul>
|
||||||
</body>
|
<li>execution
|
||||||
|
<ul>
|
||||||
|
<li><a href="/debug/flags">flags</a>
|
||||||
|
<li><a href="/debug/pprof/cmdline">command line</a>
|
||||||
|
</ul>
|
||||||
|
<li><a href="/debug/pprof">pprof</a>
|
||||||
|
<small><a href="https://golang.org/pkg/net/http/pprof/">(ref)</a></small>
|
||||||
|
<ul>
|
||||||
|
</ul>
|
||||||
|
</ul>
|
||||||
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
`))
|
`))
|
||||||
|
|
||||||
// dumpFlags to a string, for troubleshooting purposes.
|
func debugFlagsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
func dumpFlags() string {
|
|
||||||
s := ""
|
|
||||||
visited := make(map[string]bool)
|
visited := make(map[string]bool)
|
||||||
|
|
||||||
// Print set flags first, then the rest.
|
// Print set flags first, then the rest.
|
||||||
flag.Visit(func(f *flag.Flag) {
|
flag.Visit(func(f *flag.Flag) {
|
||||||
s += fmt.Sprintf("-%s=%s\n", f.Name, f.Value.String())
|
fmt.Fprintf(w, "-%s=%s\n", f.Name, f.Value.String())
|
||||||
visited[f.Name] = true
|
visited[f.Name] = true
|
||||||
})
|
})
|
||||||
|
|
||||||
s += "\n"
|
fmt.Fprintf(w, "\n")
|
||||||
|
|
||||||
flag.VisitAll(func(f *flag.Flag) {
|
flag.VisitAll(func(f *flag.Flag) {
|
||||||
if !visited[f.Name] {
|
if !visited[f.Name] {
|
||||||
s += fmt.Sprintf("-%s=%s\n", f.Name, f.Value.String())
|
fmt.Fprintf(w, "-%s=%s\n", f.Name, f.Value.String())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
return s
|
|
||||||
|
func roundDuration(d time.Duration) time.Duration {
|
||||||
|
return d.Round(time.Second)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user