Collecting metrics using "mongodb exporter" as a sidecar in kube prometheus grafana setup gives only rs0 metrics, not the cfg and mongos metrics

Description:

I am using percona mongodb operator for my mongodb instances. Needed to collect metrics in kube prometheus stack setup and create dashboards in Grafana.

Referred the below:

And I have included mongodb-exporter as a sidecar to rs0 and able to successfully receive the rs0 metrics in Prometheus.

However, in Prometheus->targets->svcmonitor endpoints, 3 endpoints are listed (rs0,cfg, mongos), but only 1/3 is up (rs0-up, cfg,mongos-down).
And the error is *Get "http://x.x.x.x:9216/metrics":read tcp ip -> ip: read: connection reset by peer* for cfg and mongos endpoints.
Believe, this is because mongodb-exporter is added to rs0, MONGODB_URI connects to the mongodb-instance in rs0 pod and unable to connect to others.

Tried updating the selector in service monitor to only rs0 instead of psmdb-db, thinking that the target would be 1/1 , but I was unable to get the endpoint itself.

As I understand, the rs0 contains the whole data, mongos is for routing and cfg has the metadata, rs0 metrics is fine, but checking if there is a way possible to fix 2/3 down.
Could you please confirm if this is expected out of this approach or any other workarounds.

Steps to Reproduce:

Referred to the below and added mongodb-exporter as a sidecar to rs0 and enabled service, service monitor.

Version:

mongodb_exporter:0.36

Logs:

Get “http://x.x.x.x:9216/metrics”:read tcp ip → ip: read: connection reset by peer
for cfg and mongos endpoints.

Expected Result:

Expecting to see the cfg and mongos metrics as well.

Actual Result:

rs0 metrics alone available.

Additional Information:

[Include any additional information that could be helpful to diagnose the issue, such as browser or device information]

@Raji do you have sidecars configured in all sections?

To make this work you need to have sidecars configured 3 times:

  1. spec.replsets..sidecars
  2. spec.sharding.configsvrReplSet.sidecars
  3. spec.sharding.mongos.sidecars

That way you will have mongod_exporter running alongside for all mongodb components.