Skip to content

Instantly share code, notes, and snippets.

@SyaibanAhmadRamadhan
Created September 16, 2023 05:33
Show Gist options
  • Save SyaibanAhmadRamadhan/d8f5374eb438f9c13090952a239890fe to your computer and use it in GitHub Desktop.
Save SyaibanAhmadRamadhan/d8f5374eb438f9c13090952a239890fe to your computer and use it in GitHub Desktop.
monitoring-stack
version: '3'
services:
cadvisor:
image: gcr.io/cadvisor/cadvisor
container_name: monitoring_cadvisor
volumes:
- /:/rootfs:ro
- /var/run:/var/run:rw
- /sys:/sys:ro
- /var/lib/docker/:/var/lib/docker:ro
ports:
- 8080:8080
restart: always
networks:
- network-monitor
networks:
network-monitor:
external: true
[Unit]
Description=Node Exporter
[Service]
User=prometheus
Group=prometheus
Restart=always
ExecStart=/usr/local/bin/node_exporter
ExexReload=/bin/kill -HUP $MAINPID
TimeoutStopSec=20s
SendSIGKILL=no
[Install]
WantedBy=multi-user.target
[Unit]
Description=Prometheus exporter for Postgresql
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
WorkingDirectory=/etc/postgres-exporter
EnvironmentFile=/etc/postgres-exporter/postgres_exporter.env
ExecStart=/usr/local/bin/postgres_exporter
Restart=always
[Install]
WantedBy=multi-user.target
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/docs/introduction/overview/
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
[Install]
WantedBy=multi-user.target
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_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
- job_name: "node-exporter"
static_configs:
- targets: ["localhost:9100"]
- job_name: 'postgres-exporter'
scrape_interval: 5s
static_configs:
- targets: ['localhost:9187']
- job_name: 'cadvisor'
scrape_interval: 5s
static_configs:
- targets: ['localhost:8080']
# nodeexporter
sudo mv node_exporter /usr/local/bin/
sudo nano /etc/systemd/system/node-exporter.serviceq
# pg exporter
sudo mkdir /etc/postgres-exporter
sudo nano /etc/postgres-exporter/postgres_exporter.env
DATA_SOURCE_NAME=”postgresql://user:pw@ip:port/db?sslmode=disable”
sudo nano /etc/systemd/system/postgres-exporter.service
# prometheus
sudo groupadd --system prometheus
sudo useradd --system -s /sbin/nologin -g prometheus prometheus
sudo mv prometheus promtool /usr/local/bin/
sudo mkdir /etc/prometheus
sudo mkdir /var/lib/prometheus
sudo chown prometheus:prometheus /var/lib/prometheus/
sudo mv consoles/ console_libraries/ prometheus.yml /etc/prometheus/
sudo nano /etc/systemd/system/prometheus.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment