{"id":527,"date":"2022-09-01T08:36:09","date_gmt":"2022-10-06T12:04:35","guid":{"rendered":"https:\/\/www.silicloud.com\/blog\/uncategorized\/how-to-keep-track-of-mongodb-using-grafana-and-prometheus-on-ubuntu-20-04\/"},"modified":"2024-03-14T15:31:53","modified_gmt":"2024-03-14T15:31:53","slug":"how-to-keep-track-of-mongodb-using-grafana-and-prometheus-on-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/blog\/how-to-keep-track-of-mongodb-using-grafana-and-prometheus-on-ubuntu-20-04\/","title":{"rendered":"How to keep track of MongoDB using Grafana and Prometheus on Ubuntu 20.04."},"content":{"rendered":"<p>As part of the Write for Donations program, the author opted to donate to the COVID-19 Relief Fund.<\/p>\n<h3>The following paragraph should be paraphrased natively:<\/h3>\n<p>&#8220;Introducing oneself is crucial at the start of any conversation or meeting. It sets the tone and allows people to get to know each other. It is a way of sharing personal information and creating a connection with others.&#8221;<\/p>\n<p>Database administrators must prioritize avoiding performance and memory problems. Prometheus and Grafana are valuable tools in monitoring the performance of your database cluster. Prometheus, an open-source platform, gathers and retains metrics as time-series data and provides alerting capabilities. Grafana, an open-source web application, enables interactive visualization and analysis. It offers the capability to import data from various sources, conduct queries, and present the data on customizable charts for effortless analysis. Additionally, you can establish alerts to promptly receive notifications about any unforeseen behavior. By combining these tools, you can effectively collect, monitor, analyze, and visualize data from your MongoDB instance.<\/p>\n<p>Within this tutorial, you will establish a MongoDB database and oversee it through Grafana by utilizing Prometheus as a data source. To achieve this, you will set up the MongoDB exporter as a target for Prometheus. Consequently, Prometheus will be able to gather the metrics from your database and present them to Grafana.<\/p>\n<h2>Requirements<\/h2>\n<p>To complete this tutorial, you will require:<\/p>\n<ul class=\"post-ul\">\n<li>One <a href=\"https:\/\/ubuntu.com\/\">Ubuntu<\/a> 20.04 server with a non-root user with sudo privileges and a firewall configured with ufw, which you can do by following the Initial Server Setup Guide for Ubuntu 20.04.<\/li>\n<li>MongoDB installed on the Ubuntu 20.04 server, which you can do by following the tutorial, How To Install MongoDB on Ubuntu 20.04.<\/li>\n<li>Grafana installed on the Ubuntu 20.04 server, which you can do by following Steps 1 through 4 of the tutorial, How To Install and Secure Grafana on Ubuntu 20.04.<\/li>\n<\/ul>\n<p>To set up Grafana, you&#8217;ll require the following:<\/p>\n<ul class=\"post-ul\">\n<li>A fully registered domain name. This tutorial uses your_domain throughout. You can purchase a domain name on Namecheap, get one for free on Freenom, or use the domain registrar of your choice.<\/li>\n<li>The following DNS records set up for your server. You can follow the How To Add Domains article for details on how to add them if you are using Silicon Cloud.An A record with your_domain pointing to your server\u2019s public IP address.<br \/>\nAn A record with www.your_domain pointing to your server\u2019s public IP address.<\/li>\n<li>Nginx set up by following the How To Install Nginx on Ubuntu 20.04 tutorial, including a server block for your domain.<\/li>\n<li>An Nginx server block with Let\u2019s Encrypt configured, which you can set up by following How To Secure Nginx with Let\u2019s Encrypt on Ubuntu 20.04.<\/li>\n<\/ul>\n<h2>First, you need to install and set up Prometheus.<\/h2>\n<p>Prometheus is a toolkit for monitoring and alerts, which is open source. It is responsible for gathering and storing metrics as time-series data, with each metric being stored alongside its respective timestamp. Your task now is to install Prometheus and set it up to function as a service.<\/p>\n<h3>Setting up Prometheus<\/h3>\n<p>To start the process, ensure you have Prometheus installed. Begin by logging into your server and proceed by updating the package lists in the provided manner.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">sudo<\/span> <span class=\"token function\">apt<\/span> update<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>Afterward, you will proceed to generate the directories for Prometheus configuration and data. To establish a configuration directory named prometheus, execute the subsequent command:<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">sudo<\/span> <span class=\"token function\">mkdir<\/span> <span class=\"token parameter variable\">-p<\/span> \/etc\/<mark>prometheus<\/mark><\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>Afterward, establish the directories for data.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">sudo<\/span> <span class=\"token function\">mkdir<\/span> <span class=\"token parameter variable\">-p<\/span> \/var\/lib\/<mark>prometheus<\/mark><\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>Once you have successfully set up the directories, you can proceed to obtain the compressed installation file. Prometheus offers precompiled binary files in compressed formats. To acquire the Prometheus installation file, visit the designated download page.<\/p>\n<p>To acquire version 2.31.0, execute the subsequent command, substituting the required version number:<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">wget<\/span> https:\/\/github.com\/prometheus\/prometheus\/releases\/download\/<mark>v2.31.0<\/mark>\/prometheus-<mark>2.31.0.<\/mark>linux-amd64.tar.gz<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>After downloading the file, you can extract it by using the tarball option.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">tar<\/span> <span class=\"token parameter variable\">-xvf<\/span> prometheus-<mark>2.31.0.<\/mark>linux-amd64.tar.gz<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>Once the file has been extracted, go to the folder named Prometheus.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token builtin class-name\">cd<\/span> prometheus-<mark>2.31.0.<\/mark>linux-amd64<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>Afterwards, transfer the prometheus and promtool executable files to the \/usr\/local\/bin\/ folder.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">sudo<\/span> <span class=\"token function\">mv<\/span> prometheus promtool \/usr\/local\/bin\/<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>Afterwards, you will relocate all the files associated with Prometheus to a single destination: \/etc\/prometheus\/. To accomplish this, execute the given command to transfer the console files found in the consoles folder and the library files located in the console_libraries folder.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">sudo<\/span> <span class=\"token function\">mv<\/span> consoles\/ console_libraries\/ \/etc\/prometheus\/<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>The Prometheus GUI is accessed through the console and console library files. These files are stored together with the configuration files to ensure they are readily available when starting the service.<\/p>\n<p>Lastly, relocate the prometheus.yml template configuration file to the \/etc\/prometheus\/ folder.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">sudo<\/span> <span class=\"token function\">mv<\/span> prometheus.yml \/etc\/prometheus\/prometheus.yml<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>The Prometheus configuration file, prometheus.yml, is the designated file for customizing the port settings and determining the necessary files to enable when initiating the service.<\/p>\n<p>To inquire about the installed Prometheus version, execute the following command:<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\">prometheus <span class=\"token parameter variable\">&#8211;version<\/span><\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>You will get output that looks like this:<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<div class=\"secondary-code-label\" title=\"Output\">Output<\/div>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>prometheus, version <mark>2.31.0<\/mark> (branch: HEAD, revision: b41e0750abf5cc18d8233161560731de05199330) build user: root@0aa1b7fc430d build date: 20220714-15:13:18 go version: go1.18.4 platform: linux\/amd64<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>After successfully installing Prometheus in the previous section and confirming its version, the next step will be to initiate it as a service.<\/p>\n<h3>Using Prometheus in a service-oriented manner<\/h3>\n<p>Once Prometheus has been installed, you will proceed with setting it up to run as a service.<\/p>\n<p>To achieve this, first establish a Prometheus group and user before developing the system file. It is important to have a specific user with owner privileges for the relevant folders. Carry out the following command to establish a Prometheus group.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">sudo<\/span> <span class=\"token function\">groupadd<\/span> <span class=\"token parameter variable\">&#8211;system<\/span> <mark>prometheus<\/mark><\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>Afterward, generate a prometheus user and allocate it to the previously established prometheus group.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">sudo<\/span> <span class=\"token function\">useradd<\/span> <span class=\"token parameter variable\">-s<\/span> \/sbin\/nologin <span class=\"token parameter variable\">&#8211;system<\/span> <span class=\"token parameter variable\">-g<\/span> <mark>prometheus<\/mark> <mark>prometheus<\/mark><\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>Modify the ownership and permissions of the directory accordingly to ensure that the dedicated user possesses the accurate permissions.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">sudo<\/span> <span class=\"token function\">chown<\/span> <span class=\"token parameter variable\">-R<\/span> prometheus:prometheus \/etc\/prometheus\/ \/var\/lib\/prometheus\/<\/li>\n<li data-prefix=\"$\"><span class=\"token function\">sudo<\/span> <span class=\"token function\">chmod<\/span> <span class=\"token parameter variable\">-R<\/span> <span class=\"token number\">775<\/span> \/etc\/prometheus\/ \/var\/lib\/prometheus\/<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>Afterwards, you will generate the service file for executing Prometheus as a service. Employing either nano or your preferred text editor, forge a prometheus.service file within the systemd service.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">sudo<\/span> <span class=\"token function\">nano<\/span> \/etc\/systemd\/system\/<mark>prometheus.service<\/mark><\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>Include these lines of code:<\/p>\n<p>Insert the following code snippets:<\/p>\n<p>Incorporate the subsequent lines of code:<\/p>\n<p>Integrate the following code lines:<\/p>\n<div>One possible option for paraphrasing &#8220;\/etc\/systemd\/system\/prometheus.service&#8221; natively could be:<br \/>\n&#8220;A service file for Prometheus located in the systemd directory under \/etc.&#8221;<\/div>\n<pre class=\"post-pre\"><code>[Unit]\r\nDescription=Prometheus\r\nts=network-online.target\r\nAfter=network-online.target\r\n\r\n[Service]\r\nUser=prometheus\r\nGroup=prometheus\r\nRestart=always\r\nType=simple\r\nExecStart=\/usr\/local\/bin\/prometheus \\\r\n    --config.file=\/etc\/prometheus\/prometheus.yml \\\r\n    --storage.tsdb.path=\/var\/lib\/prometheus\/ \\\r\n    --web.console.templates=\/etc\/prometheus\/consoles \\\r\n    --web.console.libraries=\/etc\/prometheus\/console_libraries \\\r\n    --web.listen-address=0.0.0.0:9090\r\n\r\n[Install]\r\ntedBy=multi-user.target\r\n<\/code><\/pre>\n<p>By utilizing this code, you can set up Prometheus to utilize the files mentioned in the ExecStart section in order to operate the service. The service file instructs systemd to execute Prometheus with the prometheus user, using the configuration file located at \/etc\/prometheus\/prometheus.yml and storing its data in the \/var\/lib\/prometheus directory. Additionally, Prometheus is configured to operate on port 9090. Please note that the detailed explanation of systemd service files is not covered in this tutorial, however, you can find more information at Understanding Systemd Units and Unit Files.<\/p>\n<p>Please save and close your file. If you are using nano, press CTRL+X, followed by Y.<\/p>\n<p>Begin running the Prometheus service.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">sudo<\/span> systemctl start prometheus<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>Allow the Prometheus service to initiate automatically upon system initialization.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">sudo<\/span> systemctl <span class=\"token builtin class-name\">enable<\/span> prometheus<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>To determine the service status, you can utilize the given command.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">sudo<\/span> systemctl status prometheus<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>The result will verify the service&#8217;s active status.<\/p>\n<div>\n<p>Generate a single option of the following paraphrase:<\/p>\n<p>Result<\/p>\n<\/div>\n<pre class=\"post-pre\"><code>\u25cf prometheus.service - Prometheus\r\n     Loaded: loaded (\/etc\/systemd\/system\/prometheus.service; enabled; vendor preset: enabled)\r\n     Active: <mark>active (running)<\/mark> since Fri 2022-08-05 18:06:05 UTC; 13s ago\r\n   Main PID: 7177 (prometheus)\r\n      Tasks: 6 (limit: 527)\r\n     Memory: 21.0M\r\n     CGroup: \/system.slice\/prometheus.service\r\n             \u2514\u25007177 \/usr\/local\/bin\/prometheus --config.file=\/etc\/prometheus\/prometheus.yml --storage.tsdb.path=\/var\/lib\/prometheus\/ --web.console.template&gt;\r\n<\/code><\/pre>\n<p>To open Prometheus, open your web browser and go to your server&#8217;s IP address with port 9090 added at the end: http:\/\/your_server_ip:9090.<\/p>\n<div class=\"post-conf-note\">\n<p class=\"post-conf-desc\">Note<\/p>\n<div>Please ensure that port 9090 is allowed on your server in order to access the Prometheus web console. To verify your existing UFW ruleset, execute the following command:<br \/>\nsudo ufw status<\/div>\n<p>If port 9090 is currently not permitted, you can grant access by executing the following command:<br \/>\nsudo ufw allow 9090<\/p>\n<\/div>\n<p>The Prometheus web console is now available for your access.<\/p>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/655c7e32c40ba52feef2082f\/65-0.png\" alt=\"Screencapture showing the Prometheus web console\" \/><\/div>\n<p>After completing this stage, Prometheus was successfully installed and set up as a service. Now, the next step involves associating your MongoDB database with Prometheus by utilizing the MongoDB exporter.<\/p>\n<h2>Second step: Configuring the MongoDB Exporter.<\/h2>\n<p>To collect metrics, Prometheus utilizes scraping of targets. Now, you will need to install the MongoDB exporter and configure it as a Prometheus target to enable data collection from your MongoDB instance.<\/p>\n<h3>The process of setting up the MongoDB Exporter software.<\/h3>\n<p>Create a folder for the MongoDB exporter in this section and go to it.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">mkdir<\/span> <mark>mongodb-exporter<\/mark><\/li>\n<li data-prefix=\"$\"><span class=\"token builtin class-name\">cd<\/span> <mark>mongodb-exporter<\/mark><\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>To obtain the MongoDB exporter, access it on Github. It is accessible as a binary file in an archive, which you will subsequently set up as a service. Use the specified command to download the binary file.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">wget<\/span> https:\/\/github.com\/percona\/mongodb_exporter\/releases\/download\/<mark>v0.7.1<\/mark>\/mongodb_exporter-<mark>0.7.1.<\/mark>linux-amd64.tar.gz<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>Afterwards, unzip the downloaded archive and place its contents into your existing directory.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">tar<\/span> xvzf mongodb_exporter-<mark>0.7.1.<\/mark>linux-amd64.tar.gz<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>In the end, relocate the mongodb_exporter executable to usr\/local\/bin\/.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">sudo<\/span> <span class=\"token function\">mv<\/span> mongodb_exporter \/usr\/local\/bin\/<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>You have completed the installation of the MongoDB exporter in this part. In the next step, you will activate MongoDB authentication and establish a user specifically for monitoring purposes.<\/p>\n<h3>Enabling authentication for MongoDB.<\/h3>\n<p>You will configure MongoDB authentication for the MongoDB exporter and generate a user to oversee the metrics of the cluster in this part.<\/p>\n<p>Start by establishing a connection to your MongoDB instance using mongo.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\">mongo<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>Create an administrator account for your exporter with the cluster monitor role and switch to the admin database.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"&gt;\">use admin<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>Once you have switched to the admin database, proceed to create a user who possesses the clusterMonitor role.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"&gt;\">db.createUser<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">{<\/span>user: <span class=\"token string\">&#8220;<mark>test<\/mark>&#8220;<\/span>,pwd: <span class=\"token string\">&#8220;<mark>testing<\/mark>&#8220;<\/span>,roles: <span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">{<\/span> role: <span class=\"token string\">&#8220;clusterMonitor&#8221;<\/span>, db: <span class=\"token string\">&#8220;admin&#8221;<\/span> <span class=\"token punctuation\">}<\/span>,<span class=\"token punctuation\">{<\/span> role: <span class=\"token string\">&#8220;read&#8221;<\/span>, db: <span class=\"token string\">&#8220;local&#8221;<\/span> <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>You will get the subsequent result.<\/p>\n<pre class=\"post-pre\"><code>Successfully added user: {\r\n        \"user\" : \"<mark>test<\/mark>\",\r\n        \"roles\" : [\r\n                {\r\n                        \"role\" : \"clusterMonitor\",\r\n                        \"db\" : \"admin\"\r\n                },\r\n                {\r\n                        \"role\" : \"read\",\r\n                        \"db\" : \"local\"\r\n                }\r\n        ]\r\n}\r\n<\/code><\/pre>\n<p>Once the user has been created, you can leave the MongoDB shell.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"&gt;\"><span class=\"token builtin class-name\">exit<\/span><\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>Afterward, assign the MongoDB URI environment variable with the correct authentication credentials.<\/p>\n<pre class=\"post-pre\"><code>export MONGODB_URI=mongodb:\/\/<mark>test<\/mark>:<mark>testing<\/mark>@localhost:27017\r\n<\/code><\/pre>\n<p>You designate the MONGODB_URI to indicate the mongodb instance which utilizes the previous authentication credentials (the test user and testing password). 27017 serves as the standard port for a mongodb instance. Once the environment variable is set, it becomes prioritized over the profile saved in the configuration file.<\/p>\n<p>To verify if the MongoDO URI environment variable was accurately set, execute the subsequent command.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">env<\/span> <span class=\"token operator\">|<\/span> <span class=\"token function\">grep<\/span> mongodb<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>You will be given the following result.<\/p>\n<pre class=\"post-pre\"><code>MONGODB_URI=mongodb:\/\/mongodb_exporter:password@localhost:27017\r\n<\/code><\/pre>\n<p>In this part, you established a MongoDB user with the clusterMonitor function that assists in monitoring the cluster metrics. Subsequently, you will set up the MongoDB exporter to operate as a service.<\/p>\n<h3>Developing a service to facilitate the MongoDB exporter<\/h3>\n<p>In this part, you will generate a system file for the MongoDB exporter and execute it as a service.<\/p>\n<p>Go to \/lib\/systemd\/system and generate a service file for the exporter by using nano or any text editor of your choice.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token builtin class-name\">cd<\/span> \/lib\/systemd\/system\/<\/li>\n<li data-prefix=\"$\"><span class=\"token function\">sudo<\/span> <span class=\"token function\">nano<\/span> mongodb_exporter.service<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>Copy and insert the given configuration into your service file.<\/p>\n<div>\/lib\/systemd\/system\/mongodb_exporter.service could be restated as &#8220;The service file for MongoDB exporter can be found in the directory \/lib\/systemd\/system.&#8221;<\/div>\n<pre class=\"post-pre\"><code>[Unit]\r\nDescription=MongoDB Exporter\r\nUser=prometheus\r\n\r\n[Service]\r\nType=simple\r\nRestart=always\r\nExecStart=\/usr\/local\/bin\/mongodb_exporter\r\n\r\n[Install]\r\ntedBy=multi-user.target\r\n<\/code><\/pre>\n<p>The service file instructs systemd to execute the MongoDB exporter as a service using the prometheus user. ExecStart will execute the mongodb_exporter binary located in usr\/local\/bin\/. To learn more about systemd service files, refer to the article &#8220;Understanding Systemd Units and Unit Files&#8221;.<\/p>\n<p>Please save and then close your file.<\/p>\n<p>Afterward, proceed with the system daemon restart to reload the unit files.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">sudo<\/span> systemctl daemon-reload<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>Begin your service now.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">sudo<\/span> systemctl start mongodb_exporter.service<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>To verify the condition of the MongoDB exporter service, execute the command provided below.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">sudo<\/span> systemctl status mongodb_exporter.service<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>The result will validate the service&#8217;s status as active.<\/p>\n<div>Provide a single alternative for rephrasing &#8220;Output&#8221; natively.<\/div>\n<pre class=\"post-pre\"><code>\u25cf mongodb_exporter.service - MongoDB Exporter\r\n     Loaded: loaded (\/lib\/systemd\/system\/mongodb_exporter.service; disabled; vendor preset: enabled)\r\n     Active: <mark>active (running)<\/mark> since Fri 2022-08-05 18:18:38 UTC; 1 weeks 3 days ago\r\n   Main PID: 7352 (mongodb_exporte)\r\n      Tasks: 5 (limit: 527)\r\n     Memory: 14.2M\r\n     CGroup: \/system.slice\/mongodb_exporter.service\r\n             \u2514\u25007352 \/usr\/local\/bin\/mongodb_exporter\r\n\r\n<\/code><\/pre>\n<p>To confirm proper functioning, go to the project&#8217;s main directory and execute a curl command on port 9216, which is where the exporter operates, ensuring everything is functioning correctly.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token builtin class-name\">cd<\/span> ~<\/li>\n<li data-prefix=\"$\"><span class=\"token function\">sudo<\/span> <span class=\"token function\">curl<\/span> http:\/\/localhost:9216\/metrics<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>The result will be lengthy and will consist of lines that resemble this one.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<div class=\"secondary-code-label\" title=\"Output\">Output<\/div>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p># HELP go_gc_duration_seconds A summary of the GC invocation durations. # TYPE go_gc_duration_seconds summary go_gc_duration_seconds{quantile=&#8221;0&#8243;} 0 go_gc_duration_seconds{quantile=&#8221;0.25&#8243;} 0 go_gc_duration_seconds{quantile=&#8221;0.5&#8243;} 0 go_gc_duration_seconds{quantile=&#8221;0.75&#8243;} 0 go_gc_duration_seconds{quantile=&#8221;1&#8243;} 0 go_gc_duration_seconds_sum 0 go_gc_duration_seconds_count 0 # HELP go_goroutines Number of goroutines that currently exist. # TYPE go_goroutines gauge go_goroutines 11 # HELP go_memstats_alloc_bytes Number of bytes allocated and still in use. # TYPE go_memstats_alloc_bytes gauge go_memstats_alloc_bytes 1.253696e+06 # HELP go_memstats_alloc_bytes_total Total number of bytes allocated, even if freed. # TYPE go_memstats_alloc_bytes_total counter go_memstats_alloc_bytes_total 1.253696e+06 # HELP go_memstats_buck_hash_sys_bytes Number of bytes used by the profiling bucket hash table. # TYPE go_memstats_buck_hash_sys_bytes gauge go_memstats_buck_hash_sys_bytes 3054 # HELP go_memstats_frees_total Total number of frees. # TYPE go_memstats_frees_total counter go_memstats_frees_total 2866 # HELP go_memstats_gc_sys_byte . . . # HELP mongodb_asserts_total The asserts document reports the number of asserts on the database. While assert errors are typically uncommon, if there are non-zero values for the asserts, you should check the log file for the mongod process for more information. In many cases these errors are trivial, but are worth investigating. # TYPE mongodb_asserts_total counter mongodb_asserts_total{type=&#8221;msg&#8221;} 0 mongodb_asserts_total{type=&#8221;regular&#8221;} 0 mongodb_asserts_total{type=&#8221;rollovers&#8221;} 0 mongodb_asserts_total{type=&#8221;user&#8221;} 19 mongodb_asserts_total{type=&#8221;warning&#8221;} 0 # HELP mongodb_connections The connections sub document data regarding the current status of incoming connections and availability of the database server. Use these values to assess the current load and capacity requirements of the server # TYPE mongodb_connections gauge mongodb_connections{state=&#8221;available&#8221;} 51198 mongodb_connections{state=&#8221;current&#8221;} 2 # HELP mongodb_connections_metrics_created_total totalCreated provides a count of all incoming connections created to the server. This number includes connections that have since closed # TYPE mongodb_connections_metrics_created_total counter mongodb_connections_metrics_created_total 6 # HELP mongodb_exporter_build_info A metric with a constant &#8216;1&#8217; value labeled by version, revision, branch, and goversion from which mongodb_exporter was built. # TYPE mongodb_exporter_build_info gauge mongodb_exporter_build_info{branch=&#8221;v0.7.1&#8243;,goversion=&#8221;go1.11.10&#8243;,revision=&#8221;3002738d50f689c8204f70f6cceb8150b98fa869&#8243;,version=&#8221;0.7.1&#8243;} 1 # HELP mongodb_exporter_last_scrape_duration_seconds Duration of the last scrape of metrics from MongoDB. # TYPE mongodb_exporter_last_scrape_duration_seconds gauge mongodb_exporter_last_scrape_duration_seconds 0.003641888 # HELP mongodb_exporter_last_scrape_error Whether the last scrape of metrics from MongoDB resulted in an error (1 for error, 0 for success). # TYPE mongodb_exporter_last_scrape_error gauge mongodb_exporter_last_scrape_error 0 . . . &#8230;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>The result affirms that the MongoDB exporter is gathering statistics, such as the version of MongoDB, the details of the metric document, and information about the connections.<\/p>\n<p>After setting up the MongoDB exporter as a service and gathering metrics from MongoDB in the previous section, the next step is to configure the exporter as a destination for Prometheus.<\/p>\n<h3>Setting up the MongoDB Exporter to function as a Prometheus Target.<\/h3>\n<p>Go to the directory where your Prometheus configuration file is located and set up the MongoDB exporter as a target for Prometheus.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token builtin class-name\">cd<\/span> \/etc\/prometheus\/<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>Open the file for editing by using nano or any preferred text editor.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">sudo<\/span> <span class=\"token function\">nano<\/span> prometheus.yml<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>To include the MongoDB exporter as a destination, simply duplicate the highlighted code lines into your document.<\/p>\n<div>The Prometheus configuration file can be found at &#8220;\/etc\/prometheus\/prometheus.yml&#8221;.<\/div>\n<pre class=\"post-pre\"><code># A scrape configuration containing exactly one endpoint to scrape:\r\n# Here it's Prometheus itself.\r\nscrape_configs:\r\n  # The job name is added as a label `job=&lt;job_name&gt;` to any timeseries scraped from this config.\r\n  - job_name: \"prometheus\"\r\n    static_configs:\r\n            - targets: [\"localhost:9090\"<mark>, \"localhost:9216\"]<\/mark>\r\n<\/code><\/pre>\n<p>The default port for the MongoDB exporter is 9216.<\/p>\n<p>Please save and close your file.<\/p>\n<p>Once the target is added, reboot Prometheus.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">sudo<\/span> systemctl restart prometheus<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>Go to http:\/\/localhost:9090\/targets to confirm that Prometheus is collecting data from your recently added exporter.<\/p>\n<div class=\"post-conf-note\">\n<p class=\"post-conf-desc\">Note<\/p>\n<div>Please be advised that if you are utilizing a remote server, you can access the targets by visiting http:\/\/your_server_ip:9090\/targets. Alternatively, you can view the targets locally by employing port-forwarding. To do this, launch a new terminal on your local computer and enter the following command: ssh -L 9090:localhost:9090 your_non_root_user@your_server_ip. Once you have successfully connected to the server, you can access the targets by visiting http:\/\/localhost:9090\/targets on your local machine&#8217;s web browser.<\/div>\n<\/div>\n<p>You will be able to see a collection of Prometheus targets.<\/p>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/655c7e32c40ba52feef2082f\/138-0.png\" alt=\"Screencapture showing the list of Prometheus targets\" \/><\/div>\n<p>The Prometheus scraping itself through the 9090 endpoint, while the MongoDB exporter validates if your configuration is functioning correctly through the 9216 endpoint.<\/p>\n<p>After completing this step, you have successfully installed the MongoDB exporter and set it up as a Prometheus target for gathering metrics. Moving forward, you can now proceed to the Grafana web console where you will generate a MongoDB dashboard for monitoring and analyzing these metrics.<\/p>\n<h2>Step 3 involves creating a Grafana dashboard for MongoDB.<\/h2>\n<p>To proceed, create a dashboard on Grafana to display your MongoDB data. To achieve this, incorporate Prometheus as a data source within Grafana and then import a MongoDB dashboard from Percona. Percona offers various dashboards specific to MongoDB, available in their product documentation. For this guide, import the MongoDB Overview dashboard into your Grafana setup. To get started, define Prometheus as a data source in Grafana.<\/p>\n<p>After completing the necessary requirements, you have installed and ensured the security of Grafana. Now, go to your Grafana instance at your_domain:3000 and access it by logging in with the credentials you generated during the initial setup.<\/p>\n<p>On the left side, simply click on the gear icon located in the panel for Configuration and proceed to choose Data Sources.<\/p>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/655c7e32c40ba52feef2082f\/145-0.png\" alt=\"Screencapture showing adding a Data Source under the Configuration tab in Grafana\" \/><\/div>\n<p>Please select &#8220;Add data source.&#8221;<\/p>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/655c7e32c40ba52feef2082f\/147-0.png\" alt=\"Screencapture showing the button for adding a data source in Grafana\" \/><\/div>\n<p>Choose Prometheus from the options.<\/p>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/655c7e32c40ba52feef2082f\/149-0.png\" alt=\"Screencapture showing selecting Prometheus as a data source in Grafana\" \/><\/div>\n<p>On the upcoming screen, you will set up the configurations for your Prometheus data source.<\/p>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/655c7e32c40ba52feef2082f\/151-0.png\" alt=\"Screencapture showing the configuration settings for the Prometheus data source in Grafana\" \/><\/div>\n<p>Please enter the URL of your Prometheus instance in the URL field.<\/p>\n<pre class=\"post-pre\"><code>http:\/\/<mark>your_server_ip<\/mark>:9090\/\r\n<\/code><\/pre>\n<p>Choose &#8220;Save &amp; test&#8221; located at the bottom of the screen to successfully include Prometheus as a data source in Grafana.<\/p>\n<p>Afterward, proceed to import the MongoDB Overview dashboard onto Grafana. You are able to import the dashboard either by uploading a JSON file or by importing the dashboard ID. The dashboard ID can be located in the documentation of Grafana product specifically designed for dashboards. In this case, you will use the dashboard ID to perform the importation of the dashboard.<\/p>\n<p>Click on the plus icon on the left menu and choose Import under the Create option. This will direct you to the Import page.<\/p>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/655c7e32c40ba52feef2082f\/157-0.png\" alt=\"Screencapture showing the option to add Prometheus as a data source in Grafana\" \/><\/div>\n<p>You have the option to either upload the JSON file of the dashboard or enter the Grafana Dashboard ID here.<\/p>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/655c7e32c40ba52feef2082f\/159-0.png\" alt=\"Screencapture showing the options for uploading a JSON file or adding a Dashboard ID\" \/><\/div>\n<p>Include the Grafana dashboard ID, which can be located on the MongoDB overview dashboard page in Grafana.<\/p>\n<pre class=\"post-pre\"><code>https:\/\/grafana.com\/grafana\/dashboards\/7353\r\n<\/code><\/pre>\n<p>There are numerous available dashboards that can be found on the Grafana page.<\/p>\n<p>Once you have entered the dashboard ID, simply click on the Load button.<\/p>\n<p>Afterwards, you will be directed to an Options page where you have the opportunity to name the dashboard, choose the folder it belongs to, and select a data source. You can keep the default names for the dashboard and folder if you prefer. In terms of the data source, opt for Prometheus. Once you have completed filling in the necessary details, simply click on the Import button.<\/p>\n<p>We will create the dashboard.<\/p>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/655c7e32c40ba52feef2082f\/166-0.png\" alt=\"Screencapture showing the MongoDB Overview Dashboard in Grafana\" \/><\/div>\n<p>Your MongoDB database dashboard will provide live updates on various activities including command operations, connections, cursors, document operations, and queued operations. For more information, refer to the documentation on the MongoDB Overview dashboard in Percona&#8217;s resources.<\/p>\n<h2>A conclusion can be drawn.<\/h2>\n<p>In this article, you establish a Grafana dashboard for overseeing Prometheus metrics of your MongoDB database, allowing you to conveniently monitor the database through a graphical user interface. Initially, you install Prometheus and configure the MongoDB exporter. Following that, you incorporate Prometheus as a data source in Grafana, granting you the capability to monitor and display data from your MongoDB instance.<\/p>\n<p>Now that the monitoring pipeline for MongoDB is fully functional, you can delve further. To begin, experiment with exploring extra Grafana dashboards.<\/p>\n<p>If you t to expand your knowledge of MongoDB, take a look at our tutorial series called How To Manage Data with MongoDB.<\/p>\n<p>If you t a fast way to set up a fully functional database, take a look at Silicon Cloud&#8217;s MongoDB Managed Database.<\/p>\n<p>&nbsp;<\/p>\n<p>More Tutorials<\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/heres-a-possible-paraphrase-step-by-step-guide-to-installing-and-securing-grafana-on-ubuntu-18-04\/\" target=\"_blank\" rel=\"noopener\">Grafana Tutor Step-by-step Guide to Grafana on Ubuntu 18.04<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/insertmany-function-for-bulk-insertion\/\" target=\"_blank\" rel=\"noopener\">insertMany function for bulk insertion into a MongoDB database.<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/one-possible-paraphrase-for-the-given-sentence-ishow-to-set-up-automatic-scaling-of-kubernetes-pods-using-metrics-server\/\" target=\"_blank\" rel=\"noopener\">automatic scaling of Kubernetes pods using Metrics Server?<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/set-in-python\/\" target=\"_blank\" rel=\"noopener\">Set in Python<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/reading-and-writing-data-using-python\/\" target=\"_blank\" rel=\"noopener\">Reading and Writing data using Python<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As part of the Write for Donations program, the author opted to donate to the COVID-19 Relief Fund. The following paragraph should be paraphrased natively: &#8220;Introducing oneself is crucial at the start of any conversation or meeting. It sets the tone and allows people to get to know each other. It is a way of [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-527","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to keep track of MongoDB using Grafana and Prometheus on Ubuntu 20.04. - Blog - Silicon Cloud<\/title>\n<meta name=\"description\" content=\"you will establish a MongoDB database and oversee it through Grafana by utilizing Prometheus as a data source. To achieve this, you will set\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/blog\/how-to-keep-track-of-mongodb-using-grafana-and-prometheus-on-ubuntu-20-04\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to keep track of MongoDB using Grafana and Prometheus on Ubuntu 20.04.\" \/>\n<meta property=\"og:description\" content=\"you will establish a MongoDB database and oversee it through Grafana by utilizing Prometheus as a data source. To achieve this, you will set\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/blog\/how-to-keep-track-of-mongodb-using-grafana-and-prometheus-on-ubuntu-20-04\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-06T12:04:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-14T15:31:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/655c7e32c40ba52feef2082f\/65-0.png\" \/>\n<meta name=\"author\" content=\"Sophia Anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:site\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sophia Anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"17 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-keep-track-of-mongodb-using-grafana-and-prometheus-on-ubuntu-20-04\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-keep-track-of-mongodb-using-grafana-and-prometheus-on-ubuntu-20-04\/\"},\"author\":{\"name\":\"Sophia Anderson\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/19a24313de9c988db3d69226b4a40a30\"},\"headline\":\"How to keep track of MongoDB using Grafana and Prometheus on Ubuntu 20.04.\",\"datePublished\":\"2022-10-06T12:04:35+00:00\",\"dateModified\":\"2024-03-14T15:31:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-keep-track-of-mongodb-using-grafana-and-prometheus-on-ubuntu-20-04\/\"},\"wordCount\":3554,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-keep-track-of-mongodb-using-grafana-and-prometheus-on-ubuntu-20-04\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/how-to-keep-track-of-mongodb-using-grafana-and-prometheus-on-ubuntu-20-04\/\",\"name\":\"How to keep track of MongoDB using Grafana and Prometheus on Ubuntu 20.04. - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\"},\"datePublished\":\"2022-10-06T12:04:35+00:00\",\"dateModified\":\"2024-03-14T15:31:53+00:00\",\"description\":\"you will establish a MongoDB database and oversee it through Grafana by utilizing Prometheus as a data source. To achieve this, you will set\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-keep-track-of-mongodb-using-grafana-and-prometheus-on-ubuntu-20-04\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/blog\/how-to-keep-track-of-mongodb-using-grafana-and-prometheus-on-ubuntu-20-04\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-keep-track-of-mongodb-using-grafana-and-prometheus-on-ubuntu-20-04\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.silicloud.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to keep track of MongoDB using Grafana and Prometheus on Ubuntu 20.04.\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"name\":\"Silicon Cloud Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\",\"name\":\"Silicon Cloud Blog\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"contentUrl\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"width\":1024,\"height\":1024,\"caption\":\"Silicon Cloud Blog\"},\"image\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\",\"https:\/\/twitter.com\/SiliCloudGlobal\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/19a24313de9c988db3d69226b4a40a30\",\"name\":\"Sophia Anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c726c09aa40e37115fb5c62d0c3ed62c16ca255d3763e2e3ae83a70ddf8c2175?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c726c09aa40e37115fb5c62d0c3ed62c16ca255d3763e2e3ae83a70ddf8c2175?s=96&d=mm&r=g\",\"caption\":\"Sophia Anderson\"},\"url\":\"https:\/\/www.silicloud.com\/blog\/author\/sophiaanderson\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to keep track of MongoDB using Grafana and Prometheus on Ubuntu 20.04. - Blog - Silicon Cloud","description":"you will establish a MongoDB database and oversee it through Grafana by utilizing Prometheus as a data source. To achieve this, you will set","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/blog\/how-to-keep-track-of-mongodb-using-grafana-and-prometheus-on-ubuntu-20-04\/","og_locale":"en_US","og_type":"article","og_title":"How to keep track of MongoDB using Grafana and Prometheus on Ubuntu 20.04.","og_description":"you will establish a MongoDB database and oversee it through Grafana by utilizing Prometheus as a data source. To achieve this, you will set","og_url":"https:\/\/www.silicloud.com\/blog\/how-to-keep-track-of-mongodb-using-grafana-and-prometheus-on-ubuntu-20-04\/","og_site_name":"Blog - Silicon Cloud","article_publisher":"https:\/\/www.facebook.com\/SiliCloudGlobal\/","article_published_time":"2022-10-06T12:04:35+00:00","article_modified_time":"2024-03-14T15:31:53+00:00","og_image":[{"url":"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/655c7e32c40ba52feef2082f\/65-0.png"}],"author":"Sophia Anderson","twitter_card":"summary_large_image","twitter_creator":"@SiliCloudGlobal","twitter_site":"@SiliCloudGlobal","twitter_misc":{"Written by":"Sophia Anderson","Est. reading time":"17 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.silicloud.com\/blog\/how-to-keep-track-of-mongodb-using-grafana-and-prometheus-on-ubuntu-20-04\/#article","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/how-to-keep-track-of-mongodb-using-grafana-and-prometheus-on-ubuntu-20-04\/"},"author":{"name":"Sophia Anderson","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/19a24313de9c988db3d69226b4a40a30"},"headline":"How to keep track of MongoDB using Grafana and Prometheus on Ubuntu 20.04.","datePublished":"2022-10-06T12:04:35+00:00","dateModified":"2024-03-14T15:31:53+00:00","mainEntityOfPage":{"@id":"https:\/\/www.silicloud.com\/blog\/how-to-keep-track-of-mongodb-using-grafana-and-prometheus-on-ubuntu-20-04\/"},"wordCount":3554,"commentCount":0,"publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/blog\/how-to-keep-track-of-mongodb-using-grafana-and-prometheus-on-ubuntu-20-04\/","url":"https:\/\/www.silicloud.com\/blog\/how-to-keep-track-of-mongodb-using-grafana-and-prometheus-on-ubuntu-20-04\/","name":"How to keep track of MongoDB using Grafana and Prometheus on Ubuntu 20.04. - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/#website"},"datePublished":"2022-10-06T12:04:35+00:00","dateModified":"2024-03-14T15:31:53+00:00","description":"you will establish a MongoDB database and oversee it through Grafana by utilizing Prometheus as a data source. To achieve this, you will set","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/blog\/how-to-keep-track-of-mongodb-using-grafana-and-prometheus-on-ubuntu-20-04\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/blog\/how-to-keep-track-of-mongodb-using-grafana-and-prometheus-on-ubuntu-20-04\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/blog\/how-to-keep-track-of-mongodb-using-grafana-and-prometheus-on-ubuntu-20-04\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.silicloud.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to keep track of MongoDB using Grafana and Prometheus on Ubuntu 20.04."}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/blog\/#website","url":"https:\/\/www.silicloud.com\/blog\/","name":"Silicon Cloud Blog","description":"","publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.silicloud.com\/blog\/#organization","name":"Silicon Cloud Blog","url":"https:\/\/www.silicloud.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","contentUrl":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","width":1024,"height":1024,"caption":"Silicon Cloud Blog"},"image":{"@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/SiliCloudGlobal\/","https:\/\/twitter.com\/SiliCloudGlobal"]},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/19a24313de9c988db3d69226b4a40a30","name":"Sophia Anderson","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c726c09aa40e37115fb5c62d0c3ed62c16ca255d3763e2e3ae83a70ddf8c2175?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c726c09aa40e37115fb5c62d0c3ed62c16ca255d3763e2e3ae83a70ddf8c2175?s=96&d=mm&r=g","caption":"Sophia Anderson"},"url":"https:\/\/www.silicloud.com\/blog\/author\/sophiaanderson\/"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/527","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/comments?post=527"}],"version-history":[{"count":0,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/527\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/media?parent=527"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/categories?post=527"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/tags?post=527"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}