βοΈNode-exporter + Grafana + Prometheus + Alertmanager

In this guide, we will set up a monitoring system that will collect metrics from all our servers and visualize them in Grafana. You can also install Alertmanager to receive notifications about server problems, in our case, in Telegram
We need a separate server for Prometheus, Grafana, Node Exporter, Alertmanager. All other servers will only have Node Exporter installed
Prometheus is an open source DBMS written in Go. An interesting feature of Prometheus is that it pulls metrics from a given set of services. Due to this, Prometheus cannot have any data queues clogged, which means monitoring will never become a bottleneck in the system
Node Exporter is a service whose job is to export machine information in a format that Prometheus can understand. There are actually many other exporters for Prometheus, but Node Exporter is perfect for our purposes of server monitoring
Grafana is an open web frontend to various time series DBMSs, such as Graphite, InfluxDB, and, of course, Prometheus. With Grafana, we can see beautiful graphs through our browser. It is characteristic that Prometheus also has its own web interface, but even the Prometheus developers themselves recommend using Grafana

Node Exporter
Can find the latest binaries along with their checksums on the Prometheus download page
Create a service file

Check that the metrics are being given
Now is the time to check the metrics in the browser

Prometheus, Grafana, AlertManager
Step 1 - Preparing the Server
Step 2 - Create a Prometheus User
For security purposes, let's create a prometheus account
Step 3 - Install Prometheus
Step 4 - Configure Prometheus
Now we need to configure prometheus.yml and add 1 or more parameters to it depending on the number of servers and nodes used
Important - the Prometheus configuration file uses YAML format, which strictly forbids tabs and requires two spaces for indentation. Prometheus will not start if the configuration file is not formatted correctly
Open the default config and bring it to the following form
Important - we have replaced the default prometheus port (9090) with port (8080)
Create a service file

Check that the metrics are being given
Now is the time to check the information in the browser


In the future, you can add additional information about your other servers to prometheus.yml to monitor several servers at once. The configuration will depend on your settings and json for Grafana
Step 5 - Install Grafana

Now it's time to go to the browser





Now we need to specify the URL address to our server with Prometheus in the column. If Prometheus is on the same server as Grafana, then set http://localhost:8080 and save the settings


If we have downloaded json, then we upload it ourselves



You can load several json at once and switch between them. Or create your own, spending a certain amount of time on it)
Step 6 - Install Alert manager
First, let's set up Prometheus rules. To do this, create a rules.yml file in the /etc/prometheus/ section, which will contain our rules for alerts In our configuration file, we will monitor the operation of node exporter, CPU load, RAM, and disk space
Adding information about our rules to the existing prometheus config
Adding lines

Check the created rules. The output should be #SUCCESS
After making all the changes, restart Prometheus
Downloading binary files
Set up alertmanager.yml, in which we register the bot token and chat ID from Telegram, to which notifications will be sent
Create a service file
Setting up UFW
In order to ensure the protection of your data, you must at least close our ports from others, since without this, anyone knowing the server IP and port will be able to receive Node exporter or Prometheus data from Grafana We can configure UFW so that data from Prometheus and Grafana are available only from the IP we need (for example, a home PC). And data from Node exporter is available only to the server where Prometheus is installed
Useful commands
Temporarily load the CPU
Temporarily load RAM
Remove Alert manager
Remove Prometheus
Remove Grafana
Last updated
