summaryrefslogtreecommitdiff
path: root/service/metrics/config.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2019-06-26 16:38:52 +0300
committerWolfy-J <[email protected]>2019-06-26 16:38:52 +0300
commit4968bc66f01922cdf0e5bb6cbf891e99a10bb814 (patch)
treec187b73a55b4c1f891c8dbb488f71d231afd3638 /service/metrics/config.go
parent73ce97e6fccfc59ab759787891d2cc2f8d3f88a5 (diff)
custom application metrics
Diffstat (limited to 'service/metrics/config.go')
-rw-r--r--service/metrics/config.go20
1 files changed, 12 insertions, 8 deletions
diff --git a/service/metrics/config.go b/service/metrics/config.go
index b93d8f50..b9b21ea9 100644
--- a/service/metrics/config.go
+++ b/service/metrics/config.go
@@ -11,11 +11,11 @@ type Config struct {
Address string
// Collect define application specific metrics.
- Collect map[string]Metric
+ Collect map[string]Collector
}
-// Metric describes single application specific metric.
-type Metric struct {
+// Collector describes single application specific metric.
+type Collector struct {
// Namespace of the metric.
Namespace string
@@ -41,11 +41,13 @@ func (c *Config) Hydrate(cfg service.Config) error {
}
// register application specific metrics.
-func (c *Config) registerMetrics() error {
+func (c *Config) initCollectors() (map[string]prometheus.Collector, error) {
if c.Collect == nil {
- return nil
+ return nil, nil
}
+ collectors := make(map[string]prometheus.Collector)
+
for name, m := range c.Collect {
var collector prometheus.Collector
switch m.Type {
@@ -103,13 +105,15 @@ func (c *Config) registerMetrics() error {
collector = prometheus.NewSummary(opts)
}
default:
- return fmt.Errorf("invalid metric type %s", m.Type)
+ return nil, fmt.Errorf("invalid metric type `%s` for `%s`", m.Type, name)
}
if err := prometheus.Register(collector); err != nil {
- return err
+ return nil, err
}
+
+ collectors[name] = collector
}
- return nil
+ return collectors, nil
}