Fix traffic map zoom and add paginated history with local city GeoIP
This commit is contained in:
13
traffic.go
13
traffic.go
@@ -12,6 +12,8 @@ import (
|
||||
)
|
||||
|
||||
type TrafficEvent struct {
|
||||
City string `json:"city,omitempty"`
|
||||
Region string `json:"region,omitempty"`
|
||||
Monitoring bool `json:"monitoring"`
|
||||
ID string `json:"id"`
|
||||
Sequence int64 `json:"sequence,omitempty"`
|
||||
@@ -60,6 +62,7 @@ type TrafficCountryDetail struct {
|
||||
LastSeen int64 `json:"lastSeen"`
|
||||
}
|
||||
type TrafficView struct {
|
||||
MaxSequence int64 `json:"maxSequence"`
|
||||
CountryDetails []TrafficCountryDetail `json:"countryDetails"`
|
||||
|
||||
Network *NetworkMapView `json:"network,omitempty"`
|
||||
@@ -170,8 +173,11 @@ func (s *Store) TrafficView(domain, kind string, external bool, hideMonitoring .
|
||||
network := makeNetworkMap(snapshot, external)
|
||||
v.Network = &network
|
||||
}
|
||||
where := ` WHERE ts>=? AND agent=?`
|
||||
args := []any{now - 86400, v.Settings.AgentID}
|
||||
if err := s.db.QueryRow(`SELECT COALESCE(MAX(seq),0) FROM traffic_events WHERE agent=?`, v.Settings.AgentID).Scan(&v.MaxSequence); err != nil {
|
||||
return v, err
|
||||
}
|
||||
where := ` WHERE ts>=? AND agent=? AND ts<=? AND seq<=?`
|
||||
args := []any{now - 86400, v.Settings.AgentID, now, v.MaxSequence}
|
||||
if hide {
|
||||
clause, params := monitoringSQL(v.Settings.MonitoringRules)
|
||||
where += clause
|
||||
@@ -203,6 +209,7 @@ func (s *Store) TrafficView(domain, kind string, external bool, hideMonitoring .
|
||||
return v, err
|
||||
}
|
||||
e.Monitoring = isMonitoringRequest(e, v.Settings.MonitoringRules)
|
||||
e.City, e.Region = lookupTrafficCity(e.IP)
|
||||
v.Events = append(v.Events, e)
|
||||
}
|
||||
err = rows.Err()
|
||||
@@ -291,6 +298,8 @@ func (s *Store) TrafficView(domain, kind string, external bool, hideMonitoring .
|
||||
|
||||
func trafficRoutes(mux *http.ServeMux, s *Store) {
|
||||
trafficSettingsRoute(mux, s)
|
||||
s.trafficHistoryRoute(mux)
|
||||
trafficCityRoutes(mux)
|
||||
networkRoutes(mux, s)
|
||||
mux.HandleFunc("/traffic", func(w http.ResponseWriter, r *http.Request) {
|
||||
if !s.TrafficSettings().Enabled {
|
||||
|
||||
Reference in New Issue
Block a user