DevOps Tools/Prometheus

From r00tedvw.com wiki
(Difference between revisions)
Jump to: navigation, search
 
(10 intermediate revisions by one user not shown)
Line 1: Line 1:
[[ DevOps_Tools/Monitoring | Overview ]] | [[ DevOps_Tools/Prometheus | Prometheus ]]
+
[[ DevOps_Tools/Monitoring | Overview ]] | [[ DevOps_Tools/Prometheus | Prometheus Server ]] | [[ DevOps_Tools/Prometheus/Exporter | Prometheus Node Exporter ]]
 +
=Overview=
 +
Metric Collector manager.  Uses a scrape method by default, so the prometheus server needs to have connectivity to each node exporter.
  
 
=CentOS 7 Installation=
 
=CentOS 7 Installation=
 
==Create dependencies==
 
==Create dependencies==
  <nowiki>~$ sudo yum install -y wget
+
  <nowiki>~$ sudo yum install -y wget curl
 
~$ sudo groupadd --system prometheus
 
~$ sudo groupadd --system prometheus
 
~$ sudo useradd -s /sbin/nologin --system -g prometheus prometheus
 
~$ sudo useradd -s /sbin/nologin --system -g prometheus prometheus
Line 23: Line 25:
 
  <nowiki>~$ sudo vim /etc/prometheus/prometheus.yml</nowiki>
 
  <nowiki>~$ sudo vim /etc/prometheus/prometheus.yml</nowiki>
 
<div class="mw-collapsible mw-collapsed">
 
<div class="mw-collapsible mw-collapsed">
This text is not collapsible; but the next is collapsible and hidden by default:
+
prometheus config
<div class="mw-collapsible-content">{{Lorem}}</div>
+
<div class="mw-collapsible-content">
 +
<nowiki># my global config
 +
global:
 +
  scrape_interval:    15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
 +
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
 +
  # scrape_timeout is set to the global default (10s).
 +
 
 +
# Alertmanager configuration
 +
alerting:
 +
  alertmanagers:
 +
  - static_configs:
 +
    - targets:
 +
      # - alertmanager:9093
 +
 
 +
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
 +
rule_files:
 +
  # - "first_rules.yml"
 +
  # - "second_rules.yml"
 +
 
 +
# 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=<job_name>` to any timeseries scraped from this config.
 +
  - job_name: 'prometheus'
 +
 
 +
    # metrics_path defaults to '/metrics'
 +
    # scheme defaults to 'http'.
 +
 
 +
    static_configs:
 +
    - targets: ['localhost:9090']</nowiki>
 
</div>
 
</div>
 +
</div>
 +
 +
==Setup permissions==
 +
<nowiki>~$ for i in rules rules.d files_sd; do sudo chown -R prometheus:prometheus /etc/prometheus/${i}; done
 +
~$ for i in rules rules.d files_sd; do sudo chmod -R 775 /etc/prometheus/${i}; done
 +
~$ sudo chown -R prometheus:prometheus /var/lib/prometheus/ </nowiki>
 +
 +
==Setup Firewall rules==
 +
<nowiki>~$ sudo firewall-cmd --zone=public --permanent --add-port=9090/tcp
 +
~$ sudo firewall-cmd --reload</nowiki>
 +
 +
==Create systemd service==
 +
<nowiki>~$ sudo vim /etc/systemd/system/prometheus.service</nowiki>
 +
<div class="mw-collapsible mw-collapsed">
 +
systemd service
 +
<div class="mw-collapsible-content">
 +
<nowiki>[Unit]
 +
Description=Prometheus
 +
Documentation=https://prometheus.io/docs/introduction/overview/
 +
Wants=network-online.target
 +
After=network-online.target
 +
 +
[Service]
 +
Type=simple
 +
User=prometheus
 +
Group=prometheus
 +
ExecReload=/bin/kill -HUP $MAINPID
 +
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 \
 +
  --web.listen-address=0.0.0.0:9090 \
 +
  --web.external-url=
 +
 +
SyslogIdentifier=prometheus
 +
Restart=always
 +
 +
[Install]
 +
WantedBy=multi-user.target</nowiki>
 +
</div>
 +
</div>
 +
 +
<nowiki>~$ sudo systemctl daemon-reload
 +
~$ sudo systemctl start prometheus
 +
~$ sudo systemctl enable prometheus</nowiki>
 +
 +
==Test==
 +
Test connection to the server running Prometheus on port 9090

Latest revision as of 02:44, 7 September 2022

Overview | Prometheus Server | Prometheus Node Exporter

Contents

[edit] Overview

Metric Collector manager. Uses a scrape method by default, so the prometheus server needs to have connectivity to each node exporter.

[edit] CentOS 7 Installation

[edit] Create dependencies

~$ sudo yum install -y wget curl
~$ sudo groupadd --system prometheus
~$ sudo useradd -s /sbin/nologin --system -g prometheus prometheus
~$ sudo mkdir /var/lib/prometheus
~$ for i in rules rules.d files_sd; do sudo mkdir -p /etc/prometheus/${i}; done
~$ mkdir -p /tmp/prometheus && cd /tmp/prometheus

[edit] Download and setup

~$ curl -s https://api.github.com/repos/prometheus/prometheus/releases/latest | grep browser_download_url | grep linux-amd64 | cut -d '"' -f 4 | wget -qi -
~$ tar xvf prometheus*.tar.gz
~$ cd prometheus*/
~$ sudo mv prometheus promtool /usr/local/bin/
~$ sudo mv prometheus.yml  /etc/prometheus/prometheus.yml
~$ sudo mv consoles/ console_libraries/ /etc/prometheus/
~$ cd ~/
~$ rm -rf /tmp/prometheus

[edit] Create config

~$ sudo vim /etc/prometheus/prometheus.yml

prometheus config

# my global config
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# 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=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
    - targets: ['localhost:9090']

[edit] Setup permissions

~$ for i in rules rules.d files_sd; do sudo chown -R prometheus:prometheus /etc/prometheus/${i}; done
~$ for i in rules rules.d files_sd; do sudo chmod -R 775 /etc/prometheus/${i}; done
~$ sudo chown -R prometheus:prometheus /var/lib/prometheus/ 

[edit] Setup Firewall rules

~$ sudo firewall-cmd --zone=public --permanent --add-port=9090/tcp 
~$ sudo firewall-cmd --reload

[edit] Create systemd service

~$ sudo vim /etc/systemd/system/prometheus.service

systemd service

[Unit]
Description=Prometheus
Documentation=https://prometheus.io/docs/introduction/overview/
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=prometheus
Group=prometheus
ExecReload=/bin/kill -HUP $MAINPID
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 \
  --web.listen-address=0.0.0.0:9090 \
  --web.external-url=

SyslogIdentifier=prometheus
Restart=always

[Install]
WantedBy=multi-user.target
~$ sudo systemctl daemon-reload
~$ sudo systemctl start prometheus
~$ sudo systemctl enable prometheus

[edit] Test

Test connection to the server running Prometheus on port 9090

Personal tools
Namespaces

Variants
Actions
Navigation
Mediawiki
Confluence
DevOps Tools
Open Source Products
Ubuntu
Ubuntu 22
Mac OSX
Oracle Linux
AWS
Windows
OpenVPN
Grafana
InfluxDB2
TrueNas
MagicMirror
OwnCloud
Pivotal
osTicket
OTRS
phpBB
WordPress
VmWare ESXI 5.1
Crypto currencies
HTML
CSS
Python
Java Script
PHP
Raspberry Pi
Canvas LMS
Kaltura Media Server
Plex Media Server
MetaSploit
Zoneminder
ShinobiCE
Photoshop CS2
Fortinet
Uploaded
Certifications
General Info
Games
Meal Plans
NC Statutes
2020 Election
Volkswagen
Covid
NCDMV
Toolbox