File: conn_pool_stats_hosts.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 (62 lines) | stat: -rw-r--r-- 1,688 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
package collector

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

var (
	inUse = prometheus.NewGaugeVec(prometheus.GaugeOpts{
		Namespace: Namespace,
		Subsystem: "connpoolstats",
		Name:      "in_use",
		Help:      "Corresponds to the total number of client connections to mongo.",
		// TODO: tags
	}, []string{"host"})

	available = prometheus.NewGaugeVec(prometheus.GaugeOpts{
		Namespace: Namespace,
		Subsystem: "connpoolstats",
		// TODO
		Name: "available",
		Help: "Corresponds to the total number of client connections to mongo.",
	}, []string{"host"})

	created = prometheus.NewGaugeVec(prometheus.GaugeOpts{
		Namespace: Namespace,
		Subsystem: "connpoolstats",
		// TODO
		Name: "created",
		Help: "Corresponds to the total number of client connections to mongo.",
	}, []string{"host"})
)

// ServerStatus keeps the data returned by the serverStatus() method.
type HostConnPoolStats struct {
	InUse     float64 `bson:"inUse"`
	Available float64 `bson:"available"`
	Created   float64 `bson:"created"`
}

// Export exports the server status to be consumed by prometheus.
func (stats *HostConnPoolStats) Export(hostname string, ch chan<- prometheus.Metric) {
	inUse.WithLabelValues(hostname).Set(float64(stats.InUse))
	inUse.Collect(ch)
	inUse.Reset()

	available.WithLabelValues(hostname).Set(float64(stats.Available))
	available.Collect(ch)
	available.Reset()

	created.WithLabelValues(hostname).Set(float64(stats.Created))
	created.Collect(ch)
	created.Reset()
}

// Describe describes the server status for prometheus.
func (stats *HostConnPoolStats) Describe(ch chan<- *prometheus.Desc) {
	inUse.Describe(ch)

	available.Describe(ch)

	created.Describe(ch)
}