PROMETHEUS - Rone-Gleison/SRE GitHub Wiki
Configuração abaixo suporta o monitoramento de 200 servidores com histórico de +15 dias
- Ambiente criado em VM: 8vCPUS e 16G de RAM
- Adicionar um disco somente para dados e databse do prometheus, abaixo seguem especificações:
- Armazenamento = 500GB (aproximadamente, podendo variar de acordo com a necessidade);
- Criptografar com luks;
- Sistema de arquivos = xfs;
- Ponto de montagem = /var/lib/prometheus.
- Baixar o Prometheus e seus binários:
wget https://github.com/prometheus/prometheus/releases/download/VERSION/prometheus-VERSION.linux-amd64.tar.gz
- Descompactar arquivo baixado:
tar xfz prometheus-VERSION.linux-amd64.tar.gz
- prometheus: é o binario do serviço do prometheus.
- prometheus.yaml: é o arquivo de configuração do prometheus, nele realizamos todas as confirmações do serviço.
- promtool: utilitário de linha de comando, util para trobleshooting.
- consoles e consoles_libraries: Arquivos utilizados para dashboard e seleções de visualização.
PROMETHEUS.YAML
# 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"
- "disk_space.rules"
- "f2b_alerts.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=<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"]
##STATUS VM - NODE EXPORTER -----------------------------
- job_name: 'Status Linux'
scrape_interval: 7s
static_configs:
- targets: ['192.168.1.131:9100']
##MONITORAR PROCESS - OPENTELEMETRY -----------------------------
- job_name: 'Processes'
scrape_interval: 10s
static_configs:
- targets: ['192.168.1.131:9256']
##POSTGRES - POSTGRES EXPORTER
- job_name: postgres
scrape_interval: 10s
static_configs:
- targets: ['192.168.1.131:9187']
#HAPROXY - CONFIGURAÇÃO PROPRIO HAPROXY
# - job_name: haproxy
# static_configs:
# - targets: ['192.168.1.131:8404'] #HA NGS
# scheme: https
# tls_config:
# insecure_skip_verify: true
#FAIL2BAN
- job_name: fail2ban
static_configs:
- targets: ['192.168.1.131:9191']
#REDIS
- job_name: "redis"
static_configs:
- targets: ["192.168.1.131:9121"]
- Criar usuário do prometheus:
useradd --no-create-home --shell /bin/false prometheus
- Criar um diretório para inclusão dos arquivos do Prometheus:
mkdir /etc/prometheus
- Mova os arquivos baixados do Prometheus para seus devidos lugares:
mv prometheus /usr/local/bin/
mv promtool /usr/local/bin/
mv consoles /etc/prometheus
mv console_libraries /etc/prometheus
mv prometheus.yaml /etc/prometheus/prometheus.yml
- Ajuste os permissionamentos dos diretórios que possuem arquivos do Prometheus:
chown -R prometheus:prometheus /etc/prometheus
chown -R prometheus:prometheus /var/lib/prometheus
chown prometheus:prometheus /usr/local/bin/promtool
chown prometheus:prometheus /usr/local/bin/prometheus
- Criar arquivo do serviço do Prometheus:
vim /etc/systemd/system/prometheus.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= \
--enable-feature=remote-write-receiver \
--storage.tsdb.max-block-duration=10d \
--storage.tsdb.retention.size=400GB \
--storage.tsdb.wal-compression-type=zstd
SyslogIdentifier=prometheus
Restart=always
[Install]
WantedBy=multi-user.target
- Reload no daemon:
systemctl daemon-reload
- Inicialização Prometheus:
systemctl enable --now prometheus
systemctl status prometheus
Instale o agent do coletor:
Instale o agente manualmente ou via rundeck/ansible execute a playbook de instalação do servidor destino:
Acessar o arquivo prometheus.yml e adicione ao target referente ao coletor:
vim /etc/prometheus/prometheus.yml