File: cursors.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 (35 lines) | stat: -rw-r--r-- 1,085 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
package collector

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

var (
	cursorsGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{
		Namespace: Namespace,
		Name:      "cursors",
		Help:      "The cursors data structure contains data regarding cursor state and use",
	}, []string{"state"})
)

// Cursors are the cursor metrics
type Cursors struct {
	TotalOpen      float64 `bson:"totalOpen"`
	TimeOut        float64 `bson:"timedOut"`
	TotalNoTimeout float64 `bson:"totalNoTimeout"`
	Pinned         float64 `bson:"pinned"`
}

// Export exports the data to prometheus.
func (cursors *Cursors) Export(ch chan<- prometheus.Metric) {
	cursorsGauge.WithLabelValues("total_open").Set(cursors.TotalOpen)
	cursorsGauge.WithLabelValues("timed_out").Set(cursors.TimeOut)
	cursorsGauge.WithLabelValues("total_no_timeout").Set(cursors.TotalNoTimeout)
	cursorsGauge.WithLabelValues("pinned").Set(cursors.Pinned)
	cursorsGauge.Collect(ch)
}

// Describe describes the metrics for prometheus
func (cursors *Cursors) Describe(ch chan<- *prometheus.Desc) {
	cursorsGauge.Describe(ch)
}