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

**URL:** https://forums.percona.com/t/collecting-metrics-using-mongodb-exporter-as-a-sidecar-in-kube-prometheus-grafana-setup-gives-only-rs0-metrics-not-the-cfg-and-mongos-metrics/35555
**Category:** Percona Operator for MongoDB
**Created:** [December 9, 2024, 1:25pm UTC](https://forums.percona.com/t/collecting-metrics-using-mongodb-exporter-as-a-sidecar-in-kube-prometheus-grafana-setup-gives-only-rs0-metrics-not-the-cfg-and-mongos-metrics/35555 "2024-12-09T13:25:02Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Raji](https://avatars.discourse-cdn.com/v4/letter/r/eb8c5e/32.png) [@Raji](https://forums.percona.com/u/Raji)
#### Post date: [December 9, 2024, 1:25pm UTC](https://forums.percona.com/t/collecting-metrics-using-mongodb-exporter-as-a-sidecar-in-kube-prometheus-grafana-setup-gives-only-rs0-metrics-not-the-cfg-and-mongos-metrics/35555/1 "2024-12-09T13:25:02Z")

</div>

## 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:

> [@How to collect metrics and ship to existing prometheus grafana setup](https://forums.percona.com/t/how-to-collect-metrics-and-ship-to-existing-prometheus-grafana-setup/21616):
>
> Hi friends, we are switching our mongodb deployment from using bitnami [charts/bitnami/mongodb at main · bitnami/charts · GitHub](https://github.com/bitnami/charts/tree/main/bitnami/mongodb) to use the percona operator. In our bitnami solution we have setup the metric server via ([charts/values.yaml at main · bitnami/charts · GitHub](https://github.com/bitnami/charts/blob/main/bitnami/mongodb/values.yaml#L1901)) We have an existing prometheus/grafana setup via kube-prometheus-stack [helm-charts/charts/kube-prometheus-stack at main · prometheus-community/helm-charts · GitHub](https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack) We are wondering if its possible to install a metric server …

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.

> [@How to collect metrics and ship to existing prometheus grafana setup](https://forums.percona.com/t/how-to-collect-metrics-and-ship-to-existing-prometheus-grafana-setup/21616):
>
> Hi friends, we are switching our mongodb deployment from using bitnami [charts/bitnami/mongodb at main · bitnami/charts · GitHub](https://github.com/bitnami/charts/tree/main/bitnami/mongodb) to use the percona operator. In our bitnami solution we have setup the metric server via ([charts/values.yaml at main · bitnami/charts · GitHub](https://github.com/bitnami/charts/blob/main/bitnami/mongodb/values.yaml#L1901)) We have an existing prometheus/grafana setup via kube-prometheus-stack [helm-charts/charts/kube-prometheus-stack at main · prometheus-community/helm-charts · GitHub](https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack) We are wondering if its possible to install a metric server …

## Version:

`mongodb_exporter:0.36`

## Logs:

_Get “[http://x.x.x.x:9216/metrics](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]

---

<div class="post-metadata">

### Author: ![Sergey\_Pronin](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/sergey_pronin/32/14887_2.png) [@Sergey\_Pronin](https://forums.percona.com/u/Sergey_Pronin)
#### Post date: [December 23, 2024, 10:50am UTC](https://forums.percona.com/t/collecting-metrics-using-mongodb-exporter-as-a-sidecar-in-kube-prometheus-grafana-setup-gives-only-rs0-metrics-not-the-cfg-and-mongos-metrics/35555/2 "2024-12-23T10:50:44Z")

</div>

@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.
