Skip to content

Commit baa2dc4

Browse files
Export latest_value and sensor_interface_name for active anomalies
1 parent 35b87c2 commit baa2dc4

File tree

5 files changed

+27
-15
lines changed

5 files changed

+27
-15
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ wanguard_announcements_finished 1
7575
### Anomalies Collector
7676
Metric | Type | Description | Labels
7777
-------|------|-------------|-------
78-
wanguard_anomalies_active | gauge | Active anomalies at the moment | anomaly, anomaly_id, bits, bits_s, duration, packets, pkts_s, prefix
78+
wanguard_anomalies_active | gauge | Active anomalies at the moment | anomaly, anomaly_id, bits, bits_s, duration, latest_value, packets, pkts_s, prefix, sensor_interface_name
7979
wanguard_anomalies_finished | gauge | Number of finished anomalies |
8080

8181
Example:
8282
```
83-
wanguard_anomalies_active{anomaly="ICMP pkts/s > 1",anomaly_id="1",bits="169576384000",bits_s="9014400",duration="60",packets="320020500",pkts_s="17500",prefix="10.10.10.10/32"} 1
83+
wanguard_anomalies_active{anomaly="ICMP pkts/s > 1",anomaly_id="1",bits="169576384000",bits_s="9014400",duration="60",latest_value="17500",packets="320020500",pkts_s="17500",prefix="10.10.10.10/32",sensor_interface_name="Interface 1"} 1
8484
wanguard_anomalies_finished 1
8585
```
8686

collectors/anomalies_collector.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,25 @@ type AnomaliesCount struct {
1919
}
2020

2121
type Anomaly struct {
22-
AnomalyId string `json:"anomaly_id"`
23-
Prefix string
24-
Anomaly string
25-
Duration string
26-
Pkts_s string `json:"pkts/s"`
27-
Bits_s string `json:"bits/s"`
28-
Packets string
29-
Bits string
22+
AnomalyId string `json:"anomaly_id"`
23+
Prefix string
24+
Anomaly string
25+
Duration string
26+
Pkts_s string `json:"pkts/s"`
27+
Bits_s string `json:"bits/s"`
28+
Packets string
29+
Bits string
30+
LatestValue string `json:"latest_value"`
31+
Sensor struct {
32+
SensorInterfaceName string `json:"sensor_interface_name"`
33+
} `json:"sensor"`
3034
}
3135

3236
func NewAnomaliesCollector(wgclient *wgc.Client) *AnomaliesCollector {
3337
prefix := "wanguard_anomalies_"
3438
return &AnomaliesCollector{
3539
wgClient: wgclient,
36-
AnomalyActive: prometheus.NewDesc(prefix+"active", "Active anomalies at the moment", []string{"prefix", "anomaly", "anomaly_id", "duration", "pkts_s", "packets", "bits_s", "bits"}, nil),
40+
AnomalyActive: prometheus.NewDesc(prefix+"active", "Active anomalies at the moment", []string{"prefix", "anomaly", "anomaly_id", "duration", "pkts_s", "packets", "bits_s", "bits", "latest_value", "sensor_interface_name"}, nil),
3741
AnomaliesFinished: prometheus.NewDesc(prefix+"finished", "Number of finished anomalies", nil, nil),
3842
}
3943
}
@@ -51,7 +55,7 @@ func (c *AnomaliesCollector) Collect(ch chan<- prometheus.Metric) {
5155
func collectActiveAnomalies(desc *prometheus.Desc, wgclient *wgc.Client, ch chan<- prometheus.Metric) {
5256
var anomalies []Anomaly
5357

54-
err := wgclient.GetParsed("anomalies?status=Active&fields=anomaly_id,anomaly,prefix,duration,pkts/s,packets,bits/s,bits", &anomalies)
58+
err := wgclient.GetParsed("anomalies?status=Active&fields=anomaly_id,anomaly,prefix,duration,pkts/s,packets,bits/s,bits,latest_value,sensor", &anomalies)
5559
if err != nil {
5660
return
5761
}
@@ -65,7 +69,9 @@ func collectActiveAnomalies(desc *prometheus.Desc, wgclient *wgc.Client, ch chan
6569
anomaly.Pkts_s,
6670
anomaly.Packets,
6771
anomaly.Bits_s,
68-
anomaly.Bits)
72+
anomaly.Bits,
73+
anomaly.LatestValue,
74+
anomaly.Sensor.SensorInterfaceName)
6975
}
7076
}
7177

collectors/anomalies_collector_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func anomaliesExpectedMetrics() string {
4040
return `
4141
# HELP wanguard_anomalies_active Active anomalies at the moment
4242
# TYPE wanguard_anomalies_active gauge
43-
wanguard_anomalies_active{anomaly="ICMP pkts/s > 1",anomaly_id="1",bits="169576384000",bits_s="9014400",duration="60",packets="320020500",pkts_s="17500",prefix="10.10.10.10/32"} 1
43+
wanguard_anomalies_active{anomaly="ICMP pkts/s > 1",anomaly_id="1",bits="169576384000",bits_s="9014400",duration="60",latest_value="130961807",packets="320020500",pkts_s="17500",prefix="10.10.10.10/32",sensor_interface_name="sFlows Filter Cluster"} 1
4444
4545
# HELP wanguard_anomalies_finished Number of finished anomalies
4646
# TYPE wanguard_anomalies_finished gauge

collectors/collector_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,12 @@ func anomaliesPayload() string {
270270
"bits/s": "9014400",
271271
"packets": "320020500",
272272
"bits": "169576384000",
273+
"latest_value": "130961807",
274+
"sensor": {
275+
"sensor_interface_name": "sFlows Filter Cluster",
276+
"sensor_interface_id": "4-1-0",
277+
"href": "/wanguard-api/v1/sensor_clusters/1"
278+
},
273279
"href": "/wanguard-api/v1/anomalies/1"
274280
}
275281
]`

wanguard_exporter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
const (
17-
version string = "1.6"
17+
version string = "1.7"
1818
)
1919

2020
type collectorsList struct {

0 commit comments

Comments
 (0)