Skip to content

Commit 37cf45b

Browse files
committed
Improve Prometheus labeling
1 parent d64a6c6 commit 37cf45b

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

http_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func TestHTTP(t *testing.T) {
146146
if response != nil {
147147
assert.Equal(200, response.StatusCode)
148148
bytes, _ := ioutil.ReadAll(response.Body)
149-
assert.Contains(string(bytes), "sshproxy_connections_established 1")
149+
assert.Contains(string(bytes), `sshproxy_connections_total{state="established"} 1`)
150150
}
151151
}
152152

metrics.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,21 @@ type prometheusExporter struct {
1515
var (
1616
metrics = prometheusExporter{}
1717

18-
sshConnEstablishedDesc = prometheus.NewDesc("sshproxy_connections_established", "Established SSH connections", nil, nil)
19-
sshConnFailedDesc = prometheus.NewDesc("sshproxy_connections_failed", "Failed SSH connections", nil, nil)
20-
sshForwardEstablishedDesc = prometheus.NewDesc("sshproxy_forwardings_established", "Established SSH forwardings", nil, nil)
21-
sshForwardFailedDesc = prometheus.NewDesc("sshproxy_forwardings_failed", "Failed SSH forwardings", nil, nil)
18+
variableLabels = []string{"state"}
19+
sshConnectionsDesc = prometheus.NewDesc("sshproxy_connections_total", "SSH connections", variableLabels, nil)
20+
sshForwardingsDesc = prometheus.NewDesc("sshproxy_forwardings_total", "TCP forwardings", variableLabels, nil)
2221
)
2322

2423
// Describe implements (part of the) prometheus.Collector interface.
2524
func (e *prometheusExporter) Describe(c chan<- *prometheus.Desc) {
26-
c <- sshConnEstablishedDesc
27-
c <- sshConnFailedDesc
28-
c <- sshForwardEstablishedDesc
29-
c <- sshForwardFailedDesc
25+
c <- sshConnectionsDesc
26+
c <- sshForwardingsDesc
3027
}
3128

3229
// Collect implements (part of the) prometheus.Collector interface.
3330
func (e prometheusExporter) Collect(c chan<- prometheus.Metric) {
34-
c <- prometheus.MustNewConstMetric(sshConnEstablishedDesc, prometheus.CounterValue, float64(e.connections.established))
35-
c <- prometheus.MustNewConstMetric(sshConnFailedDesc, prometheus.CounterValue, float64(e.connections.failed))
36-
c <- prometheus.MustNewConstMetric(sshForwardEstablishedDesc, prometheus.CounterValue, float64(e.forwardings.established))
37-
c <- prometheus.MustNewConstMetric(sshForwardFailedDesc, prometheus.CounterValue, float64(e.forwardings.failed))
31+
c <- prometheus.MustNewConstMetric(sshConnectionsDesc, prometheus.CounterValue, float64(e.connections.established), "established")
32+
c <- prometheus.MustNewConstMetric(sshConnectionsDesc, prometheus.CounterValue, float64(e.connections.failed), "failed")
33+
c <- prometheus.MustNewConstMetric(sshForwardingsDesc, prometheus.CounterValue, float64(e.forwardings.established), "established")
34+
c <- prometheus.MustNewConstMetric(sshForwardingsDesc, prometheus.CounterValue, float64(e.forwardings.failed), "failed")
3835
}

0 commit comments

Comments
 (0)