-
Notifications
You must be signed in to change notification settings - Fork 4
/
glance.go
47 lines (39 loc) · 1.13 KB
/
glance.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
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/glance"
)
type GlanceExporter struct {
BaseOpenStackExporter
Client *glance.Client
}
var defaultGlanceMetrics = []Metric{
{Name: "images"},
}
func NewGlanceExporter(client client.AuthenticatingClient, prefix string, config *Cloud) (*GlanceExporter, error) {
exporter := GlanceExporter{BaseOpenStackExporter{
Name: "glance",
Prefix: prefix,
Config: config,
}, glance.New(client)}
for _, metric := range defaultGlanceMetrics {
exporter.AddMetric(metric.Name, metric.Labels, nil)
}
return &exporter, nil
}
func (exporter *GlanceExporter) Describe(ch chan<- *prometheus.Desc) {
for _, metric := range exporter.Metrics {
ch <- metric
}
}
func (exporter *GlanceExporter) Collect(ch chan<- prometheus.Metric) {
log.Infoln("Fetching images list")
images, err := exporter.Client.ListImagesV2()
if err != nil {
log.Errorf("%s", err)
}
ch <- prometheus.MustNewConstMetric(exporter.Metrics["images"],
prometheus.GaugeValue, float64(len(images)))
}