File: durability.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 (110 lines) | stat: -rw-r--r-- 4,547 bytes parent folder | download | duplicates (5)
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
98
99
100
101
102
103
104
105
106
107
108
109
110
package collector

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

var (
	durabilityCommits = prometheus.NewGaugeVec(prometheus.GaugeOpts{
		Namespace: Namespace,
		Name:      "durability_commits",
		Help:      "Durability commits",
	}, []string{"state"})
)
var (
	durabilityJournaledMegabytes = prometheus.NewGauge(prometheus.GaugeOpts{
		Namespace: Namespace,
		Subsystem: "durability",
		Name:      "journaled_megabytes",
		Help:      "The journaledMB provides the amount of data in megabytes (MB) written to journal during the last journal group commit interval",
	})
	durabilityWriteToDataFilesMegabytes = prometheus.NewGauge(prometheus.GaugeOpts{
		Namespace: Namespace,
		Subsystem: "durability",
		Name:      "write_to_data_files_megabytes",
		Help:      "The writeToDataFilesMB provides the amount of data in megabytes (MB) written from journal to the data files during the last journal group commit interval",
	})
	durabilityCompression = prometheus.NewGauge(prometheus.GaugeOpts{
		Namespace: Namespace,
		Subsystem: "durability",
		Name:      "compression",
		Help:      "The compression represents the compression ratio of the data written to the journal: ( journaled_size_of_data / uncompressed_size_of_data )",
	})
	durabilityEarlyCommits = prometheus.NewSummary(prometheus.SummaryOpts{
		Namespace: Namespace,
		Subsystem: "durability",
		Name:      "early_commits",
		Help:      "The earlyCommits value reflects the number of times MongoDB requested a commit before the scheduled journal group commit interval. Use this value to ensure that your journal group commit interval is not too long for your deployment",
	})
)
var (
	durabilityTimeMilliseconds = prometheus.NewSummaryVec(prometheus.SummaryOpts{
		Namespace: Namespace,
		Name:      "durability_time_milliseconds",
		Help:      "Summary of times spent during the journaling process.",
	}, []string{"stage"})
)

// DurTiming is the information about durability returned from the server.
type DurTiming struct {
	Dt               float64 `bson:"dt"`
	PrepLogBuffer    float64 `bson:"prepLogBuffer"`
	WriteToJournal   float64 `bson:"writeToJournal"`
	WriteToDataFiles float64 `bson:"writeToDataFiles"`
	RemapPrivateView float64 `bson:"remapPrivateView"`
}

// Export exports the data for the prometheus server.
func (durTiming *DurTiming) Export(ch chan<- prometheus.Metric) {
	durabilityTimeMilliseconds.WithLabelValues("dt").Observe(durTiming.Dt)
	durabilityTimeMilliseconds.WithLabelValues("prep_log_buffer").Observe(durTiming.PrepLogBuffer)
	durabilityTimeMilliseconds.WithLabelValues("write_to_journal").Observe(durTiming.WriteToJournal)
	durabilityTimeMilliseconds.WithLabelValues("write_to_data_files").Observe(durTiming.WriteToDataFiles)
	durabilityTimeMilliseconds.WithLabelValues("remap_private_view").Observe(durTiming.RemapPrivateView)
	durabilityTimeMilliseconds.Collect(ch)
}

// DurStats are the stats related to durability.
type DurStats struct {
	Commits            float64   `bson:"commits"`
	JournaledMB        float64   `bson:"journaledMB"`
	WriteToDataFilesMB float64   `bson:"writeToDataFilesMB"`
	Compression        float64   `bson:"compression"`
	CommitsInWriteLock float64   `bson:"commitsInWriteLock"`
	EarlyCommits       float64   `bson:"earlyCommits"`
	TimeMs             DurTiming `bson:"timeMs"`
}

// Export export the durability stats for the prometheus server.
func (durStats *DurStats) Export(ch chan<- prometheus.Metric) {
	durabilityCommits.WithLabelValues("written").Set(durStats.Commits)
	durabilityCommits.WithLabelValues("in_write_lock").Set(durStats.CommitsInWriteLock)

	durabilityJournaledMegabytes.Set(durStats.JournaledMB)
	durabilityWriteToDataFilesMegabytes.Set(durStats.WriteToDataFilesMB)
	durabilityCompression.Set(durStats.Compression)
	durabilityEarlyCommits.Observe(durStats.EarlyCommits)

	durStats.TimeMs.Export(ch)

	durStats.Collect(ch)
}

// Collect collects the metrics for prometheus
func (durStats *DurStats) Collect(ch chan<- prometheus.Metric) {
	durabilityCommits.Collect(ch)
	durabilityJournaledMegabytes.Collect(ch)
	durabilityWriteToDataFilesMegabytes.Collect(ch)
	durabilityCompression.Collect(ch)
	durabilityEarlyCommits.Collect(ch)
}

// Describe describes the metrics for prometheus
func (durStats *DurStats) Describe(ch chan<- *prometheus.Desc) {
	durabilityCommits.Describe(ch)
	durabilityJournaledMegabytes.Describe(ch)
	durabilityWriteToDataFilesMegabytes.Describe(ch)
	durabilityCompression.Describe(ch)
	durabilityEarlyCommits.Describe(ch)
	durabilityTimeMilliseconds.Describe(ch)
}