forked from mdklein/candid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.go
42 lines (34 loc) · 1.03 KB
/
store.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright 2018 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package monitoring
import (
"github.com/juju/loggo"
"github.com/prometheus/client_golang/prometheus"
"golang.org/x/net/context"
"github.com/CanonicalLtd/candid/store"
)
var logger = loggo.GetLogger("candid.internal.monitoring")
type StoreCollector struct {
Store store.Store
}
var storeIdentiesDesc = prometheus.NewDesc(
"candid_store_identities",
"Number of stored identities",
[]string{"provider"},
nil,
)
// Describe implements prometheus.Collector
func (c StoreCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- storeIdentiesDesc
}
// Describe implements prometheus.Collector
func (c StoreCollector) Collect(ch chan<- prometheus.Metric) {
counts, err := c.Store.IdentityCounts(context.Background())
if err != nil {
logger.Infof("error collecting metrics: %s", err)
return
}
for provider, count := range counts {
ch <- prometheus.MustNewConstMetric(storeIdentiesDesc, prometheus.GaugeValue, float64(count), provider)
}
}