Add support for NUT (EATON inverter)
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
# nut_exporter — Prometheus exporter for NUT
|
||||
|
||||
Scrapes a local `upsd` and exposes UPS metrics for Prometheus.
|
||||
|
||||
## Supported distributions
|
||||
|
||||
- Arch Linux (AUR package `prometheus-nut-exporter`, installed via `paru`)
|
||||
|
||||
Debian/Ubuntu is not packaged upstream — add it on demand.
|
||||
|
||||
## Configuration
|
||||
|
||||
See [defaults/main.yml](defaults/main.yml).
|
||||
|
||||
Required:
|
||||
|
||||
```yaml
|
||||
nut_exporter_nut_password: "<same as nut_monitor_password>"
|
||||
```
|
||||
|
||||
Optional:
|
||||
|
||||
```yaml
|
||||
nut_exporter_listen_address: "127.0.0.1:9199"
|
||||
nut_exporter_nut_server: "127.0.0.1:3493"
|
||||
nut_exporter_nut_user: monitor
|
||||
```
|
||||
|
||||
## Pairing with Prometheus
|
||||
|
||||
Typical scrape config (target uses the multi-target pattern: the exporter
|
||||
queries a remote upsd specified in the URL parameters):
|
||||
|
||||
```yaml
|
||||
prometheus_scrape_configs:
|
||||
- job_name: 'nut'
|
||||
metrics_path: /nut
|
||||
static_configs:
|
||||
- targets: ['eaton@localhost'] # ups@host syntax
|
||||
relabel_configs:
|
||||
- source_labels: [__address__]
|
||||
target_label: __param_target
|
||||
- source_labels: [__param_target]
|
||||
target_label: instance
|
||||
- target_label: __address__
|
||||
replacement: 127.0.0.1:9199
|
||||
```
|
||||
|
||||
## Operations
|
||||
|
||||
```bash
|
||||
systemctl status prometheus-nut-exporter
|
||||
curl -s 'http://127.0.0.1:9199/nut?target=localhost&ups=eaton' | head
|
||||
journalctl -u prometheus-nut-exporter -f
|
||||
```
|
||||
|
||||
## Dependencies
|
||||
|
||||
Requires the [`nut`](../nut/README.md) role (or any other running upsd) on the
|
||||
same host.
|
||||
@@ -0,0 +1,13 @@
|
||||
---
|
||||
# Prometheus NUT exporter configuration
|
||||
|
||||
# Address the exporter listens on.
|
||||
nut_exporter_listen_address: "127.0.0.1:9199"
|
||||
|
||||
# upsd server to connect to (kept local — exporter sits next to upsd).
|
||||
nut_exporter_nut_server: "127.0.0.1:3493"
|
||||
|
||||
# Credentials used to log into upsd. These should match the upsd user defined
|
||||
# by the nut role (nut_monitor_user / nut_monitor_password).
|
||||
nut_exporter_nut_user: "{{ nut_monitor_user | default('monitor') }}"
|
||||
# nut_exporter_nut_password: "" # Inherits nut_monitor_password by default
|
||||
@@ -0,0 +1,9 @@
|
||||
---
|
||||
- name: Reload systemd
|
||||
ansible.builtin.systemd:
|
||||
daemon_reload: true
|
||||
|
||||
- name: Restart nut_exporter
|
||||
ansible.builtin.systemd:
|
||||
name: "{{ nut_exporter_service }}"
|
||||
state: restarted
|
||||
@@ -0,0 +1,2 @@
|
||||
---
|
||||
dependencies: []
|
||||
@@ -0,0 +1,46 @@
|
||||
---
|
||||
- name: Validate required configuration
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- nut_exporter_nut_password is defined
|
||||
- nut_exporter_nut_password | length >= 12
|
||||
fail_msg: |
|
||||
nut_exporter_nut_password (>=12 chars) is required.
|
||||
Usually set to the same value as nut_monitor_password.
|
||||
|
||||
- name: Load OS-specific variables
|
||||
ansible.builtin.include_vars: "{{ item }}"
|
||||
with_first_found:
|
||||
- "{{ ansible_facts['os_family'] }}.yml"
|
||||
|
||||
- name: Install prometheus-nut-exporter (AUR via paru)
|
||||
ansible.builtin.command: "paru -S --noconfirm --needed {{ nut_exporter_package }}"
|
||||
register: nut_exporter_install
|
||||
changed_when: "'there is nothing to do' not in nut_exporter_install.stdout | lower"
|
||||
when: ansible_facts['os_family'] == 'Archlinux'
|
||||
|
||||
- name: Ensure systemd override directory exists
|
||||
ansible.builtin.file:
|
||||
path: "{{ nut_exporter_override_dir }}"
|
||||
state: directory
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0755"
|
||||
|
||||
- name: Deploy systemd override (listen address + upsd credentials)
|
||||
ansible.builtin.template:
|
||||
src: override.conf.j2
|
||||
dest: "{{ nut_exporter_override_dir }}/override.conf"
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0640"
|
||||
notify:
|
||||
- Reload systemd
|
||||
- Restart nut_exporter
|
||||
|
||||
- name: Enable and start nut_exporter
|
||||
ansible.builtin.systemd:
|
||||
name: "{{ nut_exporter_service }}"
|
||||
enabled: true
|
||||
state: started
|
||||
daemon_reload: true
|
||||
@@ -0,0 +1,10 @@
|
||||
# Managed by Ansible - DO NOT EDIT MANUALLY
|
||||
# Override for prometheus-nut-exporter to inject listen address and upsd
|
||||
# credentials. The exporter reads NUT_EXPORTER_* env vars at startup.
|
||||
|
||||
[Service]
|
||||
Environment="HTTP_LISTEN_ADDRESS={{ nut_exporter_listen_address }}"
|
||||
Environment="NUT_EXPORTER_SERVER={{ nut_exporter_nut_server.split(':')[0] }}"
|
||||
Environment="NUT_EXPORTER_PORT={{ nut_exporter_nut_server.split(':')[1] }}"
|
||||
Environment="NUT_EXPORTER_USERNAME={{ nut_exporter_nut_user }}"
|
||||
Environment="NUT_EXPORTER_PASSWORD={{ nut_exporter_nut_password }}"
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
nut_exporter_package: prometheus-nut-exporter
|
||||
nut_exporter_service: prometheus-nut-exporter.service
|
||||
nut_exporter_user: nut-exporter
|
||||
nut_exporter_group: nut-exporter
|
||||
nut_exporter_override_dir: /etc/systemd/system/prometheus-nut-exporter.service.d
|
||||
Reference in New Issue
Block a user