forked from openstack-exporter/openstack-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keystone.go
85 lines (72 loc) · 2.19 KB
/
keystone.go
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
"gopkg.in/niedbalski/goose.v3/client"
"gopkg.in/niedbalski/goose.v3/keystone"
)
type KeystoneExporter struct {
BaseOpenStackExporter
Client *keystone.Client
}
var defaultKeystoneMetrics = []Metric{
{Name: "domains"},
{Name: "users"},
{Name: "groups"},
{Name: "projects"},
{Name: "regions"},
}
func NewKeystoneExporter(client client.AuthenticatingClient, prefix string, config *Cloud) (*KeystoneExporter, error) {
exporter := KeystoneExporter{
BaseOpenStackExporter{
Name: "identity",
Prefix: prefix,
Config: config,
}, keystone.New(client)}
for _, metric := range defaultKeystoneMetrics {
exporter.AddMetric(metric.Name, metric.Labels, nil)
}
return &exporter, nil
}
func (exporter *KeystoneExporter) Describe(ch chan<- *prometheus.Desc) {
for _, metric := range exporter.Metrics {
ch <- metric
}
}
func (exporter *KeystoneExporter) Collect(ch chan<- prometheus.Metric) {
log.Infoln("Fetching domains information")
domains, err := exporter.Client.ListDomains()
if err != nil {
log.Errorln(err)
}
ch <- prometheus.MustNewConstMetric(exporter.Metrics["domains"],
prometheus.GaugeValue, float64(len(domains)))
log.Infoln("Fetching users information")
users, err := exporter.Client.ListUsers()
if err != nil {
log.Errorln(err)
}
ch <- prometheus.MustNewConstMetric(exporter.Metrics["users"],
prometheus.GaugeValue, float64(len(users)))
log.Infoln("Fetching projects information")
projects, err := exporter.Client.ListProjects()
if err != nil {
log.Errorln(err)
}
ch <- prometheus.MustNewConstMetric(exporter.Metrics["projects"],
prometheus.GaugeValue, float64(len(projects)))
log.Infoln("Fetching groups information")
groups, err := exporter.Client.ListGroups()
if err != nil {
log.Errorln(err)
}
ch <- prometheus.MustNewConstMetric(exporter.Metrics["groups"],
prometheus.GaugeValue, float64(len(groups)))
log.Infoln("Fetching regions information")
regions, err := exporter.Client.ListRegions()
if err != nil {
log.Errorln(err)
}
ch <- prometheus.MustNewConstMetric(exporter.Metrics["regions"],
prometheus.GaugeValue, float64(len(regions)))
}