diff --git a/libbeat/cmd/instance/beat.go b/libbeat/cmd/instance/beat.go index 48fd103e0ef..70bae6dd7c5 100644 --- a/libbeat/cmd/instance/beat.go +++ b/libbeat/cmd/instance/beat.go @@ -309,6 +309,10 @@ func (b *Beat) createBeater(bt beat.Creator) (beat.Beater, error) { return nil, err } + // Report central management state + mgmt := monitoring.GetNamespace("state").GetRegistry().NewRegistry("management") + monitoring.NewBool(mgmt, "enabled").Set(b.ConfigManager.Enabled()) + debugf("Initializing output plugins") outputEnabled := b.Config.Output.IsSet() && b.Config.Output.Config().Enabled() if !outputEnabled { diff --git a/libbeat/monitoring/metrics.go b/libbeat/monitoring/metrics.go index ab0d9d56ec2..e398bc773d7 100644 --- a/libbeat/monitoring/metrics.go +++ b/libbeat/monitoring/metrics.go @@ -124,6 +124,30 @@ func (v *Float) Add(delta float64) { } } +// Bool is a Bool variable satisfying the Var interface. +type Bool struct{ f atomic.Bool } + +// NewBool creates and registers a new bool variable. +// +// Note: If the registry is configured to publish variables to expvar, the +// variable will be available via expvars package as well, but can not be removed +// anymore. +func NewBool(r *Registry, name string, opts ...Option) *Bool { + if r == nil { + r = Default + } + + v := &Bool{} + addVar(r, name, opts, v, makeExpvar(func() string { + return strconv.FormatBool(v.Get()) + })) + return v +} + +func (v *Bool) Get() bool { return v.f.Load() } +func (v *Bool) Set(value bool) { v.f.Store(value) } +func (v *Bool) Visit(_ Mode, vs Visitor) { vs.OnBool(v.Get()) } + // String is a string variable satisfying the Var interface. type String struct { mu sync.RWMutex