File: network.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 (45 lines) | stat: -rw-r--r-- 1,578 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
package collector

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

var (
	networkBytesTotal = prometheus.NewGaugeVec(prometheus.GaugeOpts{
		Namespace: Namespace,
		Name:      "network_bytes_total",
		Help:      "The network data structure contains data regarding MongoDB's network use",
	}, []string{"state"})
)
var (
	networkMetricsNumRequestsTotal = prometheus.NewGauge(prometheus.GaugeOpts{
		Namespace: Namespace,
		Subsystem: "network_metrics",
		Name:      "num_requests_total",
		Help:      "The numRequests field is a counter of the total number of distinct requests that the server has received. Use this value to provide context for the bytesIn and bytesOut values to ensure that MongoDB's network utilization is consistent with expectations and application use",
	})
)

//NetworkStats network stats
type NetworkStats struct {
	BytesIn     float64 `bson:"bytesIn"`
	BytesOut    float64 `bson:"bytesOut"`
	NumRequests float64 `bson:"numRequests"`
}

// Export exports the data to prometheus
func (networkStats *NetworkStats) Export(ch chan<- prometheus.Metric) {
	networkBytesTotal.WithLabelValues("in_bytes").Set(networkStats.BytesIn)
	networkBytesTotal.WithLabelValues("out_bytes").Set(networkStats.BytesOut)

	networkMetricsNumRequestsTotal.Set(networkStats.NumRequests)

	networkMetricsNumRequestsTotal.Collect(ch)
	networkBytesTotal.Collect(ch)
}

// Describe describes the metrics for prometheus
func (networkStats *NetworkStats) Describe(ch chan<- *prometheus.Desc) {
	networkMetricsNumRequestsTotal.Describe(ch)
	networkBytesTotal.Describe(ch)
}