Prometheus VM

Tags: docker Ubuntu proxmox systemd

Where?

It runs in a 2 vCPU 2 GB RAM proxmox VM with Ubuntu 20.04. The proxmox host is an old laptop.

What?

Data manager VM for collecting prometheus data that can be ingested by the Grafana instance running in my Home Assistant instance.

How?

Original creation:

docker run --name prometheus -d -p 9090:9090 -v /home/myuser/configs:/etc/prometheus prom/prometheus --config.file=/etc/prometheus/prometheus.yml --web.config.file=/etc/prometheus/web-config.yml

The context:

~/configs$ ls
prometheus.crt  prometheus.key  prometheus.yml  web-config.yml

prometheus.yml:

global:
  scrape_interval: 15s
  evaluation_interval: 30s
  # scrape_timeout is set to the global default (10s).
scrape_configs:
  - job_name: 'airgradient-bedroom'
    metrics_path: /metrics
    scrape_interval: 30s
    static_configs:
      - targets: ['local IP of an air quality sensor:9926']
  - job_name: 'ave-frame'
    metrics_path: /metrics
    scrape_interval: 30s
    static_configs:
      - targets: ['local DNS name of my laptop:9100']
  - job_name: 'data-manager'
    metrics_path: /metrics
    scrape_interval: 30s
    static_configs:
      - targets: ['local DNS name of the data-manager VM:9100']

web-config.yml:

tls_server_config:
  cert_file: prometheus.crt
  key_file: prometheus.key

Managing persistence:

sudo vim /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus container
Requires=docker.service
After=docker.service

[Service]
Restart=always
ExecStart=/usr/bin/docker start -a prometheus
ExecStop=/usr/bin/docker stop -t 2 prometheus

[Install]
WantedBy=default.target
sudo systemctl enable prometheus