Serverspace accelerated the answering of support requests by 40%
June 29, 2023
Updated June 30, 2023

How to monitor MongoDB with Grafana and Prometheus on Ubuntu

MongoDB Ubuntu Web server

Resource monitoring is an essential aspect of managing any system, whether it's a computer system, a network, or a server. By monitoring resources, we can get valuable insights into how our systems are performing, identify potential issues before they become critical problems, and optimize resource usage to improve performance and reduce costs.

Here are some specific reasons why monitoring resources is important:

  • Performance optimization — Resource monitoring helps identify performance bottlenecks so that administrators can take corrective action to improve the system's performance. For example, if we notice that CPU usage is consistently high, we might upgrade the hardware or adjust the workload distribution to balance the load more effectively.
  • Capacity planning — Resource monitoring provides information on how much capacity is being used, allowing administrators to make informed decisions about when to add more resources to support growing demand. This helps ensure that the system has enough capacity to meet current and future demands.
  • Cost control — Resource monitoring helps track resource usage, which can help organizations identify opportunities to reduce costs by optimizing usage and retiring unused resources.
  • Security — Monitoring resources can also help detect potential security threats by providing visibility into unusual activity or patterns that may indicate a breach or other unauthorized access.

Overall, resource monitoring is an essential tool for ensuring the optimal performance, scalability, and security of IT systems.

Software for installation

In that article we will use bundle for build that monitoring, alerting and visualize system. MongoDB, Graphana, Prometheus will provide interesting solution for our purposes. Graphana it's system which includes many modules and forms from it visualize system. Very comfortable. Prometheus plays an equally significant role: monitoring, alerting and transporting data. MongoDB it's common data base with save data as main function. Let's have a look for this!

Install and exploit monitoring system

Before using the main utility update and upgrade your system:

sudo apt update -y && sudo apt dist-upgrade -y
Update OS
Screenshot №1 — Update OS

For pulling container you need to register on DockerHub, please fill all needed fields and check email for confirmation:

Screenshot №2 — Site

With next step download all requirements and software:

apt install
Screenshot №3 — Install

Then we need to login into the account on our server via command below:

docker login
Screenshot №4 — Login

You will not see the typing password, but all letters and symbols will be entered! We need to pull all needed container wich have libraries and сompiled system application:

docker pull grafana/grafana && docker pull prom/prometheus && docker pull ranchercharts/bitnami-mongodb-exporter:0.8.0-debian-9-r4
Pulling software
Screenshot №5 — Pulling software

After this we need to build a dependencies between database and monitoring system, let's create configuration file in folder:

cd / && mkdir /conf && nano conf/prometheus.yml
Screenshot №6 — Folder

Enter in configuration files next parameters:

scrape_interval: 15s # how often to scrape targets by default
evaluation_interval: 15s # how often to evaluate rules by default

- job_name: 'mongodb-exporter'
scrape_interval: 5s
- targets: ['mongo-exporter:9216']

Text for config
Screenshot №7 — Text for config

In that parameters we have indicated MongoDB and port for communication and export data. Press button combination Ctrl + O  for save config and Ctrl + X  for exit from text editor. Now run container with our modules:

sudo docker run -d --name=grafana -p 3000:3000 grafana/grafana
sudo docker run -d --name=prometheus -p 9090:9090 prom/prometheus
sudo docker run -d --name mongodb-exporter -p 9216:9216 ranchercharts/bitnami-mongodb-exporter:0.8.0-debian-9-r4
Run container
Screenshot №8 — Run container

In output we will see ID for every container in process. Let's check it:

docker ps -a
Screenshot №9 — Check

If all process will alright, so we can go ahead and install graphical shell for system via command:

apt-get install ubuntu-gnome-desktop
Install Gnome
Screenshot №10 — Install Gnome

Be patient and wait for the end of the installation all shell and then reboot system via command:


After this server will restart and we will see panel for login, write your credentials and enter:

Panel login
Screenshot №11 — Panel login

For our purposes we need to install Firefox browser and wait end of installation:

sudo apt install firefox
Install Firefox
Screenshot №12 — Install Firefox

Run on the Desktop browser for next step:

Run FireFox
Screenshot №13 — Run FireFox

Go to the HTTP://localhost:3000 in the search bar. That URL open Graphana, type the login and password by the default settings Login:admin and Password:admin. Enter credentials:

Login Graphana
Screenshot №14 — Login Graphana

Okey, we are in. Go to the tab Administration and choose Add data, then you can enter URL for Prometheus http://localhost:9090:

Main window
Screenshot №15 — Main window

Click for the button Add data source:

Button for add
Screenshot №16 — Button for add

Check the message above this source and we get it! System was installed!

 Add sources
Screenshot №17 — Add sources


In conclusion, resource monitoring is crucial for the effective management of any system. By tracking resources such as CPU usage, bandwidth, and cost, organizations can optimize the performance of their IT systems and identify potential security threats. In this article, we looked at how to set up a resource monitoring system using tools such as Prometheus, MongoDB and Grafana. By following the instructions in this guide, you can easily install and use these tools to create an effective monitoring, alerting and visualization system for your organization. By installing the right system, you can ensure that your IT infrastructure works smoothly, reliably and with maximum efficiency.

5 out of 5
Аverage rating : 5
Rated by: 1
1101 CT Amsterdam The Netherlands, Herikerbergweg 292
+31 20 262-58-98
700 300
700 300

You might also like...

We use cookies to make your experience on the Serverspace better. By continuing to browse our website, you agree to our
Use of Cookies and Privacy Policy.