diff --git a/client-ctl.go b/client-ctl.go index f4dcf47..8fb83f9 100644 --- a/client-ctl.go +++ b/client-ctl.go @@ -111,6 +111,7 @@ type json_out_client_stats struct { ClientPeers int64 `json:"client-peers"` ClientPtySessions int64 `json:"client-pty-sessions"` ClientRptySessions int64 `json:"client-rpty-sessions"` + ClientRpxSessions int64 `json:"client-rpx-sessions"` } // ------------------------------------ @@ -1140,6 +1141,7 @@ func (ctl *client_ctl_stats) ServeHTTP(w http.ResponseWriter, req *http.Request) stats.ClientPeers = c.stats.peers.Load() stats.ClientPtySessions = c.stats.pty_sessions.Load() stats.ClientRptySessions = c.stats.rpty_sessions.Load() + stats.ClientRpxSessions = c.stats.rpx_sessions.Load() status_code = WriteJsonRespHeader(w, http.StatusOK) if err = je.Encode(stats); err != nil { goto oops } diff --git a/client-metrics.go b/client-metrics.go index 8233214..fe9e292 100644 --- a/client-metrics.go +++ b/client-metrics.go @@ -11,7 +11,8 @@ type ClientCollector struct { ClientRoutes *prometheus.Desc ClientPeers *prometheus.Desc PtySessions *prometheus.Desc - RptySessions *prometheus.Desc + RptySessions *prometheus.Desc + RpxSessions *prometheus.Desc } // NewClientCollector returns a new ClientCollector with all prometheus.Desc initialized @@ -58,6 +59,11 @@ func NewClientCollector(client *Client) ClientCollector { "Number of rpty sessions", nil, nil, ), + RpxSessions: prometheus.NewDesc( + prefix + "rpx_sessions", + "Number of rpx sessions", + nil, nil, + ), } } @@ -68,6 +74,7 @@ func (c ClientCollector) Describe(ch chan<- *prometheus.Desc) { ch <- c.ClientPeers ch <- c.PtySessions ch <- c.RptySessions + ch <- c.RpxSessions } func (c ClientCollector) Collect(ch chan<- prometheus.Metric) { @@ -110,4 +117,10 @@ func (c ClientCollector) Collect(ch chan<- prometheus.Metric) { prometheus.GaugeValue, float64(c.client.stats.rpty_sessions.Load()), ) + + ch <- prometheus.MustNewConstMetric( + c.RpxSessions, + prometheus.GaugeValue, + float64(c.client.stats.rpx_sessions.Load()), + ) } diff --git a/client.go b/client.go index 69b4b59..0b1dec5 100644 --- a/client.go +++ b/client.go @@ -167,6 +167,7 @@ type Client struct { peers atomic.Int64 pty_sessions atomic.Int64 rpty_sessions atomic.Int64 + rpx_sessions atomic.Int64 } pty_user string @@ -1892,6 +1893,7 @@ done: cts.rpx_mtx.Lock() delete(cts.rpx_map, crpx.id) cts.rpx_mtx.Unlock() + cts.C.stats.rpx_sessions.Add(-1) } func (cts *ClientConn) StartRpx(id uint64, data []byte, wg *sync.WaitGroup) error { @@ -1914,6 +1916,7 @@ func (cts *ClientConn) StartRpx(id uint64, data []byte, wg *sync.WaitGroup) erro crpx.ctx, crpx.cancel = context.WithCancel(cts.C.Ctx) cts.rpx_mtx.Unlock() + cts.C.stats.rpx_sessions.Add(1) wg.Add(1) go cts.RpxLoop(crpx, data, wg) @@ -2262,6 +2265,7 @@ func NewClient(ctx context.Context, name string, logger Logger, cfg *ClientConfi c.stats.peers.Store(0) c.stats.pty_sessions.Store(0) c.stats.rpty_sessions.Store(0) + c.stats.rpx_sessions.Store(0) return &c } diff --git a/hodu.go b/hodu.go index 12c2c95..40d3096 100644 --- a/hodu.go +++ b/hodu.go @@ -529,7 +529,7 @@ func get_regex_submatch(re *regexp.Regexp, str string, n int) string { pos = n * 2 if pos + 1 >= len(idxs) { return "" } - + start, end = idxs[pos], idxs[pos + 1] if start == -1 || end == -1 { return "" diff --git a/server-ctl.go b/server-ctl.go index 1f0e0ef..af700fa 100644 --- a/server-ctl.go +++ b/server-ctl.go @@ -78,6 +78,7 @@ type json_out_server_stats struct { SshProxySessions int64 `json:"pxy-ssh-sessions"` ServerPtySessions int64 `json:"server-pty-sessions"` ServerRptySessions int64 `json:"server-rpty-sessions"` + ServerRpxSessions int64 `json:"server-rpx-sessions"` } // this is a more specialized variant of json_in_notice @@ -923,6 +924,7 @@ func (ctl *server_ctl_stats) ServeHTTP(w http.ResponseWriter, req *http.Request) stats.SshProxySessions = s.stats.ssh_proxy_sessions.Load() stats.ServerPtySessions = s.stats.pty_sessions.Load() stats.ServerRptySessions = s.stats.rpty_sessions.Load() + stats.ServerRpxSessions = s.stats.rpx_sessions.Load() status_code = WriteJsonRespHeader(w, http.StatusOK) if err = je.Encode(stats); err != nil { goto oops } diff --git a/server-metrics.go b/server-metrics.go index 16d9485..923b68c 100644 --- a/server-metrics.go +++ b/server-metrics.go @@ -12,7 +12,8 @@ type ServerCollector struct { ServerPeers *prometheus.Desc SshProxySessions *prometheus.Desc PtySessions *prometheus.Desc - RptySessions *prometheus.Desc + RptySessions *prometheus.Desc + RpxSessions *prometheus.Desc } // NewServerCollector returns a new ServerCollector with all prometheus.Desc initialized @@ -64,6 +65,11 @@ func NewServerCollector(server *Server) ServerCollector { "Number of rpty session", nil, nil, ), + RpxSessions: prometheus.NewDesc( + prefix + "rpx_sessions", + "Number of rpx session", + nil, nil, + ), } } @@ -75,6 +81,7 @@ func (c ServerCollector) Describe(ch chan<- *prometheus.Desc) { ch <- c.SshProxySessions ch <- c.PtySessions ch <- c.RptySessions + ch <- c.RpxSessions } func (c ServerCollector) Collect(ch chan<- prometheus.Metric) { @@ -123,4 +130,10 @@ func (c ServerCollector) Collect(ch chan<- prometheus.Metric) { prometheus.GaugeValue, float64(c.server.stats.rpty_sessions.Load()), ) + + ch <- prometheus.MustNewConstMetric( + c.RpxSessions, + prometheus.GaugeValue, + float64(c.server.stats.rpx_sessions.Load()), + ) } diff --git a/server-rpx.go b/server-rpx.go index 2530f5d..1ec569e 100644 --- a/server-rpx.go +++ b/server-rpx.go @@ -211,6 +211,7 @@ func (rpx *server_rpx) alloc_server_rpx(cts *ServerConn, req *http.Request) (*Se cts.rpx_map[assigned_id] = srpx cts.rpx_mtx.Unlock() + cts.S.stats.rpx_sessions.Add(1) return srpx, nil } @@ -247,6 +248,7 @@ func (rpx *server_rpx) ServeHTTP(w http.ResponseWriter, req *http.Request) (int, cts.rpx_mtx.Lock() delete(cts.rpx_map, srpx.id) cts.rpx_mtx.Unlock() + cts.S.stats.rpx_sessions.Add(-1) }() ws_upgrade = strings.EqualFold(req.Header.Get("Upgrade"), "websocket") && strings.Contains(strings.ToLower(req.Header.Get("Connection")), "upgrade"); diff --git a/server.go b/server.go index 0de1f35..b41fabc 100644 --- a/server.go +++ b/server.go @@ -172,6 +172,7 @@ type Server struct { ssh_proxy_sessions atomic.Int64 pty_sessions atomic.Int64 rpty_sessions atomic.Int64 + rpx_sessions atomic.Int64 } wpx_resp_tf ServerWpxResponseTransformer @@ -1771,7 +1772,7 @@ func NewServer(ctx context.Context, name string, logger Logger, cfg *ServerConfi Addr: cfg.CtlAddrs[i], Handler: s.ctl_mux, // race condition issues without cloning. the http package modifies some fields in the configuration object - TLSConfig: cfg.CtlTls.Clone(), + TLSConfig: cfg.CtlTls.Clone(), ErrorLog: hs_log, // TODO: more settings } @@ -1902,6 +1903,7 @@ func NewServer(ctx context.Context, name string, logger Logger, cfg *ServerConfi s.stats.ssh_proxy_sessions.Store(0) s.stats.pty_sessions.Store(0) s.stats.rpty_sessions.Store(0) + s.stats.rpx_sessions.Store(0) return &s, nil @@ -2100,7 +2102,7 @@ func (s *Server) run_single_rpx_server(i int, cs *http.Server, wg* sync.WaitGrou } else { s.log.Write("", LOG_ERROR, "RPX channel[%d] error - %s", i, err.Error()) } - + } func (s *Server) RunRpxTask(wg *sync.WaitGroup) {