From eb60f68df2df3670820a532c73c4065a0bb78573 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Tue, 1 Nov 2016 18:13:33 +0000 Subject: [PATCH] Report metrics on all connection states --- prog/weaver/http.go | 4 +++- prog/weaver/metrics.go | 14 ++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/prog/weaver/http.go b/prog/weaver/http.go index ed628033..1d87255e 100644 --- a/prog/weaver/http.go +++ b/prog/weaver/http.go @@ -19,6 +19,8 @@ import ( weave "github.com/weaveworks/weave/router" ) +var allConnectionStates = []string{"established", "pending", "retrying", "failed", "connecting"} + var rootTemplate = template.New("root").Funcs(map[string]interface{}{ "countDNSEntries": countDNSEntries, "printList": func(list []string) string { @@ -87,7 +89,7 @@ var rootTemplate = template.New("root").Funcs(map[string]interface{}{ for _, conn := range conns { counts[conn.State]++ } - return printCounts(counts, []string{"established", "pending", "retrying", "failed", "connecting"}) + return printCounts(counts, allConnectionStates) }, "printPeerConnectionCounts": func(peers []mesh.PeerStatus) string { counts := make(map[string]int) diff --git a/prog/weaver/metrics.go b/prog/weaver/metrics.go index b56a4c68..296dd620 100644 --- a/prog/weaver/metrics.go +++ b/prog/weaver/metrics.go @@ -46,15 +46,13 @@ func uint64Counter(desc *prometheus.Desc, val uint64, labels ...string) promethe var metrics []metric = []metric{ {desc("weave_connections", "Number of peer-to-peer connections.", "state"), func(s WeaveStatus, desc *prometheus.Desc, ch chan<- prometheus.Metric) { - established := 0 + counts := make(map[string]int) for _, conn := range s.Router.Connections { - if conn.State == "established" { - established++ - } + counts[conn.State]++ + } + for _, state := range allConnectionStates { + ch <- intGauge(desc, counts[state], state) } - - ch <- intGauge(desc, len(s.Router.Connections)-established, "non-established") - ch <- intGauge(desc, established, "established") }}, {desc("weave_connection_terminations_total", "Number of peer-to-peer connections terminated."), func(s WeaveStatus, desc *prometheus.Desc, ch chan<- prometheus.Metric) { @@ -66,7 +64,7 @@ var metrics []metric = []metric{ ch <- intGauge(desc, s.IPAM.ActiveIPs, "local-used") } }}, - {desc("weave_max_ips", "Number of IP addresses used by allocator."), + {desc("weave_max_ips", "Size of IP address space used by allocator."), func(s WeaveStatus, desc *prometheus.Desc, ch chan<- prometheus.Metric) { if s.IPAM != nil { ch <- intGauge(desc, s.IPAM.RangeNumIPs)