added a stat item to the server
This commit is contained in:
parent
fe67d9e16f
commit
ec6577aed2
@ -50,11 +50,14 @@ 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)
|
||||
if err != nil { return nil, err }
|
||||
|
||||
matched, _ = filepath.Match("/dev/*", file_name)
|
||||
if matched {
|
||||
// if the log file is under /dev, disable rotation
|
||||
max_size = 0
|
||||
rotate = 0
|
||||
if os.PathSeparator == '/' {
|
||||
// this check is performed only on systems where the path separator is /.
|
||||
matched, _ = filepath.Match("/dev/*", file_name)
|
||||
if matched {
|
||||
// if the log file is under /dev, disable rotation
|
||||
max_size = 0
|
||||
rotate = 0
|
||||
}
|
||||
}
|
||||
|
||||
l = &AppLogger{
|
||||
|
@ -34,6 +34,8 @@ type json_out_server_stats struct {
|
||||
ServerConns int64 `json:"server-conns"`
|
||||
ServerRoutes int64 `json:"server-routes"`
|
||||
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.ServerRoutes = s.stats.routes.Load()
|
||||
stats.ServerPeers = s.stats.peers.Load()
|
||||
stats.SshProxySessions = s.stats.ssh_proxy_sessions.Load()
|
||||
status_code = http.StatusOK; w.WriteHeader(status_code)
|
||||
if err = je.Encode(stats); err != nil { goto oops }
|
||||
|
||||
|
@ -572,6 +572,7 @@ func (pxy *server_proxy_ssh_ws) ServeWebsocket(ws *websocket.Conn) {
|
||||
var n int
|
||||
var err error
|
||||
|
||||
s.stats.ssh_proxy_sessions.Add(1)
|
||||
buf = make([]byte, 2048)
|
||||
for {
|
||||
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)
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -69,6 +69,7 @@ type Server struct {
|
||||
conns atomic.Int64
|
||||
routes atomic.Int64
|
||||
peers atomic.Int64
|
||||
ssh_proxy_sessions atomic.Int64
|
||||
}
|
||||
|
||||
UnimplementedHoduServer
|
||||
@ -998,6 +999,7 @@ func NewServer(ctx context.Context, logger Logger, ctl_addrs []string, rpc_addrs
|
||||
s.stats.conns.Store(0)
|
||||
s.stats.routes.Store(0)
|
||||
s.stats.peers.Store(0)
|
||||
s.stats.ssh_proxy_sessions.Store(0)
|
||||
|
||||
return &s, nil
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user