Merge pull request #3789 from hairyhenderson/add-connection-type-label-to-weave-connection-metric-3788
Add new 'type' and 'encryption' labels to weave_connections metric
This commit is contained in:
6 files changed
+31
-6
No files matched your search
+22
-6
@@ -44,14 +44,30 @@ func uint64Counter(desc *prometheus.Desc, val uint64, labels ...string) promethe
|
||||
}
|
||||
|
||||
var metrics = []metric{
|
||||
{desc("weave_connections", "Number of peer-to-peer connections.", "state"),
|
||||
{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[string]int)
|
||||
for _, conn := range s.Router.Connections {
|
||||
counts[conn.State]++
|
||||
}
|
||||
counts := make(map[ /*state*/ string]map[ /*type*/ string]struct{ encrypted, unencrypted int })
|
||||
for _, state := range allConnectionStates {
|
||||
ch <- intGauge(desc, counts[state], state)
|
||||
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)
|
||||
}
|
||||
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.encrypted, state, connType, "yes")
|
||||
ch <- intGauge(desc, count.unencrypted, state, connType, "")
|
||||
}
|
||||
}
|
||||
}},
|
||||
{desc("weave_connection_terminations_total", "Number of peer-to-peer connections terminated."),
|
||||
|
||||
Reference in new issue
Block a user