configure prometheus for ubiquiti and proxmox cluster

This commit is contained in:
2026-05-08 00:25:55 -05:00
parent f8c6b327f9
commit 84523d0054
6 changed files with 637 additions and 378 deletions

View File

@@ -95,6 +95,8 @@
- "{{ monitoring_base_dir }}/prometheus"
- "{{ monitoring_base_dir }}/grafana"
- "{{ monitoring_base_dir }}/alertmanager"
- "{{ monitoring_base_dir }}/pve-exporter"
- "{{ monitoring_base_dir }}/snmp-exporter"
# ── Config files ───────────────────────────────────────────────────────────────
@@ -125,6 +127,56 @@
mode: "0644"
notify: restart monitoring
- name: Deploy PVE exporter credentials file
ansible.builtin.template:
src: pve.yml.j2
dest: "{{ monitoring_base_dir }}/pve-exporter/pve.yml"
owner: "{{ ansible_user }}"
group: docker
mode: "0644"
no_log: true
notify: restart monitoring
# ── SNMP exporter config ───────────────────────────────────────────────────────
# Extract the default snmp.yml from the image (contains full if_mib metrics
# mapping) then inject the mk-labs community auth into the auths section.
- name: Extract default snmp.yml from snmp-exporter image
ansible.builtin.shell:
cmd: >
docker run --rm --entrypoint cat prom/snmp-exporter:latest
/etc/snmp_exporter/snmp.yml
> {{ monitoring_base_dir }}/snmp-exporter/snmp.yml
changed_when: true
- name: Inject mk_labs_v2c auth into snmp.yml
ansible.builtin.shell:
cmd: |
python3 - << 'EOF'
path = '{{ monitoring_base_dir }}/snmp-exporter/snmp.yml'
with open(path, 'r') as f:
content = f.read()
auth = (
' mk_labs_v2c:\n'
' community: {{ vault_snmp_community }}\n'
' security_level: noAuthNoPriv\n'
' auth_protocol: MD5\n'
' priv_protocol: DES\n'
' version: 2\n'
)
if 'mk_labs_v2c' not in content:
content = content.replace('\nmodules:\n', '\n' + auth + 'modules:\n', 1)
with open(path, 'w') as f:
f.write(content)
print('injected')
else:
print('already present')
EOF
register: snmp_inject
changed_when: "'injected' in snmp_inject.stdout"
no_log: true
notify: restart monitoring
# ── Compose stack ──────────────────────────────────────────────────────────────
- name: Deploy monitoring compose file from boilerplate
@@ -149,4 +201,3 @@
community.docker.docker_compose_v2:
project_src: "{{ monitoring_base_dir }}"
state: present

View File

@@ -8,4 +8,4 @@ GRAFANA_ADMIN_USER={{ grafana_admin_user }}
GRAFANA_ADMIN_PASSWORD={{ grafana_admin_password }}
PROMETHEUS_RETENTION_TIME={{ prometheus_retention_time }}
PROMETHEUS_RETENTION_SIZE={{ prometheus_retention_size }}
TRUSTED_PROXIES={{ trusted_proxy_ip }}
TRUSTED_PROXIES={{ trusted_proxy_ip }}

View File

@@ -1,11 +1,11 @@
# ------------------------------------------------------------------------------
# FILE: roles/monitoring/templates/prometheus.yml.j2
# FILE: ansible/playbooks/roles/monitoring/templates/prometheus.yaml.j2
# DESCRIPTION: Prometheus scrape configuration
# ------------------------------------------------------------------------------
global:
scrape_interval: {{ prometheus_scrape_interval }}
evaluation_interval: {{ prometheus_scrape_interval }}
scrape_interval: 30s
evaluation_interval: 30s
alerting:
alertmanagers:
@@ -27,11 +27,11 @@ scrape_configs:
- job_name: node-cinderella-castle
static_configs:
- targets:
- cinderella-castle:9100
- 10.1.71.31:9100
labels:
hostname: cinderella-castle
# Proxmox nodes
# Proxmox nodes (node exporter on each hypervisor)
- job_name: proxmox-nodes
static_configs:
- targets:
@@ -48,3 +48,158 @@ scrape_configs:
- 10.1.71.35:8080
labels:
hostname: lightning-lane
# --------------------------------------------------------------------------
# Proxmox VE Exporter — cluster-level metrics (VM states, storage, CPU)
# Uses the multi-target pattern: Prometheus passes the cluster address as a
# query parameter to the exporter, which proxies to the Proxmox API.
# One scrape job covers all three nodes via the cluster API endpoint.
# --------------------------------------------------------------------------
- job_name: proxmox-cluster
metrics_path: /pve
params:
module: [default]
cluster: ["1"]
node: [""]
static_configs:
- targets:
- 10.1.71.11 # main-street-usa — cluster API endpoint
labels:
cluster: magic-kingdom
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: pve-exporter:9221
# --------------------------------------------------------------------------
# Pure Storage FlashArray -- utilidor (DEFERRED until Purity 6.7+)
#
# When utilidor is upgraded to Purity 6.7+, uncomment this job and remove
# the legacy exporter container. No container needed -- Prometheus scrapes
# the native OpenMetrics endpoint on the array directly over HTTPS.
#
# Also add vault_pure_utilidor_api_token to group_vars/all/vault and create
# a read-only API token on utilidor under System -> Users -> API Tokens.
# --------------------------------------------------------------------------
# - job_name: pure-flasharray-utilidor
# metrics_path: /metrics/array
# scheme: https
# tls_config:
# insecure_skip_verify: true
# authorization:
# credentials: {{ vault_pure_utilidor_api_token }}
# params:
# namespace: ["purefa"]
# static_configs:
# - targets:
# - utilidor.local.mk-labs.cloud
# labels:
# array: utilidor
# array_type: physical
# --------------------------------------------------------------------------
# UniFi Network — SNMP scrape jobs (one per device for clean Grafana filtering)
# All targets use the if_mib module for interface throughput, errors, and
# up/down state. Auth uses the mk_labs_v2c community string from vault.
# --------------------------------------------------------------------------
- job_name: snmp-udm-pro
metrics_path: /snmp
params:
auth: [mk_labs_v2c]
module: [if_mib]
static_configs:
- targets:
- 192.168.1.1
labels:
device: world-drive
model: UDM-Pro
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 10.1.71.31:9116
- job_name: snmp-usw-pro-aggregation
metrics_path: /snmp
params:
auth: [mk_labs_v2c]
module: [if_mib]
static_configs:
- targets:
- 192.168.1.123
labels:
device: usw-pro-aggregation
model: USW-Pro-Aggregation
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 10.1.71.31:9116
- job_name: snmp-usw-pro-max-24
metrics_path: /snmp
scrape_interval: 60s
scrape_timeout: 55s
params:
auth: [mk_labs_v2c]
module: [if_mib]
static_configs:
- targets:
- 192.168.1.226
labels:
device: usw-pro-max-24
model: USW-Pro-Max-24
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 10.1.71.31:9116
- job_name: snmp-usw-lite-16-poe
metrics_path: /snmp
params:
auth: [mk_labs_v2c]
module: [if_mib]
static_configs:
- targets:
- 192.168.1.136
labels:
device: usw-lite-16-poe
model: USW-Lite-16-PoE
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 10.1.71.31:9116
- job_name: snmp-ups-tower
metrics_path: /snmp
params:
auth: [mk_labs_v2c]
module: [if_mib]
static_configs:
- targets:
- 192.168.1.233
labels:
device: ups-tower
model: UPS-Tower
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 10.1.71.31:9116

View File

@@ -0,0 +1,11 @@
# ------------------------------------------------------------------------------
# FILE: ansible/playbooks/roles/monitoring/templates/pve.yml.j2
# DESCRIPTION: Proxmox VE Exporter credentials file.
# Mounted read-only into the pve-exporter container.
# ------------------------------------------------------------------------------
default:
user: prometheus@pve
token_name: prometheus-token
token_value: {{ vault_proxmox_prometheus_token }}
verify_ssl: false