Skip to content

Commit 94e2a2a

Browse files
authored
usage metrics: report acquisition + parsers metrics to LAPI (#3709)
1 parent cf98131 commit 94e2a2a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+1733
-792
lines changed

cmd/crowdsec-cli/cliitem/metrics.go

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/crowdsecurity/go-cs-lib/trace"
1616

1717
"github.com/crowdsecurity/crowdsec/pkg/cwhub"
18+
"github.com/crowdsecurity/crowdsec/pkg/metrics"
1819
)
1920

2021
func showMetrics(prometheusURL string, hub *cwhub.Hub, hubItem *cwhub.Item, wantColor string) error {
@@ -102,36 +103,27 @@ func getParserMetric(url string, itemName string) (map[string]map[string]int, er
102103
ival := int(fval)
103104

104105
switch fam.Name {
105-
case "cs_reader_hits_total":
106-
if _, ok := stats[source]; !ok {
107-
stats[source] = make(map[string]int)
108-
stats[source]["parsed"] = 0
109-
stats[source]["reads"] = 0
110-
stats[source]["unparsed"] = 0
111-
stats[source]["hits"] = 0
112-
}
113-
stats[source]["reads"] += ival
114-
case "cs_parser_hits_ok_total":
106+
case metrics.GlobalParserHitsOkMetricName:
115107
if _, ok := stats[source]; !ok {
116108
stats[source] = make(map[string]int)
117109
}
118110
stats[source]["parsed"] += ival
119-
case "cs_parser_hits_ko_total":
111+
case metrics.GlobalParserHitsKoMetricName:
120112
if _, ok := stats[source]; !ok {
121113
stats[source] = make(map[string]int)
122114
}
123115
stats[source]["unparsed"] += ival
124-
case "cs_node_hits_total":
116+
case metrics.NodesHitsMetricName:
125117
if _, ok := stats[source]; !ok {
126118
stats[source] = make(map[string]int)
127119
}
128120
stats[source]["hits"] += ival
129-
case "cs_node_hits_ok_total":
121+
case metrics.NodesHitsOkMetricName:
130122
if _, ok := stats[source]; !ok {
131123
stats[source] = make(map[string]int)
132124
}
133125
stats[source]["parsed"] += ival
134-
case "cs_node_hits_ko_total":
126+
case metrics.NodesHitsKoMetricName:
135127
if _, ok := stats[source]; !ok {
136128
stats[source] = make(map[string]int)
137129
}
@@ -194,15 +186,15 @@ func getScenarioMetric(url string, itemName string) (map[string]int, error) {
194186
ival := int(fval)
195187

196188
switch fam.Name {
197-
case "cs_bucket_created_total":
189+
case metrics.BucketsInstantiationMetricName:
198190
stats["instantiation"] += ival
199-
case "cs_buckets":
191+
case metrics.BucketsCurrentCountMetricName:
200192
stats["curr_count"] += ival
201-
case "cs_bucket_overflowed_total":
193+
case metrics.BucketsOverflowMetricName:
202194
stats["overflow"] += ival
203-
case "cs_bucket_poured_total":
195+
case metrics.BucketPouredMetricName:
204196
stats["pour"] += ival
205-
case "cs_bucket_underflowed_total":
197+
case metrics.BucketsUnderflowMetricName:
206198
stats["underflow"] += ival
207199
default:
208200
continue

0 commit comments

Comments
 (0)