From b00c5c0587e038fd3de5a0d4728779b45d9a9942 Mon Sep 17 00:00:00 2001 From: "chaitanya.singla" Date: Mon, 12 Aug 2024 16:57:51 +0530 Subject: [PATCH] Add support for Gauge function and max devices connected to Talaria --- main.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/main.go b/main.go index ccb8f5e3..b01f0c25 100644 --- a/main.go +++ b/main.go @@ -46,6 +46,7 @@ import ( const ( applicationName = "talaria" tracingConfigKey = "tracing" + maxDeviceCount = "max_device_count" ) var ( @@ -86,6 +87,13 @@ func newDeviceManager(logger *zap.Logger, r xmetrics.Registry, v *viper.Viper) ( return device.NewManager(deviceOptions), g, watcher, nil } +func newStaticMetrics(m device.Manager, r xmetrics.Registry) (err error) { + r.NewGaugeFunc(maxDeviceCount, func() float64 { + return float64(m.MaxDevices()) + }) + return +} + func loadTracing(v *viper.Viper, appName string) (candlelight.Tracing, error) { var traceConfig candlelight.Config err := v.UnmarshalKey(tracingConfigKey, &traceConfig) @@ -145,6 +153,13 @@ func talaria(arguments []string) int { logger.Error("unable to create device manager", zap.Error(err)) return 2 } + + err = newStaticMetrics(manager, metricsRegistry) + if err != nil { + logger.Error("unable to register static metrics", zap.Error(err)) + return 6 + } + var log = &adapter.Logger{ Logger: logger, }