Add gops agent

The gops agent can be enabled by providing an address to
CORE_DEBUG_AGENT_ADDRESS where it will listen to requests
from the gops utility.
This commit is contained in:
Ingo Oppermann
2023-07-03 21:27:44 +02:00
parent 9c88e88619
commit c5d52dbeb3
18 changed files with 664 additions and 123 deletions

View File

@@ -50,6 +50,7 @@ import (
"github.com/datarhei/core/v16/srt"
srturl "github.com/datarhei/core/v16/srt/url"
"github.com/datarhei/core/v16/update"
"github.com/google/gops/agent"
"github.com/lestrrat-go/strftime"
"go.uber.org/automaxprocs/maxprocs"
@@ -323,6 +324,15 @@ func (a *api) start(ctx context.Context) error {
a.undoMaxprocs = undoMaxprocs
}
if len(cfg.Debug.AgentAddress) != 0 {
if err := agent.Listen(agent.Options{
Addr: cfg.Debug.AgentAddress,
ReuseSocketAddrAndPort: true,
}); err != nil {
a.log.logger.main.Error().WithError(err).Log("")
}
}
resources, err := resources.New(resources.Config{
MaxCPU: cfg.Resources.MaxCPUUsage,
MaxMemory: cfg.Resources.MaxMemoryUsage,
@@ -1836,6 +1846,9 @@ func (a *api) stop() {
a.gcTickerStop = nil
}
// Stop gops agent
agent.Close()
// Wait for all server goroutines to exit
logger.Info().Log("Waiting for all servers to stop ...")
a.wgStop.Wait()