Устанавливаем и настраиваем Prometheus
Установить Prometheus очень просто:
docker run --name prometheus -d \ -p 9090:9090 \ -v ./config:/etc/prometheus \ -v prometheus-data:/prometheus \ prom/prometheus
Либо docker-compose.yml:
- docker-compose.yml
services: prometheus: image: prom/prometheus:latest container_name: prometheus volumes: - prometheus-data:/prometheus - ./config/:/etc/prometheus/ ports: - 9090:9090 networks: proxy-net: restart: unless-stopped volumes: prometheus-data: networks: proxy-net: external: true
./config - это каталог с конфигурацией прометеуса, в который необходимо предварительно поместить следующий файл с заданиями для сбора метрик:
- prometheus.yml
global: scrape_interval: 15s # By default, scrape targets every 15 seconds. # Attach these labels to any time series or alerts when communicating with # external systems (federation, remote storage, Alertmanager). external_labels: monitor: 'codelab-monitor' # 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' # Override the global default and scrape targets from this job every 5 seconds. scrape_interval: 15s static_configs: - targets: ['localhost:9090'] - job_name: 'myjob' scrape_interval: 30s scheme: http metrics_path: '/metrics' static_configs: - targets: ['192.168.1.1:9100']
job_name - это имена заданий. Можно прописывать любые. По ним затем можно будет делать выборку в метриках.
После запуска прометеуса проверяем его работу, открыв в браузере страничку на 9090 порту: http://IP:9090/targets
