added a stat item to the server

This commit is contained in:
hyung-hwan 2024-12-16 01:03:03 +09:00
parent fe67d9e16f
commit ec6577aed2
4 changed files with 15 additions and 5 deletions

View File

@ -50,12 +50,15 @@ func NewAppLoggerToFile (id string, file_name string, max_size int64, rotate int
f, err = os.OpenFile(file_name, os.O_CREATE | os.O_APPEND | os.O_WRONLY, 0666) f, err = os.OpenFile(file_name, os.O_CREATE | os.O_APPEND | os.O_WRONLY, 0666)
if err != nil { return nil, err } if err != nil { return nil, err }
if os.PathSeparator == '/' {
// this check is performed only on systems where the path separator is /.
matched, _ = filepath.Match("/dev/*", file_name) matched, _ = filepath.Match("/dev/*", file_name)
if matched { if matched {
// if the log file is under /dev, disable rotation // if the log file is under /dev, disable rotation
max_size = 0 max_size = 0
rotate = 0 rotate = 0
} }
}
l = &AppLogger{ l = &AppLogger{
Id: id, Id: id,

View File

@ -34,6 +34,8 @@ type json_out_server_stats struct {
ServerConns int64 `json:"server-conns"` ServerConns int64 `json:"server-conns"`
ServerRoutes int64 `json:"server-routes"` ServerRoutes int64 `json:"server-routes"`
ServerPeers int64 `json:"server-peers"` ServerPeers int64 `json:"server-peers"`
SshProxySessions int64 `json:"ssh-proxy-session"`
} }
// ------------------------------------ // ------------------------------------
@ -402,6 +404,7 @@ func (ctl *server_ctl_stats) ServeHTTP(w http.ResponseWriter, req *http.Request)
stats.ServerConns = s.stats.conns.Load() stats.ServerConns = s.stats.conns.Load()
stats.ServerRoutes = s.stats.routes.Load() stats.ServerRoutes = s.stats.routes.Load()
stats.ServerPeers = s.stats.peers.Load() stats.ServerPeers = s.stats.peers.Load()
stats.SshProxySessions = s.stats.ssh_proxy_sessions.Load()
status_code = http.StatusOK; w.WriteHeader(status_code) status_code = http.StatusOK; w.WriteHeader(status_code)
if err = je.Encode(stats); err != nil { goto oops } if err = je.Encode(stats); err != nil { goto oops }

View File

@ -572,6 +572,7 @@ func (pxy *server_proxy_ssh_ws) ServeWebsocket(ws *websocket.Conn) {
var n int var n int
var err error var err error
s.stats.ssh_proxy_sessions.Add(1)
buf = make([]byte, 2048) buf = make([]byte, 2048)
for { for {
n, err = out.Read(buf) n, err = out.Read(buf)
@ -589,6 +590,7 @@ func (pxy *server_proxy_ssh_ws) ServeWebsocket(ws *websocket.Conn) {
} }
} }
} }
s.stats.ssh_proxy_sessions.Add(-1)
} }
}() }()

View File

@ -69,6 +69,7 @@ type Server struct {
conns atomic.Int64 conns atomic.Int64
routes atomic.Int64 routes atomic.Int64
peers atomic.Int64 peers atomic.Int64
ssh_proxy_sessions atomic.Int64
} }
UnimplementedHoduServer UnimplementedHoduServer
@ -998,6 +999,7 @@ func NewServer(ctx context.Context, logger Logger, ctl_addrs []string, rpc_addrs
s.stats.conns.Store(0) s.stats.conns.Store(0)
s.stats.routes.Store(0) s.stats.routes.Store(0)
s.stats.peers.Store(0) s.stats.peers.Store(0)
s.stats.ssh_proxy_sessions.Store(0)
return &s, nil return &s, nil