Skip to content

Commit 05d2a33

Browse files
committed
feat(main): add 5xx counter metrics
Signed-off-by: Rick Rackow <[email protected]>
1 parent 8f17c80 commit 05d2a33

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+52520
-4
lines changed

README.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33
This example app serves as an example of how one can easily instrument HTTP handlers with [Prometheus][prometheus] metrics. It uses the Prometheus [go client][client-golang] to create a new Prometheus registry.
44

5-
Usage is simple, on any request to `/` the request will result in a `200` response code. This increments the counter for this response code. Similarly the `/err` endpoint will result in a `404` response code, therefore increments that respective counter. Duration metrics are also exposed for any request to `/`.
5+
Usage is simple, on any request to `/` the request will result in a `200`
6+
response code. This increments the counter for this response code. Similarly,
7+
the `/404` endpoint will result in a `404` response code, therefore
8+
increments that respective counter. Any request to `/500` will increment the
9+
respective counter for errors.
10+
11+
Duration metrics are also exposed for any request to `/`.
612

713
A Docker image is available at: `ghcr.io/rhobs/prometheus-example-app:0.3.0`
814

@@ -25,9 +31,9 @@ For this example application, [PodMonitor manifest](manifests/pod-monitor.yaml)
2531
The following metrics are exposed:
2632

2733
- `version` - of type _gauge_ - containing the app version - as a constant metric value `1` and label `version`, representing this app version
28-
- `http_requests_total` - of type _counter_ - representing the total numbere of incoming HTTP requests
34+
- `http_requests_total` - of type _counter_ - representing the total number of incoming HTTP requests
2935
- `http_request_duration_seconds` - of type _histogram_, representing duration of all HTTP requests
30-
- `http_request_duration_seconds_count`- total count of all incoming HTTP requeests
36+
- `http_request_duration_seconds_count`- total count of all incoming HTTP requests
3137
- `http_request_duration_seconds_sum` - total duration in seconds of all incoming HTTP requests
3238
- `http_request_duration_seconds_bucket` - a histogram representation of the duration of the incoming HTTP requests
3339

main.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ func main() {
5454
notfoundHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
5555
w.WriteHeader(http.StatusNotFound)
5656
})
57+
errHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
58+
w.WriteHeader(http.StatusInternalServerError)
59+
})
5760

5861
foundChain := promhttp.InstrumentHandlerDuration(
5962
httpRequestDuration.MustCurryWith(prometheus.Labels{"handler": "found"}),
@@ -62,8 +65,9 @@ func main() {
6265

6366
mux := http.NewServeMux()
6467
mux.Handle("/", foundChain)
65-
mux.Handle("/err", promhttp.InstrumentHandlerCounter(httpRequestsTotal, notfoundHandler))
68+
mux.Handle("/404", promhttp.InstrumentHandlerCounter(httpRequestsTotal, notfoundHandler))
6669
mux.Handle("/metrics", promhttp.HandlerFor(r, promhttp.HandlerOpts{}))
70+
mux.Handle("/500", promhttp.InstrumentHandlerCounter(httpRequestsTotal, errHandler))
6771

6872
var srv *http.Server
6973
if enableH2c {

manifests/all-in-one.yaml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
name: ns1
5+
---
6+
apiVersion: apps/v1
7+
kind: Deployment
8+
metadata:
9+
labels:
10+
app: prometheus-example-app
11+
name: prometheus-example-app
12+
namespace: ns1
13+
spec:
14+
replicas: 1
15+
selector:
16+
matchLabels:
17+
app: prometheus-example-app
18+
template:
19+
metadata:
20+
labels:
21+
app: prometheus-example-app
22+
spec:
23+
containers:
24+
- image: ghcr.io/rhobs/prometheus-example-app:0.4.0
25+
imagePullPolicy: IfNotPresent
26+
name: prometheus-example-app
27+
---
28+
apiVersion: v1
29+
kind: Service
30+
metadata:
31+
labels:
32+
app: prometheus-example-app
33+
name: prometheus-example-app
34+
namespace: ns1
35+
spec:
36+
ports:
37+
- port: 8080
38+
protocol: TCP
39+
targetPort: 8080
40+
name: web
41+
selector:
42+
app: prometheus-example-app
43+
type: ClusterIP
44+
---
45+
apiVersion: monitoring.coreos.com/v1
46+
kind: ServiceMonitor
47+
metadata:
48+
labels:
49+
k8s-app: prometheus-example-monitor
50+
name: prometheus-example-monitor
51+
namespace: ns1
52+
spec:
53+
endpoints:
54+
- interval: 30s
55+
port: web
56+
scheme: http
57+
selector:
58+
matchLabels:
59+
app: prometheus-example-app

vendor/golang.org/x/net/AUTHORS

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/net/CONTRIBUTORS

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/net/LICENSE

+27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/net/PATENTS

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/net/http/httpguts/guts.go

+50
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)