From 846b6b5d9523ba2a859370b48fa8bb20d918d08b Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Tue, 4 Jun 2019 16:48:25 -0700 Subject: [PATCH 1/3] add unixfs get metric License: MIT Signed-off-by: whyrusleeping --- core/corehttp/gateway_handler.go | 2 ++ core/corehttp/metrics.go | 3 +++ 2 files changed, 5 insertions(+) diff --git a/core/corehttp/gateway_handler.go b/core/corehttp/gateway_handler.go index 3f212d9180b..91bfb19787c 100644 --- a/core/corehttp/gateway_handler.go +++ b/core/corehttp/gateway_handler.go @@ -123,6 +123,7 @@ func (i *gatewayHandler) optionsHandler(w http.ResponseWriter, r *http.Request) } func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request) { + begin := time.Now() urlPath := r.URL.Path escapedURLPath := r.URL.EscapedPath() @@ -172,6 +173,7 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request webError(w, "ipfs cat "+escapedURLPath, err, http.StatusNotFound) return } + unixfsGetMetric.Observe(time.Since(begin).Seconds()) defer dr.Close() diff --git a/core/corehttp/metrics.go b/core/corehttp/metrics.go index 3f8c68ccd84..92b5a3a82b3 100644 --- a/core/corehttp/metrics.go +++ b/core/corehttp/metrics.go @@ -97,6 +97,9 @@ var ( peersTotalMetric = prometheus.NewDesc( prometheus.BuildFQName("ipfs", "p2p", "peers_total"), "Number of connected peers", []string{"transport"}, nil) + unixfsGetMetric = prometheus.NewSummary(prometheus.SummaryOpts{ + Name: "unixfsGet", + }) ) type IpfsNodeCollector struct { From ebd89b4011c300601f7b1cfcda01ee51221b748b Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 4 Jun 2019 17:19:48 -0700 Subject: [PATCH 2/3] gateway: expand get metric metadata --- core/corehttp/metrics.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/corehttp/metrics.go b/core/corehttp/metrics.go index 92b5a3a82b3..7a7f30dd995 100644 --- a/core/corehttp/metrics.go +++ b/core/corehttp/metrics.go @@ -97,8 +97,12 @@ var ( peersTotalMetric = prometheus.NewDesc( prometheus.BuildFQName("ipfs", "p2p", "peers_total"), "Number of connected peers", []string{"transport"}, nil) + unixfsGetMetric = prometheus.NewSummary(prometheus.SummaryOpts{ - Name: "unixfsGet", + Namespace: "ipfs", + Subsystem: "http", + Name: "unixfs_get_latency_seconds", + Help: "The time till the first block is received when 'getting' a file from the gateway.", }) ) From d460150f4382b6439bd13c886d725b382ef6542f Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 4 Jun 2019 17:34:53 -0700 Subject: [PATCH 3/3] gateway: label get requests latency with the path namespace --- core/corehttp/gateway_handler.go | 3 ++- core/corehttp/metrics.go | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/core/corehttp/gateway_handler.go b/core/corehttp/gateway_handler.go index 91bfb19787c..1aa343a5502 100644 --- a/core/corehttp/gateway_handler.go +++ b/core/corehttp/gateway_handler.go @@ -173,7 +173,8 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request webError(w, "ipfs cat "+escapedURLPath, err, http.StatusNotFound) return } - unixfsGetMetric.Observe(time.Since(begin).Seconds()) + + unixfsGetMetric.WithLabelValues(parsedPath.Namespace()).Observe(time.Since(begin).Seconds()) defer dr.Close() diff --git a/core/corehttp/metrics.go b/core/corehttp/metrics.go index 7a7f30dd995..b0aebd3979b 100644 --- a/core/corehttp/metrics.go +++ b/core/corehttp/metrics.go @@ -98,12 +98,12 @@ var ( prometheus.BuildFQName("ipfs", "p2p", "peers_total"), "Number of connected peers", []string{"transport"}, nil) - unixfsGetMetric = prometheus.NewSummary(prometheus.SummaryOpts{ + unixfsGetMetric = prometheus.NewSummaryVec(prometheus.SummaryOpts{ Namespace: "ipfs", Subsystem: "http", Name: "unixfs_get_latency_seconds", Help: "The time till the first block is received when 'getting' a file from the gateway.", - }) + }, []string{"namespace"}) ) type IpfsNodeCollector struct {