Skip to content

Commit

Permalink
Feature: Exposing Prometheus metrics to user-defined interface (#6528)
Browse files Browse the repository at this point in the history
Co-authored-by: Ben Adams <thundercat@illyriad.co.uk>
  • Loading branch information
tgerring and benaadams authored Jan 13, 2024
1 parent a3a8cc2 commit 1709d8c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Nethermind/Nethermind.Monitoring/Config/IMetricsConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion src/Nethermind/Nethermind.Monitoring/MonitoringService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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))
Expand Down Expand Up @@ -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}");
Expand Down

0 comments on commit 1709d8c

Please sign in to comment.