updates to admin stats

This commit is contained in:
AJ ONeal 2020-07-22 06:14:14 +00:00
förälder c7a1d8d3a2
incheckning 025fa5da6b
2 ändrade filer med 16 tillägg och 7 borttagningar

Visa fil

@ -11,6 +11,7 @@ import (
"os"
"strings"
"sync"
"time"
telebit "git.rootprojects.org/root/telebit"
"git.rootprojects.org/root/telebit/admin"
@ -107,10 +108,10 @@ func apiNotFoundHandler(w http.ResponseWriter, r *http.Request) {
}
type SubscriberStatus struct {
Subject string `json:"sub"`
RemoteAddr string `json:"socket"`
Tunnels int `json:"tunnels"`
Clients int `json:"clients"`
Since *time.Time `json:"since,omitempty"`
Subject string `json:"sub"`
Sockets []string `json:"sockets"`
Clients int `json:"clients"`
// TODO bytes read
}
@ -118,16 +119,20 @@ func getSubscribers(w http.ResponseWriter, r *http.Request) {
statuses := []*SubscriberStatus{}
table.Servers.Range(func(key, value interface{}) bool {
status := &SubscriberStatus{
Since: nil,
Subject: "",
//RemoteAddr: k.(string),
Tunnels: 0,
Sockets: []string{},
Clients: 0,
}
//subject := key.(string)
srvMap := value.(*sync.Map)
srvMap.Range(func(k, v interface{}) bool {
status.Tunnels++
status.Sockets = append(status.Sockets, k.(string))
srv := v.(*table.SubscriberConn)
if nil == status.Since || srv.Since.Sub(*status.Since) < 0 {
copied := srv.Since.Truncate(time.Second)
status.Since = &copied
}
status.Subject = srv.Grants.Subject
srv.Clients.Range(func(k, v interface{}) bool {
status.Clients++
@ -206,7 +211,9 @@ func upgradeWebsocket(w http.ResponseWriter, r *http.Request) {
// The local address of the server (port to which it connected) is not very meaningful.
// Rather the client's local address (the specific relay server) would be more useful.
ctxEncoder, cancelEncoder := context.WithCancel(context.Background())
now := time.Now()
server := &table.SubscriberConn{
Since: &now,
RemoteAddr: r.RemoteAddr,
WSConn: conn,
WSTun: wsTun,

Visa fil

@ -5,6 +5,7 @@ import (
"net"
"os"
"sync"
"time"
"io"
"strconv"
@ -104,6 +105,7 @@ func Remove(subject string) bool {
// SubscriberConn represents a tunneled server, its grants, and its clients
type SubscriberConn struct {
Since *time.Time
RemoteAddr string
WSConn *websocket.Conn
WSTun net.Conn // *telebit.WebsocketTunnel