mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-17 14:37:02 +00:00
monitoring: Add a config dump handler
This patch adds a handler to the monitoring HTTP server which dumps the parsed config, so it can easily be reviewed for troubleshooting.
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"blitiri.com.ar/go/chasquid/internal/config"
|
||||
"blitiri.com.ar/go/log"
|
||||
"google.golang.org/protobuf/encoding/prototext"
|
||||
|
||||
// To enable live profiling in the monitoring server.
|
||||
_ "net/http/pprof"
|
||||
@@ -45,6 +46,7 @@ func launchMonitoringServer(conf *config.Config) {
|
||||
})
|
||||
|
||||
http.HandleFunc("/debug/flags", debugFlagsHandler)
|
||||
http.HandleFunc("/debug/config", debugConfigHandler(conf))
|
||||
|
||||
go http.ListenAndServe(conf.MonitoringAddress, nil)
|
||||
}
|
||||
@@ -94,6 +96,7 @@ os hostname <i>{{.Hostname}}</i><p>
|
||||
<li>execution
|
||||
<ul>
|
||||
<li><a href="/debug/flags">flags</a>
|
||||
<li><a href="/debug/config">config</a>
|
||||
<li><a href="/debug/pprof/cmdline">command line</a>
|
||||
</ul>
|
||||
<li><a href="/debug/pprof">pprof</a>
|
||||
@@ -124,6 +127,12 @@ func debugFlagsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
})
|
||||
}
|
||||
|
||||
func debugConfigHandler(conf *config.Config) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
_, _ = w.Write([]byte(prototext.Format(conf)))
|
||||
}
|
||||
}
|
||||
|
||||
func roundDuration(d time.Duration) time.Duration {
|
||||
return d.Round(time.Second)
|
||||
}
|
||||
|
||||
@@ -40,6 +40,8 @@ wget -q -o /dev/null -O .data-A/dbg-flags http://localhost:1099/debug/flags \
|
||||
|| fail "failed to fetch /debug/flags"
|
||||
wget -q -o /dev/null -O .data-A/dbg-queue http://localhost:1099/debug/queue \
|
||||
|| fail "failed to fetch /debug/queue"
|
||||
wget -q -o /dev/null -O .data-A/dbg-config http://localhost:1099/debug/config \
|
||||
|| fail "failed to fetch /debug/config"
|
||||
wget -q -o /dev/null -O .data-A/dbg-root http://localhost:1099/404 \
|
||||
&& fail "fetch /404 worked, should have failed"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user