Skip to content

Commit 07f24fe

Browse files
authored
Start pprof endpoint (#158)
1 parent 3823ff8 commit 07f24fe

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,19 @@ There is also a `cli` provided in the container which can be used to make calls
145145
docker run -it --rm --entrypoint /cli ghcr.io/metal-stack/go-ipam
146146
```
147147

148+
## Metrics
149+
150+
```bash
151+
http://localhost:2112/metrics
152+
```
153+
154+
## pprof
155+
156+
```bash
157+
go tool pprof -http :8080 localhost:2113/debug/pprof/heap
158+
go tool pprof -http :8080 localhost:2113/debug/pprof/goroutine
159+
```
160+
148161
## Docker Compose example
149162

150163
Ensure you have docker with compose support installed. Then execute the following command:

cmd/server/server.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"log/slog"
66
"net/http"
7+
_ "net/http/pprof" // nolint:gosec
78
"time"
89

910
"connectrpc.com/connect"
@@ -73,6 +74,21 @@ func (s *server) Run() error {
7374
return
7475
}
7576
}()
77+
go func() {
78+
s.log.Info("starting pprof endpoint of :2113")
79+
// inspect via
80+
// go tool pprof -http :8080 localhost:2113/debug/pprof/heap
81+
// go tool pprof -http :8080 localhost:2113/debug/pprof/goroutine
82+
server := http.Server{
83+
Addr: ":2113",
84+
ReadHeaderTimeout: 1 * time.Minute,
85+
}
86+
err := server.ListenAndServe()
87+
if err != nil {
88+
s.log.Error("failed to start pprof endpoint", "error", err)
89+
return
90+
}
91+
}()
7692

7793
otelInterceptor, err := otelconnect.NewInterceptor(otelconnect.WithMeterProvider(provider))
7894
if err != nil {

0 commit comments

Comments
 (0)