Skip to content

Commit 8bc36b3

Browse files
Anton KucherovAlekSi
authored andcommitted
PMM-4168 Converting forgotten metrics.
1 parent 3335faa commit 8bc36b3

File tree

1 file changed

+26
-30
lines changed

1 file changed

+26
-30
lines changed

collector/common/op_counters.go

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@ import (
1818
"github.com/prometheus/client_golang/prometheus"
1919
)
2020

21-
// TODO convert to counter
2221
var (
23-
opCountersTotal = prometheus.NewGaugeVec(prometheus.GaugeOpts{
24-
Namespace: Namespace,
25-
Name: "op_counters_total",
26-
Help: "The opcounters data structure provides an overview of database operations by type and makes it possible to analyze the load on the database in more granular manner. These numbers will grow over time and in response to database use. Analyze these values over time to track database utilization",
27-
}, []string{"type"})
22+
opCountersTotalDesc = prometheus.NewDesc(
23+
prometheus.BuildFQName(Namespace, "", "op_counters_total"),
24+
"The opcounters data structure provides an overview of database operations by type and makes it possible to analyze the load on the database in more granular manner. These numbers will grow over time and in response to database use. Analyze these values over time to track database utilization",
25+
[]string{"type"},
26+
nil,
27+
)
2828
)
2929

30-
// TODO convert to counter
3130
var (
32-
opCountersReplTotal = prometheus.NewGaugeVec(prometheus.GaugeOpts{
33-
Namespace: Namespace,
34-
Name: "op_counters_repl_total",
35-
Help: "The opcountersRepl data structure, similar to the opcounters data structure, provides an overview of database replication operations by type and makes it possible to analyze the load on the replica in more granular manner. These values only appear when the current host has replication enabled",
36-
}, []string{"type"})
31+
opCountersReplTotalDesc = prometheus.NewDesc(
32+
prometheus.BuildFQName(Namespace, "", "op_counters_repl_total"),
33+
"The opcountersRepl data structure, similar to the opcounters data structure, provides an overview of database replication operations by type and makes it possible to analyze the load on the replica in more granular manner. These values only appear when the current host has replication enabled",
34+
[]string{"type"},
35+
nil,
36+
)
3737
)
3838

3939
// OpcountersStats opcounters stats
@@ -48,19 +48,17 @@ type OpcountersStats struct {
4848

4949
// Export exports the data to prometheus.
5050
func (opCounters *OpcountersStats) Export(ch chan<- prometheus.Metric) {
51-
opCountersTotal.WithLabelValues("insert").Set(opCounters.Insert)
52-
opCountersTotal.WithLabelValues("query").Set(opCounters.Query)
53-
opCountersTotal.WithLabelValues("update").Set(opCounters.Update)
54-
opCountersTotal.WithLabelValues("delete").Set(opCounters.Delete)
55-
opCountersTotal.WithLabelValues("getmore").Set(opCounters.GetMore)
56-
opCountersTotal.WithLabelValues("command").Set(opCounters.Command)
57-
58-
opCountersTotal.Collect(ch)
51+
ch <- prometheus.MustNewConstMetric(opCountersTotalDesc, prometheus.CounterValue, opCounters.Insert, "insert")
52+
ch <- prometheus.MustNewConstMetric(opCountersTotalDesc, prometheus.CounterValue, opCounters.Query, "query")
53+
ch <- prometheus.MustNewConstMetric(opCountersTotalDesc, prometheus.CounterValue, opCounters.Update, "update")
54+
ch <- prometheus.MustNewConstMetric(opCountersTotalDesc, prometheus.CounterValue, opCounters.Delete, "delete")
55+
ch <- prometheus.MustNewConstMetric(opCountersTotalDesc, prometheus.CounterValue, opCounters.GetMore, "getmore")
56+
ch <- prometheus.MustNewConstMetric(opCountersTotalDesc, prometheus.CounterValue, opCounters.Command, "command")
5957
}
6058

6159
// Describe describes the metrics for prometheus
6260
func (opCounters *OpcountersStats) Describe(ch chan<- *prometheus.Desc) {
63-
opCountersTotal.Describe(ch)
61+
ch <- opCountersTotalDesc
6462
}
6563

6664
// OpcountersReplStats opcounters stats
@@ -75,17 +73,15 @@ type OpcountersReplStats struct {
7573

7674
// Export exports the data to prometheus.
7775
func (opCounters *OpcountersReplStats) Export(ch chan<- prometheus.Metric) {
78-
opCountersReplTotal.WithLabelValues("insert").Set(opCounters.Insert)
79-
opCountersReplTotal.WithLabelValues("query").Set(opCounters.Query)
80-
opCountersReplTotal.WithLabelValues("update").Set(opCounters.Update)
81-
opCountersReplTotal.WithLabelValues("delete").Set(opCounters.Delete)
82-
opCountersReplTotal.WithLabelValues("getmore").Set(opCounters.GetMore)
83-
opCountersReplTotal.WithLabelValues("command").Set(opCounters.Command)
84-
85-
opCountersReplTotal.Collect(ch)
76+
ch <- prometheus.MustNewConstMetric(opCountersReplTotalDesc, prometheus.CounterValue, opCounters.Insert, "insert")
77+
ch <- prometheus.MustNewConstMetric(opCountersReplTotalDesc, prometheus.CounterValue, opCounters.Query, "query")
78+
ch <- prometheus.MustNewConstMetric(opCountersReplTotalDesc, prometheus.CounterValue, opCounters.Update, "update")
79+
ch <- prometheus.MustNewConstMetric(opCountersReplTotalDesc, prometheus.CounterValue, opCounters.Delete, "delete")
80+
ch <- prometheus.MustNewConstMetric(opCountersReplTotalDesc, prometheus.CounterValue, opCounters.GetMore, "getmore")
81+
ch <- prometheus.MustNewConstMetric(opCountersReplTotalDesc, prometheus.CounterValue, opCounters.Command, "command")
8682
}
8783

8884
// Describe describes the metrics for prometheus
8985
func (opCounters *OpcountersReplStats) Describe(ch chan<- *prometheus.Desc) {
90-
opCountersReplTotal.Describe(ch)
86+
ch <- opCountersReplTotalDesc
9187
}

0 commit comments

Comments
 (0)