Add 'encrypted' label to connections metric

Extend tests to check it shows up.
Tests assume that metrics are published with metrics in alphabetical
order, which appears to be the case for now.
This commit is contained in:
Bryan Boreham committed 2020-07-30 11:07:33 +00:00
1 parent 865e2b726f
commit 2cc5c635c9
5 files changed
+17 -6

No files matched your search

+12 -5
View File
@@ -44,22 +44,29 @@ func uint64Counter(desc *prometheus.Desc, val uint64, labels ...string) promethe
}
var metrics = []metric{
{desc("weave_connections", "Number of peer-to-peer connections.", "state", "type"),
{desc("weave_connections", "Number of peer-to-peer connections.", "state", "type", "encryption"),
func(s WeaveStatus, desc *prometheus.Desc, ch chan<- prometheus.Metric) {
counts := make(map[ /*state*/ string]map[ /*type*/ string]int)
counts := make(map[ /*state*/ string]map[ /*type*/ string]struct{ encrypted, unencrypted int })
for _, state := range allConnectionStates {
counts[state] = make(map[string]int)
counts[state] = make(map[string]struct{ encrypted, unencrypted int })
}
for _, conn := range s.Router.Connections {
typeName := "unknown"
if t, ok := conn.Attrs["name"]; ok {
typeName = t.(string)
}
counts[conn.State][typeName]++
c := counts[conn.State][typeName]
if e, ok := conn.Attrs["encrypted"]; ok && e.(bool) {
c.encrypted++
} else {
c.unencrypted++
}
counts[conn.State][typeName] = c
}
for state, stateCounts := range counts {
for connType, count := range stateCounts {
ch <- intGauge(desc, count, state, connType)
ch <- intGauge(desc, count.encrypted, state, connType, "yes")
ch <- intGauge(desc, count.unencrypted, state, connType, "")
}
}
}},