forked from claranet/rubrik-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
export_vm.go
110 lines (97 loc) · 3.08 KB
/
export_vm.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//
// rubrik-exporter
//
// Exports metrics from rubrik backup for prometheus
//
// License: Apache License Version 2.0,
// Organization: Claranet GmbH
// Author: Martin Weber <[email protected]>
//
package main
import (
"strings"
"github.com/claranet/rubrik-exporter/rubrik"
"github.com/prometheus/client_golang/prometheus"
)
// VMStats ...
type VMStats struct {
VMIsProtected *prometheus.GaugeVec
VMLogicalBytes *prometheus.GaugeVec
VMIngestedBytes *prometheus.GaugeVec
VMExclusiveBytes *prometheus.GaugeVec
VMSharedPhysicalbytes *prometheus.GaugeVec
VMIndexStorageBytes *prometheus.GaugeVec
}
// Describe ...
func (e VMStats) Describe(ch chan<- *prometheus.Desc) {
e.VMIsProtected.Describe(ch)
e.VMExclusiveBytes.Describe(ch)
e.VMIndexStorageBytes.Describe(ch)
e.VMIngestedBytes.Describe(ch)
e.VMLogicalBytes.Describe(ch)
e.VMSharedPhysicalbytes.Describe(ch)
}
// Collect ...
func (e *VMStats) Collect(ch chan<- prometheus.Metric) {
storages := make(map[string]rubrik.VmStorage)
for _, s := range rubrikAPI.GetPerVMStorage() {
storages[s.ID] = s
}
vms := rubrikAPI.ListAllVM()
for _, vm := range vms {
shortID := strings.Split(vm.ID, ":::")[1]
strg := storages[shortID]
var g prometheus.Gauge
g = e.VMIsProtected.WithLabelValues(vm.Name, vm.ID)
if vm.EffectiveSLADomainID == "UNPROTECTED" {
g.Set(0)
} else {
g.Set(1)
}
g.Collect(ch)
g = e.VMExclusiveBytes.WithLabelValues(vm.Name, vm.ID)
g.Set(float64(strg.ExclusivePhysicalBytes))
g.Collect(ch)
g = e.VMIndexStorageBytes.WithLabelValues(vm.Name, vm.ID)
g.Set(float64(strg.IndexStorageBytes))
g.Collect(ch)
g = e.VMIngestedBytes.WithLabelValues(vm.Name, vm.ID)
g.Set(float64(strg.IndexStorageBytes))
g.Collect(ch)
g = e.VMLogicalBytes.WithLabelValues(vm.Name, vm.ID)
g.Set(float64(strg.Logicalbytes))
g.Collect(ch)
g = e.VMSharedPhysicalbytes.WithLabelValues(vm.Name, vm.ID)
g.Set(float64(strg.SharedPhysicalBytes))
g.Collect(ch)
}
}
// NewVMStatsExport ...
func NewVMStatsExport() *VMStats {
return &VMStats{
VMIsProtected: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: namespace, Name: "vm_protected",
Help: "...",
}, []string{"vmname", "vmid"}),
VMExclusiveBytes: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: namespace, Name: "vm_consumed_exclusive_bytes",
Help: "...",
}, []string{"vmname", "vmid"}),
VMIndexStorageBytes: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: namespace, Name: "vm_consumed_index_storage_bytes",
Help: "...",
}, []string{"vmname", "vmid"}),
VMIngestedBytes: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: namespace, Name: "vm_consumed_ingested_bytes",
Help: "...",
}, []string{"vmname", "vmid"}),
VMLogicalBytes: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: namespace, Name: "vm_consumed_logical_bytes",
Help: "...",
}, []string{"vmname", "vmid"}),
VMSharedPhysicalbytes: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: namespace, Name: "vm_consumed_shared_physical_bytes",
Help: "...",
}, []string{"vmname", "vmid"}),
}
}