Skip to content

Commit

Permalink
metrics: refine stats fields
Browse files Browse the repository at this point in the history
  • Loading branch information
hexian000 committed Jul 16, 2023
1 parent 4de0dd8 commit 9363a06
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
6 changes: 2 additions & 4 deletions metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,13 @@ func RunHTTPServer(l net.Listener, s *Server) error {
fprintf(w, "%-20s: %v\n", "Num Goroutines", runtime.NumGoroutine())
printMemStats(w, true)
fprintf(w, "\n")
fprintf(w, "%-20s: %v\n", "Tunnels", len(s.getConfig().Tunnels))
fprintf(w, "%-20s: %v / %v\n", "Sessions / Streams", s.NumSessions(), s.f.Count())
fprintf(w, "%-20s: %v\n", "Managed Routines", s.g.Count())
fprintf(w, "%-20s: %v / %v\n", "Sessions / Streams", s.NumSessions(), s.NumStreams())
rx, tx := s.CountBytes()
fprintf(w, "%-20s: %s / %s\n", "Traffic (Rx/Tx)", formats.IECBytes(float64(rx)), formats.IECBytes(float64(tx)))
accepted, served := s.CountAccepts()
fprintf(w, "%-20s: %d (%d rejected)\n", "Listener Accepts", served, accepted-served)
authorized := s.CountAuthorized()
fprintf(w, "%-20s: %d (+%d)\n", "TLS", authorized, served-authorized)
fprintf(w, "%-20s: %d (%+d)\n", "Authorized Conns", authorized, served-authorized)
fprintf(w, "\n==============================\n")
fprintf(w, "runtime: %s\n", runtime.Version())
})
Expand Down
7 changes: 7 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ func (s *Server) NumSessions() (num int) {
return
}

func (s *Server) NumStreams() (num int) {
for _, t := range s.getTunnels() {
num += t.NumStreams()
}
return
}

func (s *Server) CountBytes() (read uint64, written uint64) {
return s.meter.Read.Load(), s.meter.Written.Load()
}
Expand Down
11 changes: 11 additions & 0 deletions tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,17 @@ func (t *Tunnel) NumSessions() (num int) {
return
}

func (t *Tunnel) NumStreams() (num int) {
t.mu.RLock()
defer t.mu.RUnlock()
for mux := range t.mux {
if !mux.IsClosed() {
num += mux.NumStreams()
}
}
return
}

func (t *Tunnel) Serve(mux *yamux.Session) {
var h Handler
if t.c.Dial != "" {
Expand Down

0 comments on commit 9363a06

Please sign in to comment.