Installing prometheus On Centos6/Centos7
Prometheus is an open-source systems monitoring and alerting toolkit, which was released in 2012. It is considered as a better alternative for popular Graphite tool.
In this article i will explain how to install prometheus on a Centos server and collects system metrics
First you have to download the binaries from https://prometheus.io/download/ . You can chose the binaries suitable for your system
For Centos 64 bit,
1 2 3 | wget https://github.com/prometheus/prometheus/releases/download/v1.2.1/prometheus-1.2.1.linux-amd64.tar.gz tar xvfz prometheus–1.2.1.linux–amd64.tar.gz cd prometheus–1.2.1.linux–amd64 |
Now you can configure it . Prometheus collects metrics from monitored targets by scraping metrics HTTP endpoints on these targets. All the definitions goes to a file prometheus.yml . Sample configuration is below
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# my global config
global:
scrape_interval: 15s # By default, scrape targets every 15 seconds.
evaluation_interval: 15s # By default, scrape targets every 15 seconds.
# scrape_timeout is set to the global default (10s).
# Attach these labels to any time series or alerts when communicating with
# external systems (federation, remote storage, Alertmanager).
external_labels:
monitor: ‘codelab-monitor’
# Load and evaluate rules in this file every ‘evaluation_interval’ seconds.
rule_files:
# – “first.rules”
# – “second.rules”
# A scrape configuration containing exactly one endpoint to scrape:
# Here it’s Prometheus itself.
scrape_configs:
# The job name is added as a label job= to any timeseries scraped from this config.
– job_name: ‘myfirstlinuxhost’
# Override the global default and scrape targets from this job every 5 seconds.
scrape_interval: 5s
# metrics_path defaults to ‘/metrics’
# scheme defaults to ‘http’.
static_configs:
– targets: [‘localhost:9100’]
|
In prometheus.yml file, under scrape_configs you can see the hosts from which prometheus pull the metrics. For now, we have added localhost
You can start prometheus using following command
1 2 3 | ./prometheus |
You can run it on screen or background. If there are no errors, you should be able to access the prometheus web interface at
1 | http://hostipaddress:9090/ |
Now we will download “Node exporter”, which is used to collect the system metrics
1 2 3 4 5 | wget https://github.com/prometheus/node_exporter/releases/download/0.12.0/node_exporter-0.12.0.linux-amd64.tar.gz tar –xzf node_exporter–0.12.0.linux–amd64.tar.gz cd node_exporter–0.12.0.linux–amd64 |
You can start it using
1 | ./node_exporter |
It will start listening on default port 9100, you can change it if needed. Also, you can see various startup options using
1 | ./node_exporter —help |
Prometheus server will pull data from nodeexporter running on port 9100 .
You can go back to Prometheus web interface and see the metrics pulled from nodeexporter
I have created a youtube video here with complete installation steps
Please try it out and feel free to contact me if you face any issue.