From 86d68c987507d62b24918af6c76804de5d751772 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Tue, 1 Nov 2016 17:57:12 +0000 Subject: [PATCH 1/3] Move total IPs in range from a state to a separate metric --- prog/weaver/metrics.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/prog/weaver/metrics.go b/prog/weaver/metrics.go index 4f6a5a64..721d37e5 100644 --- a/prog/weaver/metrics.go +++ b/prog/weaver/metrics.go @@ -63,10 +63,15 @@ var metrics []metric = []metric{ {desc("weave_ips", "Number of IP addresses.", "state"), func(s WeaveStatus, desc *prometheus.Desc, ch chan<- prometheus.Metric) { if s.IPAM != nil { - ch <- intGauge(desc, s.IPAM.RangeNumIPs, "total") ch <- intGauge(desc, s.IPAM.ActiveIPs, "local-used") } }}, + {desc("weave_max_ips", "Number of IP addresses used by allocator."), + func(s WeaveStatus, desc *prometheus.Desc, ch chan<- prometheus.Metric) { + if s.IPAM != nil { + ch <- intGauge(desc, s.IPAM.RangeNumIPs) + } + }}, {desc("weave_dns_entries", "Number of DNS entries.", "state"), func(s WeaveStatus, desc *prometheus.Desc, ch chan<- prometheus.Metric) { if s.DNS != nil { From 2b4da35b1cf6d3aabed8e14297f07193feec1c55 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Tue, 1 Nov 2016 18:00:26 +0000 Subject: [PATCH 2/3] Remove 'total' DNS entries; let the caller add them up --- prog/weaver/metrics.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/prog/weaver/metrics.go b/prog/weaver/metrics.go index 721d37e5..b56a4c68 100644 --- a/prog/weaver/metrics.go +++ b/prog/weaver/metrics.go @@ -72,11 +72,10 @@ var metrics []metric = []metric{ ch <- intGauge(desc, s.IPAM.RangeNumIPs) } }}, - {desc("weave_dns_entries", "Number of DNS entries.", "state"), + {desc("weave_dns_entries", "Number of DNS entries."), func(s WeaveStatus, desc *prometheus.Desc, ch chan<- prometheus.Metric) { if s.DNS != nil { - ch <- intGauge(desc, countDNSEntries(s.DNS.Entries), "total") - ch <- intGauge(desc, countDNSEntriesForPeer(s.Router.Name, s.DNS.Entries), "local") + ch <- intGauge(desc, countDNSEntriesForPeer(s.Router.Name, s.DNS.Entries)) } }}, {desc("weave_flows", "Number of FastDP flows."), From eb60f68df2df3670820a532c73c4065a0bb78573 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Tue, 1 Nov 2016 18:13:33 +0000 Subject: [PATCH 3/3] 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)