-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from keratin/metrics
add: `GET /metrics` (authenticated)
- Loading branch information
Showing
7 changed files
with
113 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package route | ||
|
||
import ( | ||
"net/http" | ||
"strconv" | ||
|
||
"github.com/felixge/httpsnoop" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
var ( | ||
httpRequests = prometheus.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Name: "http_requests_total", | ||
Help: "How many HTTP requests processed, partitioned by name and status code", | ||
}, | ||
[]string{"name", "code"}, | ||
) | ||
httpTimings = prometheus.NewHistogramVec( | ||
prometheus.HistogramOpts{ | ||
Name: "http_request_times", | ||
Help: "The duration of HTTP requests, partitioned by name", | ||
Buckets: prometheus.ExponentialBuckets(0.001, 10, 5), | ||
}, | ||
[]string{"name"}, | ||
) | ||
) | ||
|
||
func init() { | ||
prometheus.MustRegister(httpRequests) | ||
prometheus.MustRegister(httpTimings) | ||
} | ||
|
||
func instrumentRoute(name string, next http.Handler) http.Handler { | ||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
metrics := httpsnoop.CaptureMetrics(next, w, r) | ||
httpRequests.WithLabelValues(name, strconv.Itoa(metrics.Code)).Inc() | ||
httpTimings.WithLabelValues(name).Observe(float64(metrics.Duration.Seconds())) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters