MongoDB configuration in grafana

Hello!

This is a little bit of a tricky question because there are two things you might want to do when integrating MongoDB with Grafana, the Percona dashboards are made for grabbing information about running MongoDB rather than data that is stored in MongoDB (so if you have a users collection in MongoDB, you won’t be able to use their scripts and exporter to see for example the number of users who has logged in during the last 24 hours or whatnot but rather to see for example how many connections you have to the database).

If you want to use Grafana to visualize information about your MongoDB instances, the following steps are generally speaking what you’d like to do (I haven’t tested the exact steps described here, so I’m outlining it very vaguely).

  1. Use something like Percona’s mongodb_exporter (follow the instructions in that repository to set it up next to your MongoDB instances) to fetch the metrics from MongoDB and publishing them in a way that is accessible by Prometheus.
  2. Set up Prometheus and it’s scrape_config to fetch the metrics from your exporter.
  3. Add Prometheus as a data source in Grafana, see the Using Prometheus in Grafana documentation.

On the other hand, if you have data in MongoDB which you’d like to expose to Grafana the answer changes a little, but I’m not aware of any straight forward way of using MongoDB as a datasource directly to Grafana. There is an issue from 2015 where adding MongoDB was proposed where some of the reasoning behind why MongoDB isn’t supported by Grafana is explained, see grafana#3153. If you have a GitHub account, you can add a thumbs up to that issue to show your support for the feature request :slightly_smiling_face:

Another way to go about it would be to use one of the existing data sources and have an export job from your MongoDB database to that data source.

1 Like