Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Exposing Prometheus metrics to user-defined interface #6528

Merged
merged 3 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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