diff --git a/cmd/cmd b/cmd/cmd new file mode 100755 index 0000000..69d9884 Binary files /dev/null and b/cmd/cmd differ diff --git a/cmd/mqtt2prometheus.go b/cmd/mqtt2prometheus.go index 6adcb00..52cbbc5 100644 --- a/cmd/mqtt2prometheus.go +++ b/cmd/mqtt2prometheus.go @@ -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, diff --git a/config.yaml.dist b/config.yaml.dist index 05abbc8..560e10a 100644 --- a/config.yaml.dist +++ b/config.yaml.dist @@ -19,6 +19,10 @@ mqtt: # device_id_regex: "(.*/)?(?P.*)" # 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 diff --git a/pkg/config/config.go b/pkg/config/config.go index 46b37b0..110a322 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -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 {