telebit/rvpn/admin/server_api.go
Henry Camacho fc89682b9e updated to include domain stat traffic
- add support for domain_api container for JSON encoding
- separated server api containers out of the listener_admin
- added domain track to connection
- add extension to the send channel to identify domain associated to send bytes
- helper function for adding tracked domain
- implemented outbound byte counter for domain (inbound will come when we resolve the packer issues)
2017-02-15 20:06:26 -06:00

47 lines
1.0 KiB
Go

package admin
import (
"fmt"
"time"
"git.daplie.com/Daplie/go-rvpn-server/rvpn/connection"
)
//ServerAPI -- Structure to support the server API
type ServerAPI struct {
ServerName string
Domains []*DomainAPI
Duration float64
BytesIn int64
BytesOut int64
}
//NewServerAPI - Constructor
func NewServerAPI(c *connection.Connection) (s *ServerAPI) {
s = new(ServerAPI)
s.ServerName = fmt.Sprintf("%p", c)
s.Domains = make([]*DomainAPI, 0)
s.Duration = time.Since(c.ConnectTime()).Seconds()
s.BytesIn = c.BytesIn()
s.BytesOut = c.BytesOut()
for d := range c.DomainTrack {
dt := c.DomainTrack[d]
domainAPI := NewDomainAPI(dt.DomainName, dt.BytesIn(), dt.BytesOut())
s.Domains = append(s.Domains, domainAPI)
}
return
}
//ServerAPIContainer -- Holder for all the Servers
type ServerAPIContainer struct {
Servers []*ServerAPI
}
//NewServerAPIContainer -- Constructor
func NewServerAPIContainer() (p *ServerAPIContainer) {
p = new(ServerAPIContainer)
p.Servers = make([]*ServerAPI, 0)
return p
}