diff options
Diffstat (limited to 'echo/prometheus/prometheus.go')
-rw-r--r-- | echo/prometheus/prometheus.go | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/echo/prometheus/prometheus.go b/echo/prometheus/prometheus.go index 616e425..2fbf252 100644 --- a/echo/prometheus/prometheus.go +++ b/echo/prometheus/prometheus.go | |||
@@ -14,7 +14,7 @@ import ( | |||
14 | ) | 14 | ) |
15 | 15 | ||
16 | type Prometheus struct { | 16 | type Prometheus struct { |
17 | config *PrometheusConfig | 17 | Config *PrometheusConfig |
18 | requestCount *prometheus.CounterVec | 18 | requestCount *prometheus.CounterVec |
19 | requestDuration *prometheus.HistogramVec | 19 | requestDuration *prometheus.HistogramVec |
20 | requestSize *prometheus.HistogramVec | 20 | requestSize *prometheus.HistogramVec |
@@ -65,7 +65,7 @@ func NewPrometheusWithConfig(c *PrometheusConfig) *Prometheus { | |||
65 | } | 65 | } |
66 | 66 | ||
67 | return &Prometheus{ | 67 | return &Prometheus{ |
68 | config: c, | 68 | Config: c, |
69 | MetricsHandler: echo.WrapHandler(promhttp.Handler()), | 69 | MetricsHandler: echo.WrapHandler(promhttp.Handler()), |
70 | requestCount: promauto.NewCounterVec(prometheus.CounterOpts{ | 70 | requestCount: promauto.NewCounterVec(prometheus.CounterOpts{ |
71 | Subsystem: c.Subsystem, | 71 | Subsystem: c.Subsystem, |
@@ -92,11 +92,11 @@ func NewPrometheusWithConfig(c *PrometheusConfig) *Prometheus { | |||
92 | 92 | ||
93 | func (p *Prometheus) MiddlewareHandler(next echo.HandlerFunc) echo.HandlerFunc { | 93 | func (p *Prometheus) MiddlewareHandler(next echo.HandlerFunc) echo.HandlerFunc { |
94 | return func(c echo.Context) error { | 94 | return func(c echo.Context) error { |
95 | if c.Path() == p.config.MetricsPath { | 95 | if c.Path() == p.Config.MetricsPath { |
96 | return next(c) | 96 | return next(c) |
97 | } | 97 | } |
98 | 98 | ||
99 | if p.config.Skipper(c) { | 99 | if p.Config.Skipper(c) { |
100 | return next(c) | 100 | return next(c) |
101 | } | 101 | } |
102 | 102 | ||
@@ -116,9 +116,9 @@ func (p *Prometheus) MiddlewareHandler(next echo.HandlerFunc) echo.HandlerFunc { | |||
116 | } | 116 | } |
117 | } | 117 | } |
118 | 118 | ||
119 | url := p.config.ExtractUrl(c) | 119 | url := p.Config.ExtractUrl(c) |
120 | if len(p.config.ContextLabel) > 0 { | 120 | if len(p.Config.ContextLabel) > 0 { |
121 | u := c.Get(p.config.ContextLabel) | 121 | u := c.Get(p.Config.ContextLabel) |
122 | if u == nil { | 122 | if u == nil { |
123 | u = "unknown" | 123 | u = "unknown" |
124 | } | 124 | } |
@@ -128,7 +128,7 @@ func (p *Prometheus) MiddlewareHandler(next echo.HandlerFunc) echo.HandlerFunc { | |||
128 | s := strconv.Itoa(status) | 128 | s := strconv.Itoa(status) |
129 | m := c.Request().Method | 129 | m := c.Request().Method |
130 | p.requestDuration.WithLabelValues(s, m, url).Observe(elapsed) | 130 | p.requestDuration.WithLabelValues(s, m, url).Observe(elapsed) |
131 | p.requestCount.WithLabelValues(s, m, p.config.ExtractHost(c), url).Inc() | 131 | p.requestCount.WithLabelValues(s, m, p.Config.ExtractHost(c), url).Inc() |
132 | p.requestSize.WithLabelValues(s, m, url).Observe(float64(reqSz)) | 132 | p.requestSize.WithLabelValues(s, m, url).Observe(float64(reqSz)) |
133 | p.responseSize.WithLabelValues(s, m, url).Observe(float64(c.Response().Size)) | 133 | p.responseSize.WithLabelValues(s, m, url).Observe(float64(c.Response().Size)) |
134 | 134 | ||