diff --git a/src/Nethermind/Nethermind.Monitoring/Config/IMetricsConfig.cs b/src/Nethermind/Nethermind.Monitoring/Config/IMetricsConfig.cs index 27510f0ebc8..e568530f7fd 100644 --- a/src/Nethermind/Nethermind.Monitoring/Config/IMetricsConfig.cs +++ b/src/Nethermind/Nethermind.Monitoring/Config/IMetricsConfig.cs @@ -8,6 +8,9 @@ namespace Nethermind.Monitoring.Config; [ConfigCategory(Description = "Configuration of the metrics provided by a Nethermind node for both, the Prometheus and the dotnet-counters.")] public interface IMetricsConfig : IConfig { + [ConfigItem(Description = "The ip at which to expose Prometheus metrics.", DefaultValue = "127.0.0.1")] + string ExposeHost { get; } + [ConfigItem(Description = "The port to expose Prometheus metrics at.", DefaultValue = "null")] int? ExposePort { get; } diff --git a/src/Nethermind/Nethermind.Monitoring/Config/MetricsConfig.cs b/src/Nethermind/Nethermind.Monitoring/Config/MetricsConfig.cs index ed59ad88e58..50977531c5e 100644 --- a/src/Nethermind/Nethermind.Monitoring/Config/MetricsConfig.cs +++ b/src/Nethermind/Nethermind.Monitoring/Config/MetricsConfig.cs @@ -5,6 +5,7 @@ namespace Nethermind.Monitoring.Config { public class MetricsConfig : IMetricsConfig { + public string ExposeHost { get; set; } = "127.0.0.1"; public int? ExposePort { get; set; } = null; public bool Enabled { get; set; } = false; public bool CountersEnabled { get; set; } = false; diff --git a/src/Nethermind/Nethermind.Monitoring/MonitoringService.cs b/src/Nethermind/Nethermind.Monitoring/MonitoringService.cs index 08203506e87..e40540dcfbe 100644 --- a/src/Nethermind/Nethermind.Monitoring/MonitoringService.cs +++ b/src/Nethermind/Nethermind.Monitoring/MonitoringService.cs @@ -19,6 +19,7 @@ public class MonitoringService : IMonitoringService private readonly ILogger _logger; private readonly Options _options; + private readonly string _exposeHost; private readonly int? _exposePort; private readonly string _nodeName; private readonly bool _pushEnabled; @@ -29,12 +30,14 @@ public MonitoringService(IMetricsController metricsController, IMetricsConfig me { _metricsController = metricsController ?? throw new ArgumentNullException(nameof(metricsController)); + string exposeHost = metricsConfig.ExposeHost; int? exposePort = metricsConfig.ExposePort; string nodeName = metricsConfig.NodeName; string pushGatewayUrl = metricsConfig.PushGatewayUrl; bool pushEnabled = metricsConfig.Enabled; int intervalSeconds = metricsConfig.IntervalSeconds; + _exposeHost = exposeHost; _exposePort = exposePort; _nodeName = string.IsNullOrWhiteSpace(nodeName) ? throw new ArgumentNullException(nameof(nodeName)) @@ -81,7 +84,7 @@ public async Task StartAsync() } if (_exposePort is not null) { - new NethermindKestrelMetricServer(_exposePort.Value).Start(); + new NethermindKestrelMetricServer(_exposeHost, _exposePort.Value).Start(); } await Task.Factory.StartNew(() => _metricsController.StartUpdating(), TaskCreationOptions.LongRunning); if (_logger.IsInfo) _logger.Info($"Started monitoring for the group: {_options.Group}, instance: {_options.Instance}");