percona / mongodb_exporter

A Prometheus exporter for MongoDB including sharding, replication and storage engines
Apache License 2.0
1.2k stars 428 forks source link

Issue with MongoDB Exporter Connection to the MongoDB Instance #951

Open asemarian opened 2 weeks ago

asemarian commented 2 weeks ago

I'm using the Percona Operator for MongoDB to deploy a MongoDB cluster on Kubernetes. I'm trying to add a sidecar container running mongodb_exporter to collect metrics. Here is my current configuration for the sidecar:

sidecars:
  - args:
      - --mongodb.uri=mongodb://mongodb-cluster-a9901-mongodb-replicaset.mongodb-cluster.svc.cluster.local:27017
    env:
      - name: MONGODB_USER
        value: clusterAdmin
      - name: MONGODB_PASSWORD
        value: clusterAdminPassword
    image: percona/mongodb_exporter:0.42
    name: exporter
    ports:
      - containerPort: 9216
        name: metrics

Note that:

The problem is that the exporter cannot connect to the MongoDB instance. Here's the logs:

time="2024-10-31T13:58:07Z" level=error msg="Cannot connect to MongoDB: cannot connect to MongoDB: server selection error: server selection timeout, current topology: { Type: Single, Servers: [{ Addr: mongodb://mongodb-cluster-a9901-mongodb-replicaset.mongodb-cluster.svc.cluster.local:27017, Type: Unknown, Last error: dial tcp: lookup mongodb://mongodb-cluster-a9901-mongodb-replicaset.mongodb-cluster.svc.cluster.local on 10.43.0.10:53: no such host }, ] }"

I'd appreciate any insights you can offer into why the exporter is failing to connect.

Thank you.

rock1013 commented 1 week ago

We met the same issue. Our exporter is out of k8s. Now we rollback to 0.40.0. It works fine. I guess new version has detected the mongo replicaset cluster. Without the dns in k8s, exporter can find mongo's ip never.