File: top_status.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 (41 lines) | stat: -rw-r--r-- 960 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
package collector

import (
	"github.com/golang/glog"
	"github.com/prometheus/client_golang/prometheus"
	"gopkg.in/mgo.v2"
	"gopkg.in/mgo.v2/bson"
)

// TopStatus represents top metrics
type TopStatus struct {
	TopStats TopStatsMap `bson:"totals,omitempty"`
}

// GetTopStats fetches top stats
func GetTopStats(session *mgo.Session) (*TopStatus, error) {
	results := &TopStatus{}
	err := session.DB("admin").Run(bson.D{{"top", 1}}, &results)
	return results, err
}

// Export exports metrics to Prometheus
func (status *TopStatus) Export(ch chan<- prometheus.Metric) {
	status.TopStats.Export(ch)
}

// Describe describes metrics collected
func (status *TopStatus) Describe(ch chan<- *prometheus.Desc) {
	status.TopStats.Describe(ch)
}

// GetTopStatus fetches top stats
func GetTopStatus(session *mgo.Session) *TopStatus {
	topStatus, err := GetTopStats(session)
	if err != nil {
		glog.Error("Failed to get top status.")
		return nil
	}

	return topStatus
}