<p>I have added <code>pgbouncer-exporter</code> container to my deployment. It is emitting the metrics on port <code>9100</code>.
I want to add a scraper for these metrics so that it becomes visible in Prometheus.
How can I do it by using Kubernetes <code>ServiceMonitor</code>?</p>

Dev
<p>I'm unfamiliar with <a href="https://github.com/prometheus-community/pgbouncer_exporter" rel="nofollow noreferrer"><code>pgbouncer-exporter</code></a> but the principles are consistent irrespective of technology.</p>
<p>You'll need to:</p>
<ol>
<li>Ensure the <code>pgbouncer_exporter</code>'s port (default <code>9127</code>?) is published so that the <code>/metrics</code> are accessible beyond the Pod.</li>
<li>Test <code>GET</code>'ting the endpoint (e.g. <code>kubectl port-forward</code> to the <code>Deployment</code>) to ensure that <code>/metrics</code> is accessible.</li>
<li>Determine whether to use a <a href="https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/design.md#servicemonitor" rel="nofollow noreferrer"><code>ServiceMonitor</code></a> or <a href="https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/design.md#podmonitor" rel="nofollow noreferrer"><code>PodMonitor</code></a>. If you have a Service exposing <code>pgbouncer_exporter</code>, then use <code>ServiceMonitor</code>. Otherwise, use <code>PodMonitor</code></li>
<li>Configure <code>*Monitor</code>'s <code>selector</code> and <code>port</code></li>
<li>Apply the config to your cluster in the <code>Namespace</code> of your <code>Deployment</code>.</li>
</ol>
