How to Monitor an Ubuntu Server with Grafana & Prometheus

Grafana is an open source metric analytics & visualization tool which can help us to monitor the system with a nice Dashboard.

Step 1: Installing Grafana

Grafana is available in the official packages repository, however it could not be the latest version, so we’ll use the official repository on packagecloud.

First, download the GPG key of packagecloud and add it to the trusted APT keys.

$ curl https://packagecloud.io/gpg.key | sudo apt-key add -

Then, add the packagecloud repository to your APT sources.

$ sudo add-apt-repository "deb https://packagecloud.io/grafana/stable/debian/ stretch main"

Refresh your APT cache to update your package lists.

$ sudo apt-get update

Then make sure Grafana will be installed from the packagecloud repository.

$ apt-cache policy grafana

Now, we can proceed with the installation of Grafana.

$ sudo apt-get install grafana

Once installed, now we can start it.

$ sudo systemctl start grafana-server

We should check now Grafana has started OK (active (running)).

$ sudo systemctl status grafana-server

And finally, enable Grafana to start at boot time.

$ sudo systemctl enable grafana-server

Step 2: Installing Prometheus

Prometheus is an open-source systems monitoring and alerting toolkit. We are going to use the APT tool to install it:

$ sudo apt-get install prometheus prometheus-node-exporter

After this, we should check we have 2 new TCP connections listen on port 9090 and 9100.

$ netstat -plunt

Also, we could see that on port 3000 it is listening Grafana.

Step 3: Login into the system

Once installed Grafana & Prometheus, you can access Grafana site from a Web Browser. The URL is the IP address of the web server (or the domain), and the port is the 3000. The first page you should see is this.

You can login with the admin/admin credentials. Once logged, you have to change the password of the admin account.

Step 4: Setting up the Prometheus Data Source

Grafana needs to add new data sources.

Step 5: Creating the new Dashboard

Grafana has lots of Grafana Dashboards created by different users which are shared in the Grafana Dashboard URL. I use the “Node Exporter Full” Dashboard, so I only have to add the 7039 ID in the import Dashboard tool of Grafana.

And finally, we have the Dashboard created with several statistics to monitor our server.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.