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

HttpListenerPrefixes other than localhost #2840

Closed
GuglielmoFrigerio opened this issue Feb 1, 2022 · 4 comments · Fixed by #3521
Closed

HttpListenerPrefixes other than localhost #2840

GuglielmoFrigerio opened this issue Feb 1, 2022 · 4 comments · Fixed by #3521
Labels
pkg:OpenTelemetry.Exporter.Prometheus.AspNetCore Issues related to OpenTelemetry.Exporter.Prometheus.AspNetCore NuGet package question Further information is requested

Comments

@GuglielmoFrigerio
Copy link

Does anyone tried to configure the exporter to publish on every network interface the host provide?
I've tried the following prefixes

  • http://0.0.0.0:9184
  • http://+:9184
  • http://*:9184
  • http://{an-existing-network-interface-ip}:9184

Nothing seems to work.

I've tried under Windows 11 & DotNet 6.

I wanted to test a scenario where the Prometheus server is remote respect to the application.

@GuglielmoFrigerio GuglielmoFrigerio added the question Further information is requested label Feb 1, 2022
@Yun-Ting
Copy link
Contributor

Yun-Ting commented Feb 8, 2022

Hi @GuglielmoFrigerio,
Could you share the code on how you configure the Prometheus server please?
Thank you.

@sakowiczm
Copy link

sakowiczm commented Feb 18, 2022

Guys, I think I have exactly the same problem. I'm using examples\Console\TestPrometheusExporter.cs and if I modify HttpListenerPrefixes collection to use anything different than localhost - I'm not able to access /metrics endpoint. Examples:

This works fine:

  options.HttpListenerPrefixes = new string[] {
      "http://localhost:9184"
  };

and below ones does not:

  options.HttpListenerPrefixes = new string[] {
      "http://*:9184", "http://+:9185"
  };

  options.HttpListenerPrefixes = new string[] {
      "http://{host-ip}:9184"
  };

I'm trying to expose /metrics using host IP so it can be reached by Prometheus running in a docker container.
I've disabled the firewall for the test duration - just in case.
Any idea what I may be doing wrong here?

Thanks.

@GuglielmoFrigerio
Copy link
Author

Hi @Yun-Ting this is how I configure Prometheus in the Startup.cs:

        var prometheusConfigSection = Configuration.GetSection("Prometheus");
        var prefixes = prometheusConfigSection.GetSection("prefixes").Get<string[]>();
        _meterProvider = Sdk.CreateMeterProviderBuilder()
            .AddMeter("SessionControl")
            .AddPrometheusExporter(opt =>
            {
                opt.StartHttpListener = true;
                opt.HttpListenerPrefixes = prefixes;
            })
            .Build();

This is the app settings:

 "Prometheus": {
   "prefixes": [
     "http://localhost:9174/"
   ]
 }

@cijothomas cijothomas added the pkg:OpenTelemetry.Exporter.Prometheus.AspNetCore Issues related to OpenTelemetry.Exporter.Prometheus.AspNetCore NuGet package label Mar 8, 2022
@8
Copy link

8 commented Mar 19, 2022

Hi,

I stumbled over the same bug, which makes exposing the metrics interface on all interfaces impossible.

After taking a look at the source code, I came up with the following workaround until the bug is fixed, by setting the private backing field directly using reflection, thereby sidestepping the buggy validation:

...
.AddPrometheusExporter(options =>
    {
      options.StartHttpListener = true;

      options.GetType()
        ?.GetField("httpListenerPrefixes", BindingFlags.NonPublic | BindingFlags.Instance)
        ?.SetValue(options, new[] { "http://*:9464" });
    });

Take care,
Martin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:OpenTelemetry.Exporter.Prometheus.AspNetCore Issues related to OpenTelemetry.Exporter.Prometheus.AspNetCore NuGet package question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants