Skip to content

Commit

Permalink
Add Agent diagnostic hook to dump beat metrics (#38115)
Browse files Browse the repository at this point in the history
Register an Agent diagnostic hook that will dump all metrics registered into
the default monitoring namespace as well as expvar. The hook is registered
within libbeat so this change will affect all Beats operating under Agent.

The file will be named beat_metrics.json and will contain a single pretty JSON
object.

Closes #37929
  • Loading branch information
andrewkroh authored Feb 24, 2024
1 parent 353dab3 commit ef7115c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions libbeat/cmd/instance/beat.go
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,16 @@ func (b *Beat) configure(settings Settings) error {

b.Manager.RegisterDiagnosticHook("global processors", "a list of currently configured global beat processors",
"global_processors.txt", "text/plain", b.agentDiagnosticHook)
b.Manager.RegisterDiagnosticHook("beat_metrics", "Metrics from the default monitoring namespace and expvar.",
"beat_metrics.json", "application/json", func() []byte {
m := monitoring.CollectStructSnapshot(monitoring.Default, monitoring.Full, true)
data, err := json.MarshalIndent(m, "", " ")
if err != nil {
logp.L().Warnw("Failed to collect beat metric snapshot for Agent diagnostics.", "error", err)
return []byte(err.Error())
}
return data
})

return err
}
Expand Down

0 comments on commit ef7115c

Please sign in to comment.