×


Install Prometheus Network Monitoring Server on CentOS 7

Need to install Prometheus on your CentOS Server?

This guide is for you.


Prometheus is an open-source monitoring software that is very popular in the industry. Prometheus is easy to customize, and produces metrics without impacting application performance.

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform Software Installation tasks on their CentOS System.

In this context, we shall look into the steps to install Prometheus on CentOS 7.


Prerequisites for Installing Prometheus on CentOS 7?

Prometheus scrapes metrics from instrumented jobs, either directly or via an intermediary push gateway for short-lived jobs. It stores all scraped samples locally and runs rules over this data to either aggregate and record new time series from existing data or generate alerts.


To set up this monitoring we need to have one 64-bit CentOS 7 server and follow the steps give below.


Steps for Installing Prometheus on Linux Server?

1.  Installing Prometheus Server

a. Create a new ‘prometheus’ user with the following command:

$ useradd -m -s /bin/bash prometheus

b. Then update the system with the following command:

$ yum update -y

c. After that we need to download the latest build of the Prometheus server and time-series database using the below command:

$ curl -LO "https://github.com/prometheus/prometheus/releases/download/0.16.0/prometheus-0.16.0.linux-amd64.tar.gz"

d. Then run the following commands:

$ mkdir ~/Prometheus
$ cd ~/Prometheus
$ tar -xvzf ~/Downloads/prometheus-0.16.0.linux-amd64.tar.gz

e. We can verify the installation with the following command:

$ ~/Prometheus/prometheus-0.16.0.linux-amd64/prometheus -version

The result can be seen as shown below:

prometheus, version 0.16.0 (branch: HEAD, revision: dcb8ba4)
build user: julius@desktop
build date: 20151009-23:51:17
go version: 1.5.1

2. Installing Node Exporter

Node Exporter exports lots of metrics such as disk I/O statistics, CPU load, memory usage, network statistics, and more in a format Prometheus understands.

We can install this by giving the following commands:

$ cd ~/Downloads && curl -LO "https://github.com/prometheus/node_exporter/releases/download/0.11.0/node_exporter-0.11.0.linux-amd64.tar.gz"
$ mkdir ~/Prometheus/node_exporter
$ cd ~/Prometheus/node_exporter
$ tar -xvzf ~/Downloads/node_exporter-0.11.0.linux-amd64.tar.gz

3. Running Node Exporter as a Service

a. We can use the following commands to run Node Exporter as a service.

$ sudo vi /etc/systemd/system/node_exporter.service

b. And add the following:

/etc/init/node_exporter.conf
[Unit]
Description=Node Exporter
[Service]
User=prometheus
ExecStart=/home/prometheus/Prometheus/node_exporter/node_exporter
[Install]
WantedBy=default.target

c. Then provide the following commands:

$ sudo systemctl daemon-reload
$ sudo systemctl enable node_exporter.service
$ sudo systemctl start node_exporter.service


[Need assistance to install Software on Ubuntu Server? We can help you!]


4. Starting Prometheus Server

Before we start Prometheus, we can create a configuration file for it called prometheus.yml.

$ cd ~/Prometheus/prometheus-0.16.0.linux-amd64
$ vi ~/Prometheus/prometheus-0.16.0.linux-amd64/prometheus.yml


And copy the following code into the file:

scrape_configs:
- job_name: "node"
scrape_interval: "15s"
target_groups:
- targets: ['localhost:9100']


Then open port 9090 for the Prometheus access using firewall-cmd commands below.

$ firewall-cmd --add-port=9090/tcp --permanent
$ firewall-cmd --reload

 

5. Installing PromDash

One way to visualize the data in Prometheus’s time-series database is to use PromDash.

We can install this by giving the following commands:

$ cd ~/Prometheus
$ sudo yum install git ruby ruby-devel sqlite-devel zlib-devel gcc gcc-c++ automake patch
$ git clone https://github.com/prometheus/promdash.git
$ cd ~/Prometheus/promdash
$ gem install bundler
$ bundle install --without mysql postgresql


As we are configuring PromDash to work with SQLite3, we must ensure to exclude the gems for MySQL and PostgreSQL using the –without parameter.

Once done, we can see the following messages:

. . .
Your bundle is complete!
Gems in the groups mysql and postgresql were not installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.

 

6. Setting Up the Rails Environment

We have to create a directory to store the SQLite3 databases associated with PromDash.

$ mkdir ~/Prometheus/databases

Type in the following to  PromDash create a SQLite3 database called mydb.sqlite3 inside the databases directory:

$ echo "export DATABASE_URL=sqlite3:$HOME/Prometheus/databases/mydb.sqlite3" >> ~/.bashrc

To set the RAILS_ENV environment variable to production.:

$ echo "export RAILS_ENV=production" >> ~/.bashrc

Apply the changes we made to the .bashrc file.

$ . ~/.bashrc

Next, we need to create PromDash’s tables in the SQLite3 database using the rake tool.

$ rake db:migrate

For precompiling give the following:

$ rake assets:precompile


[Need assistance with Debian Software Installation? We can help you!]


7. Starting and Configuring PromDash

Start the server as a daemon with the following command:

$ bundle exec thin start -d

We need to wait for a few seconds for the server to start and then check  http://your_server_ip:3000/ to view PromDash’s homepage.

Then click New Server, then in the form, we can give any name for the Prometheus server. Set the URL field to http://your_server_ip:9090 and the Server type field to Prometheus.


Finally, click on Create Server to complete the configuration.


8. Creating a Dashboard

The dashboard already has one graph, but it needs to be configured.

Hovering over the graph’s header (which says Title) will reveal various icons that let you configure the graph.

i. To change its title, we can click on the Graph and Axis Settings icon (fourth from the left) and type in a new title in the Graph Title field.

ii. Click on the Datasources icon, which is the second to the left, to add one or more expressions to the graph.

iii. Then click Add Expression, and enter nodeprocsrunning.

iv. Now click on the Refresh icon in the graph’s header to update the graph.

v. We can add more graphs by clicking on the Add Graph button at the bottom.


After making all the changes we can Save Changes to make the changes permanent.


[Need urgent assistance with Linux Software Installation? We can help you!]


Conclusion

#Prometheus collects metrics from targets by scraping 3metrics #HTTP endpoints. Since Prometheus exposes #data in the same manner about itself, it can also scrape and monitor its own health. 

This article will guide you on the steps to perform #installation of Prometheus on #CentOS 7 along with the method used for the #setup.