Thursday, April 26, 2018

Installing & running Prometheus

Prometheus is a powerful , open source monitoring system that collect metrics from your services and stores them in a time series database.
It provides a query language , data model and when combined with visualization tools like grafana it provides more details.
Prometheus by default only exports metrics about it self like the memory consumption etc. But it also provides expansion by installing exporters which are generally optional programs that generate additional metrics.
Exporters provides information ranging from infra to databases and from web servers to message systems , API’s and more.
Some of the most popular exporters include:
node_exporter - This produces metrics about infrastructure, including the current CPU, memory and disk usage, as well as I/O and network statistics, such as the number of bytes read from a disk or a server's average load.
blackbox_exporter - This generates metrics derived from probing protocols like HTTP and HTTPS to determine endpoint availability, response time, and more.
nginx-vts-exporter - This provides metrics about an Nginx web server using the Nginx VTS module, including the number of open connections, the number of sent responses (grouped by response codes), and the total size of sent or received requests in bytes.

In this article we will see how we can install and configure Prometheus tool.
1. Create prometheus user with no home and no shell for our installation purpose
    sudo useradd --no-create-home --shell /bin/false prometheus

2. Configure the location where you want to save the prometheus data.
    Mkdir /etc/prometheus   - For config files
    Mkdir /var/lib/prometheus  - For data

3. Set the ownership on the above locations for prometheus user
   chown prometheus:prometheus /etc/prometheus
  chown prometheus:prometheus /var/lib/prometheus
4. Now once the prerequisites are done, we will be download the prometheus and install
Wget 
https://github.com/prometheus/prometheus/releases/download/v2.2.1/
prometheus-2.2.1.linux-amd64.tar.gz
5. Untar the file to see that we have 2 binary files (prometheus and promtool ), consoles and console_libraraies directories container web interface files and some other files like examples , notice etc
6. Execute the below commands for copying binary files to /usr/local/bin location and console files. Also to change the permission on the copied files
cp prometheus/prometheus /usr/local/bin/
cp prometheus/promtool /usr/local/bin/
chown prometheus:prometheus /usr/local/bin/prometheus
chown prometheus:prometheus /usr/local/bin/promtool
cp -r prometheus/consoles /etc/prometheus
cp -r prometheus/console_libraries /etc/prometheus
chown -R prometheus:prometheus /etc/prometheus/consoles
chown -R prometheus:prometheus /etc/prometheus/console_libraries
7.  Create a basic config prometheus file at /etc/prometheus
[root@root] cat /etc/prometheus/prometheus.yml
global:
  scrape_interval: 15s
scrape_configs:
  - job_name: 'prometheus'
    scrape_interval: 5s
    static_configs:
      - targets: ['localhost:9090']
  - job_name: 'node_exporter'
    scrape_interval: 5s
    static_configs:
      - targets: ['localhost:9100']
The configuration file is written in the yml format. The major configuration will be defined under the global element.
This scrape_interval value tells Prometheus to collect metrics from its exporters every 15 seconds, which is long enough for most exporters.
Once the scrape interval are defined we can then configure our node exporters.
By default prometheus gather all details about it self. You can also see i configured node exporter too. Please check this link for configuring node exporter.
We can understand the other elements. Job name is used to know the type of exporter we are using , static config and target as used to define where these exporters are running.
8. Change the permission on this file
    chown prometheus:prometheus /etc/prometheus/prometheus.yml
9. Run the prometheus using the command,
   prometheus /usr/local/bin/prometheus
    --config.file   /etc/prometheus/prometheus.yml
    --storage.tsdb.path /var/lib/prometheus/  
    --web.console.templates=/etc/prometheus/consoles
    --web.console.libraries=/etc/prometheus/console_libraries
10. Check the status if the server is running.
11. Access the application using “http://<IP address>:9090/”. You will be seeing some screen like this
This is how you will be installing Prometheus tool and we will see more of this tool. More to Come ,Happy Learning :-)

No comments :

Post a Comment