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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
package collector
import (
"github.com/prometheus/client_golang/prometheus"
)
var (
locksTimeLockedGlobalMicrosecondsTotal = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "locks_time_locked_global_microseconds_total",
Help: "amount of time in microseconds that any database has held the global lock",
}, []string{"type", "database"})
)
var (
locksTimeLockedLocalMicrosecondsTotal = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "locks_time_locked_local_microseconds_total",
Help: "amount of time in microseconds that any database has held the local lock",
}, []string{"type", "database"})
)
var (
locksTimeAcquiringGlobalMicrosecondsTotal = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "locks_time_acquiring_global_microseconds_total",
Help: "amount of time in microseconds that any database has spent waiting for the global lock",
}, []string{"type", "database"})
)
// LockStatsMap is a map of lock stats
type LockStatsMap map[string]LockStats
// ReadWriteLockTimes information about the lock
type ReadWriteLockTimes struct {
Read float64 `bson:"R"`
Write float64 `bson:"W"`
ReadLower float64 `bson:"r"`
WriteLower float64 `bson:"w"`
}
// LockStats lock stats
type LockStats struct {
TimeLockedMicros ReadWriteLockTimes `bson:"timeLockedMicros"`
TimeAcquiringMicros ReadWriteLockTimes `bson:"timeAcquiringMicros"`
}
// Export exports the data to prometheus.
func (locks LockStatsMap) Export(ch chan<- prometheus.Metric) {
for key, locks := range locks {
if key == "." {
key = "dot"
}
locksTimeLockedGlobalMicrosecondsTotal.WithLabelValues("read", key).Set(locks.TimeLockedMicros.Read)
locksTimeLockedGlobalMicrosecondsTotal.WithLabelValues("write", key).Set(locks.TimeLockedMicros.Write)
locksTimeLockedLocalMicrosecondsTotal.WithLabelValues("read", key).Set(locks.TimeLockedMicros.ReadLower)
locksTimeLockedLocalMicrosecondsTotal.WithLabelValues("write", key).Set(locks.TimeLockedMicros.WriteLower)
locksTimeAcquiringGlobalMicrosecondsTotal.WithLabelValues("read", key).Set(locks.TimeAcquiringMicros.ReadLower)
locksTimeAcquiringGlobalMicrosecondsTotal.WithLabelValues("write", key).Set(locks.TimeAcquiringMicros.WriteLower)
}
locksTimeLockedGlobalMicrosecondsTotal.Collect(ch)
locksTimeLockedLocalMicrosecondsTotal.Collect(ch)
locksTimeAcquiringGlobalMicrosecondsTotal.Collect(ch)
}
// Describe describes the metrics for prometheus
func (locks LockStatsMap) Describe(ch chan<- *prometheus.Desc) {
locksTimeLockedGlobalMicrosecondsTotal.Describe(ch)
locksTimeLockedLocalMicrosecondsTotal.Describe(ch)
locksTimeAcquiringGlobalMicrosecondsTotal.Describe(ch)
}
|