updates to admin stats
This commit is contained in:
parent
c7a1d8d3a2
commit
025fa5da6b
|
@ -11,6 +11,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
telebit "git.rootprojects.org/root/telebit"
|
telebit "git.rootprojects.org/root/telebit"
|
||||||
"git.rootprojects.org/root/telebit/admin"
|
"git.rootprojects.org/root/telebit/admin"
|
||||||
|
@ -107,10 +108,10 @@ func apiNotFoundHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type SubscriberStatus struct {
|
type SubscriberStatus struct {
|
||||||
Subject string `json:"sub"`
|
Since *time.Time `json:"since,omitempty"`
|
||||||
RemoteAddr string `json:"socket"`
|
Subject string `json:"sub"`
|
||||||
Tunnels int `json:"tunnels"`
|
Sockets []string `json:"sockets"`
|
||||||
Clients int `json:"clients"`
|
Clients int `json:"clients"`
|
||||||
// TODO bytes read
|
// TODO bytes read
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,16 +119,20 @@ func getSubscribers(w http.ResponseWriter, r *http.Request) {
|
||||||
statuses := []*SubscriberStatus{}
|
statuses := []*SubscriberStatus{}
|
||||||
table.Servers.Range(func(key, value interface{}) bool {
|
table.Servers.Range(func(key, value interface{}) bool {
|
||||||
status := &SubscriberStatus{
|
status := &SubscriberStatus{
|
||||||
|
Since: nil,
|
||||||
Subject: "",
|
Subject: "",
|
||||||
//RemoteAddr: k.(string),
|
Sockets: []string{},
|
||||||
Tunnels: 0,
|
|
||||||
Clients: 0,
|
Clients: 0,
|
||||||
}
|
}
|
||||||
//subject := key.(string)
|
//subject := key.(string)
|
||||||
srvMap := value.(*sync.Map)
|
srvMap := value.(*sync.Map)
|
||||||
srvMap.Range(func(k, v interface{}) bool {
|
srvMap.Range(func(k, v interface{}) bool {
|
||||||
status.Tunnels++
|
status.Sockets = append(status.Sockets, k.(string))
|
||||||
srv := v.(*table.SubscriberConn)
|
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
|
status.Subject = srv.Grants.Subject
|
||||||
srv.Clients.Range(func(k, v interface{}) bool {
|
srv.Clients.Range(func(k, v interface{}) bool {
|
||||||
status.Clients++
|
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.
|
// 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.
|
// Rather the client's local address (the specific relay server) would be more useful.
|
||||||
ctxEncoder, cancelEncoder := context.WithCancel(context.Background())
|
ctxEncoder, cancelEncoder := context.WithCancel(context.Background())
|
||||||
|
now := time.Now()
|
||||||
server := &table.SubscriberConn{
|
server := &table.SubscriberConn{
|
||||||
|
Since: &now,
|
||||||
RemoteAddr: r.RemoteAddr,
|
RemoteAddr: r.RemoteAddr,
|
||||||
WSConn: conn,
|
WSConn: conn,
|
||||||
WSTun: wsTun,
|
WSTun: wsTun,
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"io"
|
"io"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -104,6 +105,7 @@ func Remove(subject string) bool {
|
||||||
|
|
||||||
// SubscriberConn represents a tunneled server, its grants, and its clients
|
// SubscriberConn represents a tunneled server, its grants, and its clients
|
||||||
type SubscriberConn struct {
|
type SubscriberConn struct {
|
||||||
|
Since *time.Time
|
||||||
RemoteAddr string
|
RemoteAddr string
|
||||||
WSConn *websocket.Conn
|
WSConn *websocket.Conn
|
||||||
WSTun net.Conn // *telebit.WebsocketTunnel
|
WSTun net.Conn // *telebit.WebsocketTunnel
|
||||||
|
|
Loading…
Reference in New Issue