✨ CLI Loading server stats and traces
This commit is contained in:
@ -5,6 +5,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pelletier/go-toml/v2"
|
||||
)
|
||||
@ -19,6 +20,7 @@ func ReadInConfig(root string) error {
|
||||
Traffic: make(map[string]int64),
|
||||
TrafficFrom: make(map[string]int64),
|
||||
TotalTraffic: 0,
|
||||
StartupAt: time.Now(),
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,9 @@
|
||||
package navi
|
||||
|
||||
import "github.com/spf13/viper"
|
||||
import (
|
||||
"github.com/spf13/viper"
|
||||
"time"
|
||||
)
|
||||
|
||||
type RoadMetrics struct {
|
||||
Traces []RoadTrace `json:"-"`
|
||||
@ -8,9 +11,11 @@ type RoadMetrics struct {
|
||||
Traffic map[string]int64 `json:"traffic"`
|
||||
TrafficFrom map[string]int64 `json:"traffic_from"`
|
||||
TotalTraffic int64 `json:"total_traffic"`
|
||||
StartupAt time.Time `json:"startup_at"`
|
||||
}
|
||||
|
||||
type RoadTrace struct {
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
Region string `json:"region"`
|
||||
Location string `json:"location"`
|
||||
Destination string `json:"destination"`
|
||||
@ -27,6 +32,7 @@ type RoadTraceError struct {
|
||||
|
||||
func (v *RoadMetrics) AddTrace(trace RoadTrace) {
|
||||
v.TotalTraffic++
|
||||
trace.Timestamp = time.Now()
|
||||
if _, ok := v.Traffic[trace.Region]; !ok {
|
||||
v.Traffic[trace.Region] = 0
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user