Add light traffic theme, interactive map and metric detail dialogs
This commit is contained in:
28
traffic.go
28
traffic.go
@@ -51,7 +51,17 @@ type TrafficCount struct {
|
||||
Count int64 `json:"count"`
|
||||
}
|
||||
|
||||
type TrafficCountryDetail struct {
|
||||
Country string `json:"country"`
|
||||
Requests int64 `json:"requests"`
|
||||
UniqueIPs int64 `json:"uniqueIps"`
|
||||
Alerts int64 `json:"alerts"`
|
||||
Decisions int64 `json:"decisions"`
|
||||
LastSeen int64 `json:"lastSeen"`
|
||||
}
|
||||
type TrafficView struct {
|
||||
CountryDetails []TrafficCountryDetail `json:"countryDetails"`
|
||||
|
||||
Network *NetworkMapView `json:"network,omitempty"`
|
||||
Events []TrafficEvent `json:"events"`
|
||||
Sources []TrafficSource `json:"sources"`
|
||||
@@ -222,6 +232,24 @@ func (s *Store) TrafficView(domain, kind string, external bool, hideMonitoring .
|
||||
return v, e
|
||||
}
|
||||
}
|
||||
detailRows, detailErr := s.db.Query(`SELECT country,SUM(kind='request'),COUNT(DISTINCT CASE WHEN kind='request' THEN ip END),SUM(kind='alert'),SUM(kind='decision'),MAX(ts) FROM traffic_events`+where+` GROUP BY country`, args...)
|
||||
if detailErr != nil {
|
||||
return v, detailErr
|
||||
}
|
||||
v.CountryDetails = []TrafficCountryDetail{}
|
||||
for detailRows.Next() {
|
||||
var d TrafficCountryDetail
|
||||
if err = detailRows.Scan(&d.Country, &d.Requests, &d.UniqueIPs, &d.Alerts, &d.Decisions, &d.LastSeen); err != nil {
|
||||
detailRows.Close()
|
||||
return v, err
|
||||
}
|
||||
v.CountryDetails = append(v.CountryDetails, d)
|
||||
}
|
||||
detailErr = detailRows.Err()
|
||||
detailRows.Close()
|
||||
if detailErr != nil {
|
||||
return v, detailErr
|
||||
}
|
||||
r, err := s.db.Query(`SELECT CAST((ts/60)*60 AS TEXT),COUNT(*) FROM traffic_events`+where+` AND kind='request' AND ts>=? GROUP BY ts/60 ORDER BY ts/60`, append(args, now-3600)...)
|
||||
if err != nil {
|
||||
return v, err
|
||||
|
||||
Reference in New Issue
Block a user