https://github.com/postfinance/profiler
pprof endpoint for Go applications that can be activated by a signal
https://github.com/postfinance/profiler
Last synced: 9 months ago
JSON representation
pprof endpoint for Go applications that can be activated by a signal
- Host: GitHub
- URL: https://github.com/postfinance/profiler
- Owner: postfinance
- License: mit
- Created: 2020-02-17T09:33:59.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2025-01-31T12:56:42.000Z (12 months ago)
- Last Synced: 2025-03-28T04:28:06.252Z (10 months ago)
- Language: Go
- Size: 50.8 KB
- Stars: 2
- Watchers: 7
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
[](https://goreportcard.com/report/github.com/postfinance/profiler)
[](https://godoc.org/github.com/postfinance/profiler)
[](https://github.com/postfinance/profiler/actions/workflows/build.yml)
[](https://coveralls.io/github/postfinance/profiler?branch=master)
# profiler
## Usage
Add the following line to your Go code:
```go
// create and start the profiler handler
profiler.New().Start()
// ... or with custom values
profiler.New(
profiler.WithSignal(syscall.SIGUSR1),
profiler.WithAddress(":8080"),
profiler.WithTimeout(15 * time.Minute),
)
```
## Defaults
| Parameter | Default |
|-----------|-----------|
| Signal | *SIGUSR1* |
| Listen | *:6666* |
| Timeout | *30m* |
### Start the pprof endpoint
```shell
pkill -SIGUSR1
```
> After *timeout* the endpoint will shutdown.
### Collect pprof data
```shell
go tool pprof -http $(hostname):8080 http://localhost:6666/debug/pprof/profile
```
... or ...
```shell
go tool pprof -http localhost:7007 http://localhost:8080/debug/pprof/profile
```
## Kubernetes
### Start the pprof endpoint
```shell
kubectl get pods
NAME READY STATUS RESTARTS AGE
...
kubectl exec -ti -- sh
/ # pkill -SIGUSR1
/ #
```
> After *timeout* the endpoint will shutdown.
### Check log
```shell
kubectl logs -f | grep 'start debug endpoint'
```
### Port-forward
```shell
kubectl port-forward 8080:6666
Forwarding from 127.0.0.1:8080 -> 6666
Forwarding from [::1]:8080 -> 6666
Handling connection for 8080
```
### Collect pprof data
```shell
go tool pprof -http $(hostname):8888 http://localhost:8080/debug/pprof/profile
```
... or ...
```shell
go tool pprof -http localhost:7007 http://localhost:8080/debug/pprof/profile
```
### Use [statsviz](https://github.com/arl/statsviz)
Open: [http://localhost:8080/debug/statsviz](http://localhost:8080/debug/statsviz)
### Use [expvarmon](https://github.com/divan/expvarmon)
```shell
expvarmon -ports=http://localhost:8080
```