2020-05-01 05:47:46 +00:00
|
|
|
package api
|
2017-03-14 01:22:44 +00:00
|
|
|
|
2017-03-26 01:33:09 +00:00
|
|
|
//DomainsAPI -- A collections of all the domains
|
|
|
|
//List of Domains -> DomainAPI
|
|
|
|
//DomainsAPI -> DomainServerAPI
|
|
|
|
//
|
|
|
|
|
|
|
|
//DomainServerAPI -- Container for Server Stats related to a domain
|
|
|
|
type DomainServerAPI struct {
|
|
|
|
ServerName string `json:"server_name"`
|
|
|
|
Traffic TrafficAPI `json:"traffic"`
|
2017-03-14 01:22:44 +00:00
|
|
|
}
|
|
|
|
|
2017-03-26 01:33:09 +00:00
|
|
|
//NewDomainServerAPI -- Constructor
|
|
|
|
func NewDomainServerAPI(domain string, conn *Connection) (p *DomainServerAPI) {
|
|
|
|
p = new(DomainServerAPI)
|
|
|
|
dt := conn.DomainTrack[domain]
|
|
|
|
p.Traffic.BytesIn = dt.BytesIn()
|
|
|
|
p.Traffic.BytesOut = dt.BytesOut()
|
|
|
|
p.Traffic.Requests = dt.Requests()
|
|
|
|
p.Traffic.Responses = dt.Responses()
|
|
|
|
p.ServerName = conn.ServerName()
|
2017-03-14 01:22:44 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-03-26 01:33:09 +00:00
|
|
|
//DomainAPI -- Container for domain and related servers
|
|
|
|
type DomainAPI struct {
|
2017-03-26 01:43:31 +00:00
|
|
|
DomainName string `json:"domain_name"`
|
2017-03-26 01:33:09 +00:00
|
|
|
TotalServers int `json:"server_total"`
|
|
|
|
Servers []*DomainServerAPI `json:"servers"`
|
|
|
|
Traffic TrafficAPI `json:"traffic"`
|
2017-03-14 01:22:44 +00:00
|
|
|
}
|
|
|
|
|
2017-03-26 01:33:09 +00:00
|
|
|
//NewDomainAPI -- Constructor
|
|
|
|
func NewDomainAPI(domain string, domainLoadBalance *DomainLoadBalance) (p *DomainAPI) {
|
|
|
|
p = new(DomainAPI)
|
2017-03-26 01:43:31 +00:00
|
|
|
p.DomainName = domain
|
2020-05-01 05:47:46 +00:00
|
|
|
for pos := range domainLoadBalance.Connections() {
|
|
|
|
ds := NewDomainServerAPI(domain, domainLoadBalance.Connections()[pos])
|
2017-03-26 01:33:09 +00:00
|
|
|
p.Servers = append(p.Servers, ds)
|
|
|
|
p.TotalServers++
|
2020-05-01 05:47:46 +00:00
|
|
|
p.Traffic.BytesIn += domainLoadBalance.Connections()[pos].BytesIn()
|
|
|
|
p.Traffic.BytesOut += domainLoadBalance.Connections()[pos].BytesOut()
|
|
|
|
p.Traffic.Requests += domainLoadBalance.Connections()[pos].Requests
|
|
|
|
p.Traffic.Responses += domainLoadBalance.Connections()[pos].Responses
|
2017-03-26 01:33:09 +00:00
|
|
|
}
|
|
|
|
return
|
2017-03-14 01:22:44 +00:00
|
|
|
}
|
|
|
|
|
2017-03-26 01:33:09 +00:00
|
|
|
//DomainsAPI -- Container for Domains
|
|
|
|
type DomainsAPI struct {
|
|
|
|
TotalDomains int `json:"domain_total"`
|
|
|
|
Domains []*DomainAPI `json:"domains"`
|
|
|
|
Traffic TrafficAPI `json:"traffic"`
|
2017-03-14 01:22:44 +00:00
|
|
|
}
|
|
|
|
|
2017-03-26 01:33:09 +00:00
|
|
|
//NewDomainsAPI -- Constructor
|
|
|
|
func NewDomainsAPI(domains map[string]*DomainLoadBalance) (p *DomainsAPI) {
|
|
|
|
p = new(DomainsAPI)
|
|
|
|
for domain := range domains {
|
|
|
|
d := NewDomainAPI(domain, domains[domain])
|
|
|
|
p.Domains = append(p.Domains, d)
|
|
|
|
p.Traffic.BytesIn += d.Traffic.BytesIn
|
|
|
|
p.Traffic.BytesOut += d.Traffic.BytesOut
|
|
|
|
p.Traffic.Requests += d.Traffic.Requests
|
|
|
|
p.Traffic.Responses += d.Traffic.Responses
|
|
|
|
|
|
|
|
}
|
2017-03-14 01:22:44 +00:00
|
|
|
return
|
|
|
|
}
|