feat: Add configuration option to enable/disable profiling metrics

Added a new configuration `enable_profiling_metrics` which
enable/disable the default runtime metrics exported by the Prometheus
client package.

BREAKING CHANGE: Changed default behavior to exclude runtime metrics.
        Enable with enable_profiling_metrics configuration option.
Signed-off-by: Alf-Rune Siqveland <alf.rune@siqveland.no>
This commit is contained in:
Alf-Rune Siqveland
2024-08-18 12:42:16 +02:00
parent 0137ffc738
commit 95bbd81f7d
4 changed files with 19 additions and 7 deletions

BIN
cmd/cmd Executable file

Binary file not shown.

View File

@@ -151,9 +151,16 @@ func main() {
time.Sleep(10 * time.Second)
}
prometheus.MustRegister(ingest.Collector())
prometheus.MustRegister(collector)
http.Handle("/metrics", promhttp.Handler())
var gatherer prometheus.Gatherer
if cfg.EnableProfiling {
gatherer = prometheus.DefaultGatherer
} else {
reg := prometheus.NewRegistry()
reg.MustRegister(ingest.Collector())
reg.MustRegister(collector)
gatherer = reg
}
http.Handle("/metrics", promhttp.HandlerFor(gatherer, promhttp.HandlerOpts{}))
s := &http.Server{
Addr: getListenAddress(),
Handler: http.DefaultServeMux,

View File

@@ -19,6 +19,10 @@ mqtt:
# device_id_regex: "(.*/)?(?P<deviceid>.*)"
# The MQTT QoS level
qos: 0
# Export internal profiling metrics including CPU, Memory, uptime, open file
# descriptors, as well as metrics exported by Go runtime such as information about
# heap and garbage collection stats.
enable_profiling_metrics: false
cache:
# Timeout. Each received metric will be presented for this time if no update is send via MQTT.
# Set the timeout to -1 to disable the deletion of metrics from the cache. The exporter presents the ingest timestamp

View File

@@ -89,10 +89,11 @@ func MustNewRegexp(pattern string) *Regexp {
}
type Config struct {
JsonParsing *JsonParsingConfig `yaml:"json_parsing,omitempty"`
Metrics []MetricConfig `yaml:"metrics"`
MQTT *MQTTConfig `yaml:"mqtt,omitempty"`
Cache *CacheConfig `yaml:"cache,omitempty"`
JsonParsing *JsonParsingConfig `yaml:"json_parsing,omitempty"`
Metrics []MetricConfig `yaml:"metrics"`
MQTT *MQTTConfig `yaml:"mqtt,omitempty"`
Cache *CacheConfig `yaml:"cache,omitempty"`
EnableProfiling bool `yaml:"enable_profiling_metrics,omitempty"`
}
type CacheConfig struct {