From ef7115ca63138437da83c734008d63c6d54e5724 Mon Sep 17 00:00:00 2001 From: Andrew Kroh Date: Sat, 24 Feb 2024 08:13:39 -0500 Subject: [PATCH] Add Agent diagnostic hook to dump beat metrics (#38115) 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 --- libbeat/cmd/instance/beat.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libbeat/cmd/instance/beat.go b/libbeat/cmd/instance/beat.go index 4b7470b1dbd..f25a24d2d5a 100644 --- a/libbeat/cmd/instance/beat.go +++ b/libbeat/cmd/instance/beat.go @@ -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 }