File: global_lock.go

package info (click to toggle)
prometheus-mongodb-exporter 1.0.0%2Bgit20180522.e755a44-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 668 kB
  • sloc: sh: 65; makefile: 27
file content (97 lines) | stat: -rw-r--r-- 3,612 bytes parent folder | download | duplicates (3)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package collector

import (
	"github.com/prometheus/client_golang/prometheus"
)

var (
	globalLockRatio = prometheus.NewGauge(prometheus.GaugeOpts{
		Namespace: Namespace,
		Subsystem: "global_lock",
		Name:      "ratio",
		Help:      "The value of ratio displays the relationship between lockTime and totalTime. Low values indicate that operations have held the globalLock frequently for shorter periods of time. High values indicate that operations have held globalLock infrequently for longer periods of time",
	})
	globalLockTotal = prometheus.NewGauge(prometheus.GaugeOpts{
		Namespace: Namespace,
		Subsystem: "global_lock",
		Name:      "total",
		Help:      "The value of totalTime represents the time, in microseconds, since the database last started and creation of the globalLock. This is roughly equivalent to total server uptime",
	})
	globalLockLockTotal = prometheus.NewCounter(prometheus.CounterOpts{
		Namespace: Namespace,
		Subsystem: "global_lock",
		Name:      "lock_total",
		Help:      "The value of lockTime represents the time, in microseconds, since the database last started, that the globalLock has been held",
	})
)
var (
	globalLockCurrentQueue = prometheus.NewGaugeVec(prometheus.GaugeOpts{
		Namespace: Namespace,
		Name:      "global_lock_current_queue",
		Help:      "The currentQueue data structure value provides more granular information concerning the number of operations queued because of a lock",
	}, []string{"type"})
)
var (
	globalLockClient = prometheus.NewGaugeVec(prometheus.GaugeOpts{
		Namespace: Namespace,
		Name:      "global_lock_client",
		Help:      "The activeClients data structure provides more granular information about the number of connected clients and the operation types (e.g. read or write) performed by these clients",
	}, []string{"type"})
)

// ClientStats metrics for client stats
type ClientStats struct {
	Total   float64 `bson:"total"`
	Readers float64 `bson:"readers"`
	Writers float64 `bson:"writers"`
}

// Export exports the metrics to prometheus
func (clientStats *ClientStats) Export(ch chan<- prometheus.Metric) {
	globalLockClient.WithLabelValues("reader").Set(clientStats.Readers)
	globalLockClient.WithLabelValues("writer").Set(clientStats.Writers)
}

// QueueStats queue stats
type QueueStats struct {
	Total   float64 `bson:"total"`
	Readers float64 `bson:"readers"`
	Writers float64 `bson:"writers"`
}

// Export exports the metrics to prometheus
func (queueStats *QueueStats) Export(ch chan<- prometheus.Metric) {
	globalLockCurrentQueue.WithLabelValues("reader").Set(queueStats.Readers)
	globalLockCurrentQueue.WithLabelValues("writer").Set(queueStats.Writers)
}

// GlobalLockStats global lock stats
type GlobalLockStats struct {
	TotalTime     float64      `bson:"totalTime"`
	LockTime      float64      `bson:"lockTime"`
	Ratio         float64      `bson:"ratio"`
	CurrentQueue  *QueueStats  `bson:"currentQueue"`
	ActiveClients *ClientStats `bson:"activeClients"`
}

// Export exports the metrics to prometheus
func (globalLock *GlobalLockStats) Export(ch chan<- prometheus.Metric) {
	globalLockTotal.Set(globalLock.LockTime)
	globalLockRatio.Set(globalLock.Ratio)

	globalLock.CurrentQueue.Export(ch)
	globalLock.ActiveClients.Export(ch)

	globalLockTotal.Collect(ch)
	globalLockRatio.Collect(ch)
	globalLockCurrentQueue.Collect(ch)
	globalLockClient.Collect(ch)
}

// Describe describes the metrics for prometheus
func (globalLock *GlobalLockStats) Describe(ch chan<- *prometheus.Desc) {
	globalLockTotal.Describe(ch)
	globalLockRatio.Describe(ch)
	globalLockCurrentQueue.Describe(ch)
	globalLockClient.Describe(ch)
}