forked from jacksontj/mongodb_exporter
-
Notifications
You must be signed in to change notification settings - Fork 5
/
conn_pool_stats_replicasets.go
46 lines (37 loc) · 1.21 KB
/
conn_pool_stats_replicasets.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
package collector
import (
"sync"
"time"
"github.com/prometheus/client_golang/prometheus"
)
var (
pingTime = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: Namespace,
Subsystem: "connpoolstats",
Name: "ping_time_seconds",
Help: "Corresponds to the ping time from this mongos to the corresponding host in seconds",
}, []string{"host", "rs"})
// Lock for using these metrics
connPoolReplicaSetStatsLock = sync.Mutex{}
)
type ReplicaSetHostStats struct {
Host string `bson:"addr"`
PingTime float64 `bson:"pingTimeMillis"`
}
type ReplicaSetStats struct {
Hosts []*ReplicaSetHostStats `bson:"hosts"`
}
// Export exports the server status to be consumed by prometheus.
func (stats *ReplicaSetStats) Export(replicaSet string, ch chan<- prometheus.Metric) {
connPoolReplicaSetStatsLock.Lock()
defer connPoolReplicaSetStatsLock.Unlock()
for _, rsHostStat := range stats.Hosts {
pingTime.WithLabelValues(rsHostStat.Host, replicaSet).Set(rsHostStat.PingTime / float64(time.Second/time.Millisecond))
pingTime.Collect(ch)
pingTime.Reset()
}
}
// Describe describes the server status for prometheus.
func (stats *ReplicaSetStats) Describe(ch chan<- *prometheus.Desc) {
pingTime.Describe(ch)
}