<p>I have Keycloak 14 running and would like to scrape metrics data from it.</p>
<p>So I configured Prometheus to scrape <code>http://KEYCLOAK_HOST:9990/metrics</code>. Unfortunately this gives me a &quot;Connection refused&quot;.</p>
<p>When I try to connect from another host manually I get the same:</p>
<pre><code>user@host:/$ curl -vvv 10.244.3.154:9990/metrics
* Expire in 0 ms for 6 (transfer 0x5566ecabbfb0)
*   Trying 10.244.3.154...
* TCP_NODELAY set
* Expire in 200 ms for 4 (transfer 0x5566ecabbfb0)
* connect to 10.244.3.154 port 9990 failed: Connection refused
* Failed to connect to 10.244.3.154 port 9990: Connection refused
* Closing connection 0
curl: (7) Failed to connect to 10.244.3.154 port 9990: Connection refused
user@host:/$
</code></pre>
<p>In fact I get this error on all paths on the management port. Even on those, that do not exist:</p>
<pre><code>user@host:/$ curl -vvv 10.244.3.154:9990/some_endpoint
* Expire in 0 ms for 6 (transfer 0x55eea4059fb0)
*   Trying 10.244.3.154...
* TCP_NODELAY set
* Expire in 200 ms for 4 (transfer 0x55eea4059fb0)
* connect to 10.244.3.154 port 9990 failed: Connection refused
* Failed to connect to 10.244.3.154 port 9990: Connection refused
* Closing connection 0
curl: (7) Failed to connect to 10.244.3.154 port 9990: Connection refused
user@host:/$
</code></pre>
<p>From within the Keycloak host it works fine:</p>
<pre><code>bash-4.4$ curl -vvv localhost:9990/metrics
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 9990 (#0)
&gt; GET /metrics HTTP/1.1
&gt; Host: localhost:9990
&gt; User-Agent: curl/7.61.1
&gt; Accept: */*
&gt;
&lt; HTTP/1.1 200 OK
&lt; Connection: keep-alive
...
bash-4.4$
</code></pre>
<p>It only works on <code>localhost</code> though:</p>
<pre><code>bash-4.4$ hostname -I
10.244.3.154
bash-4.4$ curl -vvv 10.244.3.154:9990/metrics
*   Trying 10.244.3.154...
* TCP_NODELAY set
* connect to 10.244.3.154 port 9990 failed: Connection refused
* Failed to connect to 10.244.3.154 port 9990: Connection refused
* Closing connection 0
curl: (7) Failed to connect to 10.244.3.154 port 9990: Connection refused
bash-4.4$
</code></pre>
<p>So I assume Keycloak is not providing the management endpoints &quot;to the outside world&quot;. But how can I enable it?</p>
<p>I'm using the <code>codecentric</code> Helm chart for deployment (<a href="https://github.com/codecentric/helm-charts/tree/master/charts/keycloak" rel="nofollow noreferrer">https://github.com/codecentric/helm-charts/tree/master/charts/keycloak</a>). I'm running Keycloak 14.0.0 right now, but had the same issue with 15.x (cannot update right now due to a bug).</p>
<p>Thanks in advance!</p>

Max N.
<p>Found in the documentation of the Helm chart, that I had to enable it by setting the env variable <code>KEYCLOAK_STATISTICS</code> to <code>all</code>.</p>
<p><a href="https://github.com/codecentric/helm-charts/tree/master/charts/keycloak#prometheus-metrics-support" rel="nofollow noreferrer">https://github.com/codecentric/helm-charts/tree/master/charts/keycloak#prometheus-metrics-support</a></p>
