-
Notifications
You must be signed in to change notification settings - Fork 17
/
deployments_collector.go
146 lines (127 loc) · 4.32 KB
/
deployments_collector.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package collectors
import (
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/bosh-prometheus/bosh_exporter/deployments"
)
type DeploymentsCollector struct {
deploymentReleaseInfoMetric *prometheus.GaugeVec
deploymentStemcellInfoMetric *prometheus.GaugeVec
lastDeploymentsScrapeTimestampMetric prometheus.Gauge
lastDeploymentsScrapeDurationSecondsMetric prometheus.Gauge
}
func NewDeploymentsCollector(
namespace string,
environment string,
boshName string,
boshUUID string,
) *DeploymentsCollector {
deploymentReleaseInfoMetric := prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: "deployment",
Name: "release_info",
Help: "Labeled BOSH Deployment Release Info with a constant '1' value.",
ConstLabels: prometheus.Labels{
"environment": environment,
"bosh_name": boshName,
"bosh_uuid": boshUUID,
},
},
[]string{"bosh_deployment", "bosh_release_name", "bosh_release_version"},
)
deploymentStemcellInfoMetric := prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: "deployment",
Name: "stemcell_info",
Help: "Labeled BOSH Deployment Stemcell Info with a constant '1' value.",
ConstLabels: prometheus.Labels{
"environment": environment,
"bosh_name": boshName,
"bosh_uuid": boshUUID,
},
},
[]string{"bosh_deployment", "bosh_stemcell_name", "bosh_stemcell_version", "bosh_stemcell_os_name"},
)
lastDeploymentsScrapeTimestampMetric := prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: "",
Name: "last_deployments_scrape_timestamp",
Help: "Number of seconds since 1970 since last scrape of Deployments metrics from BOSH.",
ConstLabels: prometheus.Labels{
"environment": environment,
"bosh_name": boshName,
"bosh_uuid": boshUUID,
},
},
)
lastDeploymentsScrapeDurationSecondsMetric := prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: "",
Name: "last_deployments_scrape_duration_seconds",
Help: "Duration of the last scrape of Deployments metrics from BOSH.",
ConstLabels: prometheus.Labels{
"environment": environment,
"bosh_name": boshName,
"bosh_uuid": boshUUID,
},
},
)
collector := &DeploymentsCollector{
deploymentReleaseInfoMetric: deploymentReleaseInfoMetric,
deploymentStemcellInfoMetric: deploymentStemcellInfoMetric,
lastDeploymentsScrapeTimestampMetric: lastDeploymentsScrapeTimestampMetric,
lastDeploymentsScrapeDurationSecondsMetric: lastDeploymentsScrapeDurationSecondsMetric,
}
return collector
}
func (c *DeploymentsCollector) Collect(deployments []deployments.DeploymentInfo, ch chan<- prometheus.Metric) error {
var begun = time.Now()
c.deploymentReleaseInfoMetric.Reset()
c.deploymentStemcellInfoMetric.Reset()
for _, deployment := range deployments {
c.reportDeploymentReleaseInfoMetrics(deployment, ch)
c.reportDeploymentStemcellInfoMetrics(deployment, ch)
}
c.deploymentReleaseInfoMetric.Collect(ch)
c.deploymentStemcellInfoMetric.Collect(ch)
c.lastDeploymentsScrapeTimestampMetric.Set(float64(time.Now().Unix()))
c.lastDeploymentsScrapeTimestampMetric.Collect(ch)
c.lastDeploymentsScrapeDurationSecondsMetric.Set(time.Since(begun).Seconds())
c.lastDeploymentsScrapeDurationSecondsMetric.Collect(ch)
return nil
}
func (c *DeploymentsCollector) Describe(ch chan<- *prometheus.Desc) {
c.deploymentReleaseInfoMetric.Describe(ch)
c.deploymentStemcellInfoMetric.Describe(ch)
c.lastDeploymentsScrapeTimestampMetric.Describe(ch)
c.lastDeploymentsScrapeDurationSecondsMetric.Describe(ch)
}
func (c *DeploymentsCollector) reportDeploymentReleaseInfoMetrics(
deployment deployments.DeploymentInfo,
ch chan<- prometheus.Metric,
) {
for _, release := range deployment.Releases {
c.deploymentReleaseInfoMetric.WithLabelValues(
deployment.Name,
release.Name,
release.Version,
).Set(float64(1))
}
}
func (c *DeploymentsCollector) reportDeploymentStemcellInfoMetrics(
deployment deployments.DeploymentInfo,
ch chan<- prometheus.Metric,
) {
for _, stemcell := range deployment.Stemcells {
c.deploymentStemcellInfoMetric.WithLabelValues(
deployment.Name,
stemcell.Name,
stemcell.Version,
stemcell.OSName,
).Set(float64(1))
}
}