mirror of
https://github.com/datarhei/core.git
synced 2025-10-16 13:00:37 +08:00
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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user