diff --git a/main.go b/main.go index a5054cf..739834c 100644 --- a/main.go +++ b/main.go @@ -188,7 +188,7 @@ func main() { go tl.Listen(events) } - mapper := &mapper.MetricMapper{} + mapper := &mapper.MetricMapper{MappingsCount: mappingsCount} if *mappingConfig != "" { err := mapper.InitFromFile(*mappingConfig) if err != nil { diff --git a/pkg/mapper/mapper.go b/pkg/mapper/mapper.go index ec469a7..973607c 100644 --- a/pkg/mapper/mapper.go +++ b/pkg/mapper/mapper.go @@ -44,6 +44,8 @@ type MetricMapper struct { Defaults mapperConfigDefaults `yaml:"defaults"` Mappings []MetricMapping `yaml:"mappings"` mutex sync.Mutex + + MappingsCount prometheus.Gauge } type matchMetricType string @@ -159,7 +161,9 @@ func (m *MetricMapper) InitFromYAMLString(fileContents string) error { m.Defaults = n.Defaults m.Mappings = n.Mappings - mappingsCount.Set(float64(len(n.Mappings))) + if m.MappingsCount != nil { + m.MappingsCount.Set(float64(len(n.Mappings))) + } return nil } diff --git a/pkg/mapper/telemetry.go b/pkg/mapper/telemetry.go deleted file mode 100644 index c74ccf0..0000000 --- a/pkg/mapper/telemetry.go +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2013 The Prometheus Authors -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mapper - -import ( - "github.com/prometheus/client_golang/prometheus" -) - -var ( - mappingsCount = prometheus.NewGauge(prometheus.GaugeOpts{ - Name: "statsd_exporter_loaded_mappings", - Help: "The current number of configured metric mappings.", - }) -) - -func init() { - prometheus.MustRegister(mappingsCount) -} diff --git a/telemetry.go b/telemetry.go index 1025efc..92e174b 100644 --- a/telemetry.go +++ b/telemetry.go @@ -91,6 +91,10 @@ var ( }, []string{"outcome"}, ) + mappingsCount = prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "statsd_exporter_loaded_mappings", + Help: "The current number of configured metric mappings.", + }) conflictingEventStats = prometheus.NewCounterVec( prometheus.CounterOpts{ Name: "statsd_exporter_events_conflict_total", @@ -112,5 +116,6 @@ func init() { prometheus.MustRegister(tagsReceived) prometheus.MustRegister(tagErrors) prometheus.MustRegister(configLoads) + prometheus.MustRegister(mappingsCount) prometheus.MustRegister(conflictingEventStats) }