Skip to content

Commit 80443b0

Browse files
author
Mario Macias
authored
Enable remote profiling (#38)
1 parent d0c59d8 commit 80443b0

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

cmd/netobserv-ebpf-agent.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package main
55
import (
66
"context"
77
"fmt"
8+
"net/http"
89
"os"
910
"os/signal"
1011
"syscall"
@@ -13,6 +14,8 @@ import (
1314
"github.com/sirupsen/logrus"
1415

1516
"github.com/netobserv/netobserv-ebpf-agent/pkg/agent"
17+
18+
_ "net/http/pprof"
1619
)
1720

1821
func main() {
@@ -23,6 +26,14 @@ func main() {
2326
}
2427
setLoggerVerbosity(&config)
2528

29+
if config.ProfilePort != 0 {
30+
go func() {
31+
logrus.WithField("port", config.ProfilePort).Info("starting PProf HTTP listener")
32+
logrus.WithError(http.ListenAndServe(fmt.Sprintf(":%d", config.ProfilePort), nil)).
33+
Error("PProf HTTP listener stopped working")
34+
}()
35+
}
36+
2637
logrus.WithField("configuration", fmt.Sprintf("%#v", config)).Debugf("configuration loaded")
2738

2839
flowsAgent, err := agent.FlowsAgent(&config)

docs/config.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,6 @@ The following environment variables are available to configure the NetObserv eBF
4545
* `KAFKA_ASYNC` (default: `true`). If `true`, the message writing process will never block. It also
4646
means that errors are ignored since the caller will not receive the returned value.
4747
* `KAFKA_COMPRESSION` (default: `none`). Compression codec to be used to compress messages. Accepted
48-
values: `none`, `gzip`, `snappy`, `lz4`, `zstd`.
48+
values: `none`, `gzip`, `snappy`, `lz4`, `zstd`.
49+
* `PROFILE_PORT` (default: unset). Sets the listening port for [Go's Pprof tool](https://pkg.go.dev/net/http/pprof).
50+
If it is not set, profile is disabled.

pkg/agent/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,6 @@ type Config struct {
6767
// KafkaCompression sets the compression codec to be used to compress messages. The accepted
6868
// values are: none (default), gzip, snappy, lz4, zstd.
6969
KafkaCompression string `env:"KAFKA_COMPRESSION" envDefault:"none"`
70+
// ProfilePort sets the listening port for Go's Pprof tool. If it is not set, profile is disabled
71+
ProfilePort int `env:"PROFILE_PORT"`
7072
}

0 commit comments

Comments
 (0)