mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 16:14:02 +03:00
Simplify stats
This commit is contained in:
+11
-17
@@ -40,7 +40,7 @@ func crashManager() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func connectionManager() { // nolint: gocyclo
|
func connectionManager() {
|
||||||
for event := range connectionsChan {
|
for event := range connectionsChan {
|
||||||
instance.mutex.RLock()
|
instance.mutex.RLock()
|
||||||
|
|
||||||
@@ -53,27 +53,21 @@ func connectionManager() { // nolint: gocyclo
|
|||||||
switch event.connectionType {
|
switch event.connectionType {
|
||||||
case mtproto.ConnectionTypeAbridged:
|
case mtproto.ConnectionTypeAbridged:
|
||||||
if isIPv4 {
|
if isIPv4 {
|
||||||
instance.ActiveConnections.Abridged.IPv4 += inc
|
instance.Connections.Abridged.IPv4 += inc
|
||||||
if event.connected {
|
|
||||||
instance.AllConnections.Abridged.IPv4 += inc
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
instance.ActiveConnections.Abridged.IPv6 += inc
|
instance.Connections.Abridged.IPv6 += inc
|
||||||
if event.connected {
|
}
|
||||||
instance.AllConnections.Abridged.IPv6 += inc
|
case mtproto.ConnectionTypeSecure:
|
||||||
}
|
if isIPv4 {
|
||||||
|
instance.Connections.Secure.IPv4 += inc
|
||||||
|
} else {
|
||||||
|
instance.Connections.Secure.IPv6 += inc
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
if isIPv4 {
|
if isIPv4 {
|
||||||
instance.ActiveConnections.Intermediate.IPv4 += inc
|
instance.Connections.Intermediate.IPv4 += inc
|
||||||
if event.connected {
|
|
||||||
instance.AllConnections.Intermediate.IPv4 += inc
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
instance.ActiveConnections.Intermediate.IPv6 += inc
|
instance.Connections.Intermediate.IPv6 += inc
|
||||||
if event.connected {
|
|
||||||
instance.AllConnections.Intermediate.IPv6 += inc
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+11
-9
@@ -52,20 +52,23 @@ type connections struct {
|
|||||||
All connectionType `json:"all"`
|
All connectionType `json:"all"`
|
||||||
Abridged connectionType `json:"abridged"`
|
Abridged connectionType `json:"abridged"`
|
||||||
Intermediate connectionType `json:"intermediate"`
|
Intermediate connectionType `json:"intermediate"`
|
||||||
|
Secure connectionType `json:"secure"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c connections) MarshalJSON() ([]byte, error) {
|
func (c connections) MarshalJSON() ([]byte, error) {
|
||||||
c.All.IPv4 = c.Abridged.IPv4 + c.Intermediate.IPv4
|
c.All.IPv4 = c.Abridged.IPv4 + c.Intermediate.IPv4 + c.Secure.IPv4
|
||||||
c.All.IPv6 = c.Abridged.IPv6 + c.Intermediate.IPv6
|
c.All.IPv6 = c.Abridged.IPv6 + c.Intermediate.IPv6 + c.Secure.IPv6
|
||||||
|
|
||||||
value := struct {
|
value := struct {
|
||||||
All connectionType `json:"all"`
|
All connectionType `json:"all"`
|
||||||
Abridged connectionType `json:"abridged"`
|
Abridged connectionType `json:"abridged"`
|
||||||
Intermediate connectionType `json:"intermediate"`
|
Intermediate connectionType `json:"intermediate"`
|
||||||
|
Secure connectionType `json:"secure"`
|
||||||
}{
|
}{
|
||||||
All: c.All,
|
All: c.All,
|
||||||
Abridged: c.Abridged,
|
Abridged: c.Abridged,
|
||||||
Intermediate: c.Intermediate,
|
Intermediate: c.Intermediate,
|
||||||
|
Secure: c.Secure,
|
||||||
}
|
}
|
||||||
|
|
||||||
return json.Marshal(value)
|
return json.Marshal(value)
|
||||||
@@ -87,13 +90,12 @@ type speed struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type stats struct {
|
type stats struct {
|
||||||
URLs config.IPURLs `json:"urls"`
|
URLs config.IPURLs `json:"urls"`
|
||||||
ActiveConnections connections `json:"active_connections"`
|
Connections connections `json:"connections"`
|
||||||
AllConnections connections `json:"all_connections"`
|
Traffic traffic `json:"traffic"`
|
||||||
Traffic traffic `json:"traffic"`
|
Speed speed `json:"speed"`
|
||||||
Speed speed `json:"speed"`
|
Uptime uptime `json:"uptime"`
|
||||||
Uptime uptime `json:"uptime"`
|
Crashes uint32 `json:"crashes"`
|
||||||
Crashes uint32 `json:"crashes"`
|
|
||||||
|
|
||||||
speedCurrent speed
|
speedCurrent speed
|
||||||
mutex *sync.RWMutex
|
mutex *sync.RWMutex
|
||||||
|
|||||||
Reference in New Issue
Block a user