Skip to content

Commit

Permalink
Start pprof endpoint (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 authored Jul 31, 2024
1 parent 3823ff8 commit 07f24fe
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,19 @@ There is also a `cli` provided in the container which can be used to make calls
docker run -it --rm --entrypoint /cli ghcr.io/metal-stack/go-ipam
```

## Metrics

```bash
http://localhost:2112/metrics
```

## pprof

```bash
go tool pprof -http :8080 localhost:2113/debug/pprof/heap
go tool pprof -http :8080 localhost:2113/debug/pprof/goroutine
```

## Docker Compose example

Ensure you have docker with compose support installed. Then execute the following command:
Expand Down
16 changes: 16 additions & 0 deletions cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log/slog"
"net/http"
_ "net/http/pprof" // nolint:gosec
"time"

"connectrpc.com/connect"
Expand Down Expand Up @@ -73,6 +74,21 @@ func (s *server) Run() error {
return
}
}()
go func() {
s.log.Info("starting pprof endpoint of :2113")
// inspect via
// go tool pprof -http :8080 localhost:2113/debug/pprof/heap
// go tool pprof -http :8080 localhost:2113/debug/pprof/goroutine
server := http.Server{
Addr: ":2113",
ReadHeaderTimeout: 1 * time.Minute,
}
err := server.ListenAndServe()
if err != nil {
s.log.Error("failed to start pprof endpoint", "error", err)
return
}
}()

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

0 comments on commit 07f24fe

Please sign in to comment.