add support for 'prometheus_mode' configuration directive that can be set to 'aggregation' to limit the cardinality of prometheus metrics (#192)

This commit is contained in:
Thibault "bui" Koechlin 2020-08-24 11:51:50 +02:00 committed by GitHub
parent 6624fce66a
commit b2ef6a555c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 7 deletions

View file

@ -276,7 +276,7 @@ func main() {
// Enable profiling early
if cConfig.Prometheus {
registerPrometheus()
registerPrometheus(cConfig.PrometheusMode)
cConfig.Profiling = true
}
if cConfig.Profiling {

View file

@ -126,12 +126,22 @@ func runTachymeter(HTTPListen string) {
log.Fatal(http.ListenAndServe(HTTPListen, nil))
}
func registerPrometheus() {
func registerPrometheus(mode string) {
/*Registering prometheus*/
log.Warningf("Loading prometheus collectors")
prometheus.MustRegister(globalParserHits, globalParserHitsOk, globalParserHitsKo,
parser.NodesHits, parser.NodesHitsOk, parser.NodesHitsKo,
acquisition.ReaderHits, globalCsInfo,
leaky.BucketsPour, leaky.BucketsUnderflow, leaky.BucketsInstanciation, leaky.BucketsOverflow, leaky.BucketsCurrentCount)
/*If in aggregated mode, do not register events associated to a source, keeps cardinality low*/
if mode == "aggregated" {
log.Infof("Loading aggregated prometheus collectors")
prometheus.MustRegister(globalParserHits, globalParserHitsOk, globalParserHitsKo,
acquisition.ReaderHits, globalCsInfo,
leaky.BucketsUnderflow, leaky.BucketsInstanciation, leaky.BucketsOverflow,
leaky.BucketsCurrentCount)
} else {
log.Infof("Loading prometheus collectors")
prometheus.MustRegister(globalParserHits, globalParserHitsOk, globalParserHitsKo,
parser.NodesHits, parser.NodesHitsOk, parser.NodesHitsKo,
acquisition.ReaderHits, globalCsInfo,
leaky.BucketsPour, leaky.BucketsUnderflow, leaky.BucketsInstanciation, leaky.BucketsOverflow, leaky.BucketsCurrentCount)
}
http.Handle("/metrics", promhttp.Handler())
}

View file

@ -73,6 +73,9 @@ To enable or disable {{crowdsec.Name}} daemon mode.
#### `prometheus:`
To enable or disable Prometheus metrics.
### `prometheus_mode:`
If `prometheus` is enabled, and is set to `aggregated`, will restrict prometheus metrics to global ones. All metrics containing a source as a label will be unregistered. Meant to keep cardinality low when relevant.
#### `http_listen:`
To configure the Prometheus service listening `address:port` or {{crowdsec.Name}} profiling

View file

@ -41,6 +41,7 @@ type CrowdSec struct {
SimulationCfg *SimulationConfig
Linter bool
Prometheus bool
PrometheusMode string `yaml:"prometheus_mode"`
HTTPListen string `yaml:"http_listen,omitempty"`
RestoreMode string
DumpBuckets bool