예제 #1
0
        public async Task Execute(CancellationToken cancellationToken)
        {
            IMetricsConfig metricsConfig = _api.Config <IMetricsConfig>();
            ILogger        logger        = _api.LogManager.GetClassLogger();

            // hacky
            if (!string.IsNullOrEmpty(metricsConfig.NodeName))
            {
                _api.LogManager.SetGlobalVariable("nodeName", metricsConfig.NodeName);
            }

            if (metricsConfig.Enabled)
            {
                Metrics.Version = VersionToMetrics.ConvertToNumber(ClientVersion.Version);
                MetricsUpdater metricsUpdater = new MetricsUpdater(metricsConfig);
                _api.MonitoringService = new MonitoringService(metricsUpdater, metricsConfig, _api.LogManager);
                var metrics = new TypeDiscovery().FindNethermindTypes(nameof(Metrics));
                foreach (var metric in metrics)
                {
                    _api.MonitoringService.RegisterMetrics(metric);
                }

                await _api.MonitoringService.StartAsync().ContinueWith(x =>
                {
                    if (x.IsFaulted && logger.IsError)
                    {
                        logger.Error("Error during starting a monitoring.", x.Exception);
                    }
                }, cancellationToken);

                _api.DisposeStack.Push(Disposable.Create(() => _api.MonitoringService.StopAsync())); // do not await
            }
            else
            {
                if (logger.IsInfo)
                {
                    logger.Info("Grafana / Prometheus metrics are disabled in configuration");
                }
            }
        }
예제 #2
0
 public void Converts_all_formats(string versionString, int versionNumber)
 {
     VersionToMetrics.ConvertToNumber(versionString).Should().Be(versionNumber);
 }