Added root handler, collapsed subscriptionsz

This commit is contained in:
Derek Collison
2015-08-06 00:58:24 -07:00
parent bb0e6429bd
commit afc1bb05b1
3 changed files with 22 additions and 3 deletions

View File

@@ -153,7 +153,7 @@ func castToSliceString(input []interface{}) []string {
// Subsz represents detail information on current connections.
type Subsz struct {
SubjectStats sublist.Stats `json:"stats"`
*sublist.Stats
}
// Routez represents detailed information on current client connections.
@@ -224,7 +224,7 @@ func (s *Server) HandleRoutez(w http.ResponseWriter, r *http.Request) {
// HandleStats process HTTP requests for subjects stats.
func (s *Server) HandleSubsz(w http.ResponseWriter, r *http.Request) {
st := &Subsz{SubjectStats: *s.sl.Stats()}
st := &Subsz{s.sl.Stats()}
b, err := json.MarshalIndent(st, "", " ")
if err != nil {
@@ -282,6 +282,20 @@ func myUptime(d time.Duration) string {
return fmt.Sprintf("%ds", tsecs)
}
// HandleRoot will show basic info and links to others handlers.
func (s *Server) HandleRoot(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "<html lang=\"en\">gnatsd monitoring<br/><br/>")
vlink := fmt.Sprintf("http://%s/varz", r.Host)
fmt.Fprintf(w, "<a href=%s>%s</a><br/>", vlink, vlink)
clink := fmt.Sprintf("http://%s/connz", r.Host)
fmt.Fprintf(w, "<a href=%s>%s</a><br/>", clink, clink)
rlink := fmt.Sprintf("http://%s/routez", r.Host)
fmt.Fprintf(w, "<a href=%s>%s</a><br/>", rlink, rlink)
slink := fmt.Sprintf("http://%s/subscriptionsz", r.Host)
fmt.Fprintf(w, "<a href=%s>%s</a><br/>", slink, slink)
fmt.Fprint(w, "</html>")
}
// HandleVarz will process HTTP requests for server information.
func (s *Server) HandleVarz(w http.ResponseWriter, r *http.Request) {
v := &Varz{Info: &s.info, Options: s.opts, Start: s.start}

View File

@@ -350,6 +350,9 @@ func (s *Server) StartHTTPMonitoring() {
mux := http.NewServeMux()
// Root
mux.HandleFunc("/", s.HandleRoot)
// Varz
mux.HandleFunc("/varz", s.HandleVarz)