From 73be4f2a46b769de0a5a6a943d37a8fb573f4446 Mon Sep 17 00:00:00 2001 From: Dnile Date: Mon, 30 May 2016 14:43:03 -0700 Subject: [PATCH] added func getPercentile(t *topic, percentile int) float64 --- collector/stats.go | 11 +++++++++++ collector/stats_topic.go | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/collector/stats.go b/collector/stats.go index 0d4383a..ce37235 100644 --- a/collector/stats.go +++ b/collector/stats.go @@ -66,6 +66,17 @@ type client struct { TLS bool `json:"tls"` } +func getPercentile(t *topic, percentile int) float64 { + if len(t.E2eLatency.Percentiles) > 0 { + if percentile == 99 { + return t.E2eLatency.Percentiles[0]["value"] + } else if percentile == 95 { + return t.E2eLatency.Percentiles[1]["value"] + } + } + return 0 +} + func getNsqdStats(nsqdURL string) (*stats, error) { resp, err := http.Get(nsqdURL) diff --git a/collector/stats_topic.go b/collector/stats_topic.go index 5f0f127..96280d8 100644 --- a/collector/stats_topic.go +++ b/collector/stats_topic.go @@ -42,7 +42,7 @@ func TopicStats(namespace string) StatsCollector { }, labels), }, { - val: func(t *topic) float64 { return t.E2eLatency.Percentiles[0]["value"] }, + val: func(t *topic) float64 { return getPercentile(t, 99) }, vec: prometheus.NewGaugeVec(prometheus.GaugeOpts{ Namespace: namespace, Name: "e2e_latency_99_percentile", @@ -50,7 +50,7 @@ func TopicStats(namespace string) StatsCollector { }, labels), }, { - val: func(t *topic) float64 { return t.E2eLatency.Percentiles[1]["value"] }, + val: func(t *topic) float64 { return getPercentile(t, 95) }, vec: prometheus.NewGaugeVec(prometheus.GaugeOpts{ Namespace: namespace, Name: "e2e_latency_95_percentile",