PROMETHEUS AND GRAFANA

Posted By : Yash Vishwakarma | 04-Dec-2020

USING PROMETHEUS & GRAFANA TO SEE SERVER UTILIZATION STATUS


INTRODUCTION OF PROMETHEUS:-

Prometheus is a leading monitoring solution that has seen its community grow to a large number. The support for multiple exporters is one of the strongest points of Prometheus since it can help you get started with specific monitoring requirements quickly. Prometheus is a leading open source monitoring and alert tool. Since its announcement in 2015, it has been a significant adoption. It originated at SoundCloud and was created because of the need to monitor multiple microservices that might be running in your system. With a modular architecture and availability of modules referred to as exporters, it can capture metrics from the most popular software. Written in the Go language and shipping with easily distributed binaries, Prometheus can be run as quickly as possible.


INTRODUCTION OF GRAFANA

Grafana is a beautiful dashboard for displaying various Graphic metrics through a web browser.  It has a simple set up and easy to maintain. Also, it has a nice Kabana-like display to display metrics and is also easy to use. 

I would like to walk readers through the basics of this tool because although it is a very new project it has an enormous amount of potential. 

One very nice feature of this product offering is that you do not need to worry about any of the behind the scene detail or intricacies of how all of the Graphite components work together.  You can find out with just a few clicks.  Highly recommended if you just need something that works.

 

Also Read: Setting Up Kibana For ElasticSearch


PROMETHEUS -- PROS & CONS 

 

Pros Cons

1. Prometheus has a powerful, self-contained monitoring and alert solution.

2. It is fully functional and highly reliable even when other services on your network or in the cloud are unavailable.

3. Prometheus integrates well with Grafana.

1.Graphing features are primarily intended for ad-hoc queries and debugging. Prometheus recommends Grafana for comprehensive graphing capabilities.

2.If you're looking to visualize existing log information that's already stored in a functionally redundant in some ways. You may still wish to use Prometheus for its high reliability during service outages.

GRAFANA -- PROS & CONS 

 

Pros Cons  

1. Broad compatibility and support are two of the main project goals. If you plan to hook into
multiple data sources and collaborate across different solutions, Grafana is created to make
that as straightforward as possible.

 2.Grafana includes support for Elasticsearch and Prometheus.

 3.It offers a great selection of reporting functions, which are available without customization.

 4.An active developer community contributing to the code base ensures new functionality and
compatibility options are added on a continuous basis.

1. Natural complexity occurs with such a wide variety of features and interfaces.

2.Grafana was primarily built to perform time-series analytics. Functionality may be
limited if you need other reporting types.

 

Also Read: Monitoring Using Prometheus and Grafana Stack

 

 

LET'S DOWNLOAD AND INSTALL PROMETHEUS & GRAFANA


sudo useradd --no-create-home --shell /bin/false prometheus
sudo useradd --no-create-home --shell /bin/false node_exporter

sudo mkdir /etc/prometheus
sudo mkdir /var/lib/prometheus

sudo chown prometheus:prometheus /etc/prometheus
sudo chown prometheus:prometheus /var/lib/prometheus


Step 2 — Downloading Prometheus

cd ~
curl -LO https://github.com/prometheus/prometheus/releases/download/v2.0.0/prometheus-2.0.0.linux-amd64.tar.gz


sudo cp prometheus-2.0.0.linux-amd64/prometheus /usr/local/bin/
sudo cp prometheus-2.0.0.linux-amd64/promtool /usr/local/bin/

sudo chown prometheus:prometheus /usr/local/bin/prometheus
sudo chown prometheus:prometheus /usr/local/bin/promtool

sudo cp -r prometheus-2.0.0.linux-amd64/consoles /etc/prometheus
sudo cp -r prometheus-2.0.0.linux-amd64/console_libraries /etc/prometheus

sudo chown -R prometheus:prometheus /etc/prometheus/consoles
sudo chown -R prometheus:prometheus /etc/prometheus/console_libraries

rm -rf prometheus-2.0.0.linux-amd64.tar.gz prometheus-2.0.0.linux-amd64


Step 3 — Configuring Prometheus

sudo nano /etc/prometheus/prometheus.yml

...
scrape_configs:
  - job_name: 'prometheus'
    scrape_interval: 5s
    static_configs:
      - targets: ['localhost:9090']

global:
  scrape_interval: 15s

scrape_configs:
  - job_name: 'prometheus'
    scrape_interval: 5s
    static_configs:
      - targets: ['localhost:9090']

sudo chown prometheus:prometheus /etc/prometheus/prometheus.yml

Step 4 — Running Prometheus

sudo -u 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

sudo nano /etc/systemd/system/prometheus.service

[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target

[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/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

sudo systemctl daemon-reload
sudo systemctl start prometheus
sudo systemctl status prometheus

cd ~
curl -LO https://github.com/prometheus/node_exporter/releases/download/v0.15.1/node_exporter-0.15.1.linux-amd64.tar.gz

sudo cp node_exporter-0.15.1.linux-amd64/node_exporter /usr/local/bin
sudo chown node_exporter:node_exporter /usr/local/bin/node_exporter

rm -rf node_exporter-0.15.1.linux-amd64.tar.gz node_exporter-0.15.1.linux-amd64

Step 6 — Running Node Exporter

sudo nano /etc/systemd/system/node_exporter.service

[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target

[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter

[Install]
WantedBy=multi-user.target


sudo systemctl daemon-reload

sudo systemctl start node_exporter

sudo systemctl status node_exporter

sudo systemctl enable node_exporter

Step 7 — Configuring Prometheus Node Exporter


sudo nano /etc/prometheus/prometheus.yml

Prometheus config file part 1 - /etc/prometheus/prometheus.yml

...
  - job_name: 'node_exporter'
    scrape_interval: 5s
    static_configs:
      - targets: ['localhost:9100']

Prometheus config file - /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']


sudo systemctl restart prometheus

sudo systemctl status prometheus

sudo apt-get update
sudo apt-get install apache2-utils

sudo htpasswd -c /etc/nginx/.htpasswd sammy

sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/prometheus

sudo nano /etc/nginx/sites-available/prometheus

/etc/nginx/sites-available/default

...
    location / {
        try_files $uri $uri/ =404;
    }
...
Copy


/etc/nginx/sites-available/prometheus

...
    location / {
        auth_basic "Prometheus server authentication";
        auth_basic_user_file /etc/nginx/.htpasswd;
        proxy_pass http://localhost:9090;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
...
Copy

sudo rm /etc/nginx/sites-enabled/default
sudo ln -s /etc/nginx/sites-available/prometheus /etc/nginx/sites-enabled/

sudo nginx -t

sudo systemctl reload nginx

sudo systemctl status nginx
 

 

 

We are seasoned DevOps solutions and service providers with vast experience in providing full-scale DevOps solutions for varied business requirements. Our team of DevOps professionals formulates effective strategies to strengthen your enterprise IT infrastructure and enhance operational efficiency. Our 360-degree DevOps solutions and services accelerate the software development lifecycle and ensure faster delivery with continuous deployment. For project related queries, reach us out at [email protected]

About Author

Author Image
Yash Vishwakarma

He is DevOps engineer and enthusiastic to work in Linux, Cloud technology like AWS (Amazon web services).AWS, docker, gitlab in DevOps envirnment and willing to learn new technologies and like to play table tennis and snooker.

Request for Proposal

Name is required

Comment is required

Sending message..