Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/tutorials/instrumenting_http_server_in_go.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ func main() {
}
```

The `prometheus.MustRegister` function registers the pingCounter with the default registry.
The `promauto.With(reg).NewCounter()` function creates the counter and registers it with the custom registry.
To expose the metrics, the Go Prometheus client library provides the promhttp package.
`promhttp.Handler()` provides an `http.Handler` which exposes the metrics registered in the default registry.
`promhttp.HandlerFor(reg, promhttp.HandlerOpts{})` provides an `http.Handler` which exposes the metrics registered in the given registry.

The sample code is now:

Expand All @@ -111,7 +111,7 @@ func newMetrics(reg prometheus.Registerer) *metrics {
pingCounter: promauto.With(reg).NewCounter(
prometheus.CounterOpts{
Name: "ping_request_count",
Help: "No of request handled by Ping handler",
Help: "No of requests handled by Ping handler",
}),
}
return m
Expand Down Expand Up @@ -147,7 +147,7 @@ Now hit the localhost:8090/ping endpoint a couple of times and then send a reque

Here, the `ping_request_count` shows that the `/ping` endpoint was called 3 times.

The default registry comes with a collector for Go runtime metrics, and that is why we see other metrics like `go_threads`, `go_goroutines`, etc.
The code above uses a custom registry (`prometheus.NewRegistry()`), which does not include Go runtime metrics by default. To also collect Go runtime metrics, register `prometheus.NewGoCollector()` with the registry.

We have built our first metric exporter. Let’s update our Prometheus config to scrape the metrics from our server.

Expand Down
Loading