0
Fork 0
mirror of https://github.com/willnorris/imageproxy.git synced 2024-12-30 22:34:18 -05:00

rename prometheus metrics and vars

Make names a little more consistent and align with naming docs at
https://prometheus.io/docs/practices/naming/
This commit is contained in:
Will Norris 2020-02-24 08:16:36 -08:00
parent 4e97a7ea8f
commit 7f91379373
3 changed files with 22 additions and 19 deletions

View file

@ -150,7 +150,7 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h = tphttp.TimeoutHandler(h, p.Timeout, "Gateway timeout waiting for remote resource.") h = tphttp.TimeoutHandler(h, p.Timeout, "Gateway timeout waiting for remote resource.")
} }
timer := prometheus.NewTimer(httpRequestsResponseTime) timer := prometheus.NewTimer(metricRequestDuration)
defer timer.ObserveDuration() defer timer.ObserveDuration()
h.ServeHTTP(w, r) h.ServeHTTP(w, r)
} }
@ -191,7 +191,7 @@ func (p *Proxy) serveImage(w http.ResponseWriter, r *http.Request) {
msg := fmt.Sprintf("error fetching remote image: %v", err) msg := fmt.Sprintf("error fetching remote image: %v", err)
p.log(msg) p.log(msg)
http.Error(w, msg, http.StatusInternalServerError) http.Error(w, msg, http.StatusInternalServerError)
remoteImageFetchErrors.Inc() metricRemoteErrors.Inc()
return return
} }
// close the original resp.Body, even if we wrap it in a NopCloser below // close the original resp.Body, even if we wrap it in a NopCloser below
@ -203,7 +203,7 @@ func (p *Proxy) serveImage(w http.ResponseWriter, r *http.Request) {
} }
if cached { if cached {
requestServedFromCacheCount.Inc() metricServedFromCache.Inc()
} }
copyHeader(w.Header(), resp.Header, "Cache-Control", "Last-Modified", "Expires", "Etag", "Link") copyHeader(w.Header(), resp.Header, "Cache-Control", "Last-Modified", "Expires", "Etag", "Link")

View file

@ -5,29 +5,32 @@ import (
) )
var ( var (
requestServedFromCacheCount = prometheus.NewCounter( metricServedFromCache = prometheus.NewCounter(
prometheus.CounterOpts{ prometheus.CounterOpts{
Name: "requests_served_from_cache", Namespace: "imageproxy",
Name: "requests_served_from_cache_total",
Help: "Number of requests served from cache.", Help: "Number of requests served from cache.",
}) })
imageTransformationSummary = prometheus.NewSummary(prometheus.SummaryOpts{ metricTransformationDuration = prometheus.NewSummary(prometheus.SummaryOpts{
Name: "image_transformation_seconds", Namespace: "imageproxy",
Name: "transformation_duration_seconds",
Help: "Time taken for image transformations in seconds.", Help: "Time taken for image transformations in seconds.",
}) })
remoteImageFetchErrors = prometheus.NewCounter(prometheus.CounterOpts{ metricRemoteErrors = prometheus.NewCounter(prometheus.CounterOpts{
Name: "remote_image_fetch_errors", Namespace: "imageproxy",
Help: "Total image fetch failures", Name: "remote_fetch_errors_total",
Help: "Total remote image fetch errors",
}) })
httpRequestsResponseTime = prometheus.NewSummary(prometheus.SummaryOpts{ metricRequestDuration = prometheus.NewSummary(prometheus.SummaryOpts{
Namespace: "http", Namespace: "http",
Name: "response_time_seconds", Name: "request_duration_seconds",
Help: "Request response times", Help: "Request response times",
}) })
) )
func init() { func init() {
prometheus.MustRegister(imageTransformationSummary) prometheus.MustRegister(metricTransformationDuration)
prometheus.MustRegister(requestServedFromCacheCount) prometheus.MustRegister(metricServedFromCache)
prometheus.MustRegister(remoteImageFetchErrors) prometheus.MustRegister(metricRemoteErrors)
prometheus.MustRegister(httpRequestsResponseTime) prometheus.MustRegister(metricRequestDuration)
} }

View file

@ -275,7 +275,7 @@ func exifOrientation(r io.Reader) (opt Options) {
// transformImage modifies the image m based on the transformations specified // transformImage modifies the image m based on the transformations specified
// in opt. // in opt.
func transformImage(m image.Image, opt Options) image.Image { func transformImage(m image.Image, opt Options) image.Image {
timer := prometheus.NewTimer(imageTransformationSummary) timer := prometheus.NewTimer(metricTransformationDuration)
defer timer.ObserveDuration() defer timer.ObserveDuration()
// Parse crop and resize parameters before applying any transforms. // Parse crop and resize parameters before applying any transforms.