forked from mdlayher/prombolt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prombolt.go
54 lines (44 loc) · 1.41 KB
/
prombolt.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
43
44
45
46
47
48
49
50
51
52
53
54
// Package prombolt provides a Prometheus metrics collector for Bolt databases.
package prombolt
import (
"sync"
"github.com/prometheus/client_golang/prometheus"
bolt "go.etcd.io/bbolt"
)
const (
// namespace is the top-level namespace metric names.
namespace = "bolt"
)
// New creates a new prometheus.Collector that can be registered with
// Prometheus to scrape metrics from a Bolt database handle.
//
// Name should specify a unique name for the collector, and will be added
// as a label to all produced Prometheus metrics.
func New(name string, db *bolt.DB, blockedBuckets ...[]byte) prometheus.Collector {
return &collector{
stats: newStatsCollector(name, db),
bucketStats: newBucketStatsCollector(name, db, blockedBuckets...),
}
}
// Enforce that collector is a prometheus.Collector.
var _ prometheus.Collector = &collector{}
// A collector is a prometheus.Collector for Bolt database metrics.
type collector struct {
mu sync.Mutex
stats *statsCollector
bucketStats *bucketStatsCollector
}
// Describe implements the prometheus.Collector interface.
func (c *collector) Describe(ch chan<- *prometheus.Desc) {
c.mu.Lock()
defer c.mu.Unlock()
c.stats.Describe(ch)
c.bucketStats.Describe(ch)
}
// Collect implements the prometheus.Collector interface.
func (c *collector) Collect(ch chan<- prometheus.Metric) {
c.mu.Lock()
defer c.mu.Unlock()
c.stats.Collect(ch)
c.bucketStats.Collect(ch)
}