mirror of
https://github.com/aykhans/my-self-host-services.git
synced 2026-05-29 15:35:59 +00:00
monitoring: update crowdsec
This commit is contained in:
@@ -28,6 +28,11 @@ var (
|
|||||||
Help: "Unique IPs with at least one active decision across all origins.",
|
Help: "Unique IPs with at least one active decision across all origins.",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
decisionRemaining = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||||
|
Name: "crowdsec_decision_remaining_seconds",
|
||||||
|
Help: "Remaining seconds before each local decision expires. Only origin=crowdsec is exposed to keep cardinality bounded (CAPI/lists can contain tens of thousands of IPs).",
|
||||||
|
}, []string{"origin", "ip", "scenario", "type"})
|
||||||
|
|
||||||
lastFetchUnix = prometheus.NewGauge(prometheus.GaugeOpts{
|
lastFetchUnix = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
Name: "crowdsec_exporter_last_fetch_unix",
|
Name: "crowdsec_exporter_last_fetch_unix",
|
||||||
Help: "Unix timestamp of the last successful LAPI fetch.",
|
Help: "Unix timestamp of the last successful LAPI fetch.",
|
||||||
@@ -44,6 +49,7 @@ type decision struct {
|
|||||||
Scenario string `json:"scenario"`
|
Scenario string `json:"scenario"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Value string `json:"value"`
|
Value string `json:"value"`
|
||||||
|
Duration string `json:"duration"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -51,6 +57,7 @@ func init() {
|
|||||||
decisionsActive,
|
decisionsActive,
|
||||||
decisionsUniqueIPs,
|
decisionsUniqueIPs,
|
||||||
decisionsUniqueIPsTotal,
|
decisionsUniqueIPsTotal,
|
||||||
|
decisionRemaining,
|
||||||
lastFetchUnix,
|
lastFetchUnix,
|
||||||
fetchErrors,
|
fetchErrors,
|
||||||
)
|
)
|
||||||
@@ -119,6 +126,7 @@ func fetchAndUpdate(client *http.Client, lapiURL, apiKey string) {
|
|||||||
|
|
||||||
decisionsActive.Reset()
|
decisionsActive.Reset()
|
||||||
decisionsUniqueIPs.Reset()
|
decisionsUniqueIPs.Reset()
|
||||||
|
decisionRemaining.Reset()
|
||||||
for k, n := range counts {
|
for k, n := range counts {
|
||||||
decisionsActive.WithLabelValues(k.origin, k.scenario, k.dtype).Set(float64(n))
|
decisionsActive.WithLabelValues(k.origin, k.scenario, k.dtype).Set(float64(n))
|
||||||
}
|
}
|
||||||
@@ -127,6 +135,17 @@ func fetchAndUpdate(client *http.Client, lapiURL, apiKey string) {
|
|||||||
}
|
}
|
||||||
decisionsUniqueIPsTotal.Set(float64(len(allIPs)))
|
decisionsUniqueIPsTotal.Set(float64(len(allIPs)))
|
||||||
|
|
||||||
|
for _, d := range data {
|
||||||
|
if d.Origin != "crowdsec" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
dur, err := time.ParseDuration(d.Duration)
|
||||||
|
if err != nil {
|
||||||
|
dur = 0
|
||||||
|
}
|
||||||
|
decisionRemaining.WithLabelValues(d.Origin, d.Value, d.Scenario, d.Type).Set(dur.Seconds())
|
||||||
|
}
|
||||||
|
|
||||||
fetchErrors.Set(0)
|
fetchErrors.Set(0)
|
||||||
lastFetchUnix.Set(float64(time.Now().Unix()))
|
lastFetchUnix.Set(float64(time.Now().Unix()))
|
||||||
|
|
||||||
|
|||||||
@@ -428,6 +428,106 @@
|
|||||||
"values": false
|
"values": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 15,
|
||||||
|
"type": "table",
|
||||||
|
"title": "Local bans detail",
|
||||||
|
"datasource": {
|
||||||
|
"type": "prometheus",
|
||||||
|
"uid": "prometheusdatasource"
|
||||||
|
},
|
||||||
|
"gridPos": {
|
||||||
|
"x": 0,
|
||||||
|
"y": 24,
|
||||||
|
"w": 24,
|
||||||
|
"h": 10
|
||||||
|
},
|
||||||
|
"targets": [
|
||||||
|
{
|
||||||
|
"expr": "crowdsec_decision_remaining_seconds{origin=\"crowdsec\"}",
|
||||||
|
"refId": "A",
|
||||||
|
"instant": true,
|
||||||
|
"format": "table",
|
||||||
|
"datasource": {
|
||||||
|
"type": "prometheus",
|
||||||
|
"uid": "prometheusdatasource"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"transformations": [
|
||||||
|
{
|
||||||
|
"id": "organize",
|
||||||
|
"options": {
|
||||||
|
"excludeByName": {
|
||||||
|
"Time": true,
|
||||||
|
"__name__": true,
|
||||||
|
"instance": true,
|
||||||
|
"job": true,
|
||||||
|
"origin": true
|
||||||
|
},
|
||||||
|
"indexByName": {
|
||||||
|
"ip": 0,
|
||||||
|
"scenario": 1,
|
||||||
|
"type": 2,
|
||||||
|
"Value": 3
|
||||||
|
},
|
||||||
|
"renameByName": {
|
||||||
|
"ip": "IP",
|
||||||
|
"scenario": "Scenario",
|
||||||
|
"type": "Type",
|
||||||
|
"Value": "Time remaining"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"fieldConfig": {
|
||||||
|
"defaults": {
|
||||||
|
"custom": {
|
||||||
|
"align": "auto",
|
||||||
|
"filterable": true,
|
||||||
|
"inspect": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"overrides": [
|
||||||
|
{
|
||||||
|
"matcher": {
|
||||||
|
"id": "byName",
|
||||||
|
"options": "Time remaining"
|
||||||
|
},
|
||||||
|
"properties": [
|
||||||
|
{
|
||||||
|
"id": "unit",
|
||||||
|
"value": "s"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "custom.cellOptions",
|
||||||
|
"value": {
|
||||||
|
"type": "color-text"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "color",
|
||||||
|
"value": {
|
||||||
|
"mode": "continuous-GrYlRd"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"options": {
|
||||||
|
"showHeader": true,
|
||||||
|
"sortBy": [
|
||||||
|
{
|
||||||
|
"displayName": "Time remaining",
|
||||||
|
"desc": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"footer": {
|
||||||
|
"show": false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user