<p>I'm setting up a Prometheus exporter for my ASP.NET Core 3.1 app.</p>
<p>I've imported</p>
<p><code>&lt;PackageReference Include=&quot;prometheus-net.AspNetCore&quot; Version=&quot;4.1.1&quot; /&gt;</code></p>
<p>And this is what I have configured:</p>
<pre><code>public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    ...

    app.UseRouting();
    app.UseHttpMetrics();

    app.UseEndpoints(endpoints =&gt;
    {
        endpoints.MapControllers();
        endpoints.MapMetrics();
    });
}
</code></pre>
<p>This will expose the metrics endpoint on the same port as the rest of the ASP.NET Core application, for example: <code>my.api.com:80/metrics</code>.</p>
<p>What do I need to do to expose the <code>/metrics</code> endpoint on another port? I would like to have my API running on port 80, and the <code>/metrics</code> endpoint on port 9102.</p>
<p>Can't really find any docs about that.</p>
<p><strong>Edit</strong></p>
<p>I'm deploying this into Kubernetes</p>

<p>I ended up doing like this:</p>
<pre><code>public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    ...
    app.UseMetricServer(9102);

    app.UseRouting();
    app.UseHttpMetrics();

    ...

}
</code></pre>
<p>And then for my Kubernetes <code>Deployment</code> I had to add both port 80 and 9102 to <code>containerPort</code>s under <code>ports</code>.</p>
<p>Additionally I had to set the <code>ASPNETCORE_URLS</code> environment variable to <code>http://+:80;http://+:9102</code></p>
<p>That way, <code>/metrics</code> is only exposed on port 9102. (However the rest of my API is exposed on both port 80 and 9102).</p>
