Merge pull request #154 from alfrunes/config-profiling-metrics

feat: Add configuration option to enable/disable profiling metrics
This commit is contained in:
Christoph Petrausch
2024-12-26 13:04:31 +01:00
committed by GitHub
4 changed files with 19 additions and 7 deletions
Executable
BIN
View File
Binary file not shown.
+10 -3
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,
+4
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
+5 -4
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 {