forked from mirrors/statsd_exporter
Inject the mappings count metric into the library package
so that it can be initialized with an exporter-specific name. Signed-off-by: Matthias Rampke <mr@soundcloud.com>
This commit is contained in:
parent
40a13e604f
commit
d9f305b6f2
4 changed files with 11 additions and 31 deletions
2
main.go
2
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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue