Merge pull request #27 from corvus-migratorius/add-ipmi-exporter

Add ipmi exporter
This commit is contained in:
Fogucoco
2025-12-12 17:17:16 +03:00
committed by GitHub
15 changed files with 294 additions and 1 deletions

View File

@@ -8,6 +8,7 @@
- [alertmanager](roles/alertmanager/README.md)
- [dnsmasq](roles/dnsmasq/README.md)
- [grafana](roles/grafana/README.md)
- [ipmi_exporter](roles/ipmi_exporter/README.md)
- [mount_device](roles/mount_device/README.md)
- [prometheus](roles/prometheus/README.md)
- [ufw](roles/ufw/README.md)

View File

@@ -1,7 +1,7 @@
---
namespace: genlab
name: common
version: 0.8.0
version: 0.9.0
readme: README.md
authors:
- Alexander Gorelyshev (corvus-migratorius@proton.me)

View File

@@ -0,0 +1,61 @@
genlab.ipmi_exporter
=========
This Ansible role installs ipmi_exporter on target host. This is a Prometheus exporter for Intelligent Platform Management Interface [metrics](https://github.com/prometheus-community/ipmi_exporter/blob/master/docs/metrics.md)
Requirements
------------
By default, the exporter relies on tools from the FreeIPMI suite for the actual IPMI implementation.
Role Variables
--------------
Configuration files must have names ```web_conf.yaml``` and ```ipmi_local.conf```. If ipmi_exp_source_dir is specified, the role searches for ```web_conf.yaml``` and ```ipmi_local.conf``` in that directory and copy to target host in ```ipmi_exp_config_dir```. If the source directory is not specified, the role skips this step. In ipmi_local.conf user can describe what modules to use for metric collection.
ipmi_up{collector="<NAME>"} is 1 if the data for this collector could successfully be retrieved from the remote host, 0 otherwise. The following collectors are available and can be enabled or disabled in the config:
- ipmi: collects IPMI sensor data. If it fails, sensor metrics (see below) will not be available
- dcmi: collects DCMI data, currently only power consumption. If it fails, power consumption metrics (see below) will not be available
- bmc: collects BMC details. If it fails, BMC info metrics (see below) will not be available
- bmc-watchdog: collects status of the watchdog. If it fails, BMC watchdog metrics (see below) will not be available
- chassis: collects the current chassis power state (on/off). If it fails, the chassis power state metric (see below) will not be available
- sel: collects system event log (SEL) details. If it fails, SEL metrics (see below) will not be available
- sel-events: collects metrics for user-defined events in system event log (SEL). If it fails, SEL entries metrics (see below) will not be available
- sm-lan-mode: collects the "LAN mode" setting in the current BMC config. If it fails, the LAN mode metric (see below) will not be available
```yaml
ipmi_exp_version: 1.10.1
ipmi_exp_dir: "/etc/exporters"
ipmi_exp_config_dir: "/etc/exporters/config"
ipmi_exp_args: "" # --[no-]native-ipmi Use native IPMI implementation instead of FreeIPMI (EXPERIMENTAL)
# --[no-]web.systemd-socket Use systemd socket activation listeners instead of port listeners (Linux only).
ipmi_exp_log_level: "info" # Only log messages with the given severity or above. One of: [debug, info, warn, error]
ipmi_exp_log_format: "logfmt" # Output format of log messages. One of: [logfmt, json]
ipmi_exp_web_listen_address: "localhost:9290" # Addresses on which to expose metrics and web interface. Repeatable for multiple addresses. Examples: `:9100` or `[::1]:9100` for http, vsock://:9100` for vsock
ipmi_exp_source_dir: ipmi_local.conf # Path to configuration file. See: https://github.com/prometheus-community/ipmi_exporter/blob/master/docs/configuration.md
ipmi_exp_web_source_dir: web_conf.yaml # Path to configuration file that can enable TLS or authentication. See: https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md
```
Dependencies
------------
None
Example Playbook
----------------
```yaml
roles:
- role: genlab.ipmi_exporter
ipmi_exp_version: "1.10.1"
ipmi_exp_source_dir: "molecule/default/"
```
License
-------
BSD
Author Information
------------------
corvus-migratorius@proton.me

View File

@@ -0,0 +1,8 @@
---
ipmi_exporter_version: 1.10.1
ipmi_exporter_dir: "/etc/exporters"
ipmi_exporter_config_dir: "/etc/exporters/config"
ipmi_exporter_log_level: "info"
ipmi_exporter_log_format: "logfmt"
ipmi_exporter_web_listen_address: "localhost:9290"
ipmi_exporter_args: ""

View File

@@ -0,0 +1,7 @@
---
- name: "(Re)start and enable ipmi_exporter"
ansible.builtin.systemd_service:
name: ipmi_exporter.service
state: restarted
enabled: true
daemon_reload: true

View File

@@ -0,0 +1,17 @@
---
galaxy_info:
role_name: "ipmi_exporter"
namespace: genlab
author: "Alexander Gorelyshev"
company: "Genlab, LLC"
description: ""
license: "MIT"
min_ansible_version: "2.1"
platforms:
- name: "Ubuntu"
versions: ["focal", "jammy", "noble"]
galaxy_tags: []
dependencies: []

View File

@@ -0,0 +1,6 @@
---
- name: Converge
hosts: all
roles:
- role: genlab.common.ipmi_exporter
ipmi_exp_source_dir: "molecule/default/"

View File

@@ -0,0 +1,12 @@
modules:
default:
# Available collectors are bmc, bmc-watchdog, ipmi, chassis, dcmi, sel, sel-events and sm-lan-mode
collectors:
- bmc
- bmc-watchdog
- ipmi
- dcmi
- chassis
- sel
- sel-events
- sm-lan-mode

View File

@@ -0,0 +1,27 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: ubuntu
image: geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2404}-ansible:latest
pre_build_image: true
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: true
provisioner:
name: ansible
verifier:
name: ansible
lint: |
set -e
yamllint .
ansible-lint .

View File

@@ -0,0 +1,37 @@
---
- name: Verify
hosts: all
gather_facts: false
any_errors_fatal: true
tasks:
- name: "Include default vars"
ansible.builtin.include_vars:
dir: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/defaults/"
extensions: ['yml']
- name: "Check if ipmi_exporter is installed"
changed_when: false
ansible.builtin.command: "ipmi_exporter --version"
register: ipmi_exporter_installed_version
- name: "Check ipmi_exporter version"
ansible.builtin.assert:
that: "ipmi_exporter_installed_version.stdout is regex('{{ ipmi_exporter_version }}')"
success_msg: "ipmi_exporter version {{ ipmi_exporter_version }} is installed and working"
fail_msg: "ipmi_exporter version {{ ipmi_exporter_version }} is not installed or not working correctly"
# kics-scan ignore-block
- name: Check if /metrics endpoint is reachable
ansible.builtin.uri:
url: "http://{{ ipmi_exporter_web_listen_address }}/metrics"
return_content: true
status_code: 200
timeout: 60
register: ipmi_exporter_metrics_check
- name: "Fail if /metrics doesn't contain ipmi_exporter_build_info line"
ansible.builtin.assert:
that: "'ipmi_exporter_build_info' in ipmi_exporter_metrics_check.content"
fail_msg: "ipmi_exporter /metrics endpoint doesn't contain ipmi_exporter_build_info line!"
success_msg: "ipmi_exporter /metrics endpoint contains ipmi_exporter_build_info line!"

View File

@@ -0,0 +1,20 @@
---
- name: "Upload ipmi_exporter local configure file"
notify: "(Re)start and enable ipmi_exporter"
when: ipmi_exp_source_dir is defined and ipmi_exp_source_dir | length > 0
ansible.builtin.template:
src: "{{ ipmi_exp_source_dir }}/ipmi_local.conf"
dest: "{{ ipmi_exporter_config_dir }}/ipmi_local.conf"
owner: root
group: root
mode: '0640'
- name: "Upload ipmi_exporter web configure file"
notify: "(Re)start and enable ipmi_exporter"
when: ipmi_exp_web_source_dir is defined and ipmi_exp_web_source_dir | length > 0
ansible.builtin.template:
src: "{{ ipmi_exp_web_source_dir }}/web_conf.yaml"
dest: "{{ ipmi_exporter_config_dir }}/web_conf.yaml"
owner: root
group: root
mode: '0640'

View File

@@ -0,0 +1,51 @@
---
- name: "Install ipmi_exporter from binary"
block:
- name: "Check ipmi_exporter version"
changed_when: false
ansible.builtin.command:
cmd: "ipmi_exporter --version"
register: ipmi_exporter_ver
- name: "Assert version correctness"
ansible.builtin.assert:
that: "ipmi_exporter_ver.stdout is regex('{{ ipmi_exporter_version }}')"
success_msg: "ipmi_exporter version {{ ipmi_exporter_version }} is installed and working"
fail_msg: "ipmi_exporter version {{ ipmi_exporter_version }} is not installed or not working correctly"
rescue:
- name: "Create ipmi_exporter directories"
ansible.builtin.file:
path: "{{ item }}"
state: directory
owner: root
group: root
mode: "0755"
with_items:
- "{{ ipmi_exporter_dir }}"
- "{{ ipmi_exporter_config_dir }}"
- name: "Unarchive ipmi_exporter tar file"
notify: "(Re)start and enable ipmi_exporter"
ansible.builtin.unarchive:
src: "https://github.com/prometheus-community/ipmi_exporter/releases/\
download/v{{ ipmi_exporter_version }}/ipmi_exporter-{{ ipmi_exporter_version }}.linux-amd64.tar.gz"
dest: "{{ ipmi_exporter_dir }}"
remote_src: true
- name: "Move ipmi_exporter binary"
ansible.builtin.copy:
src: "{{ ipmi_exporter_dir }}/ipmi_exporter-{{ ipmi_exporter_version }}.linux-amd64/ipmi_exporter"
dest: "/usr/local/bin/ipmi_exporter"
mode: "0755"
owner: root
group: root
remote_src: true
- name: Create systemd service file
ansible.builtin.template:
src: ipmi_exporter.service.j2
dest: /etc/systemd/system/ipmi_exporter.service
owner: root
group: root
mode: '0644'

View File

@@ -0,0 +1,7 @@
---
- name: "Include installation tasks"
ansible.builtin.include_tasks: "install.yml"
- name: "Including configuration tasks"
ansible.builtin.include_tasks: "configure.yml"

View File

@@ -0,0 +1,38 @@
[Unit]
Description=IPMI exporter
Documentation=https://github.com/prometheus-community/ipmi_exporter
After=network.target
StartLimitIntervalSec=120
StartLimitBurst=5
[Service]
Type=simple
ExecStart=/usr/local/bin/ipmi_exporter \
--web.listen-address={{ ipmi_exporter_web_listen_address }} \
--log.level={{ ipmi_exporter_log_level }} \
--log.format={{ ipmi_exporter_log_format }} \
{% if ipmi_exporter_args is defined and ipmi_exporter_args | length > 0 %}
{{ ipmi_exporter_args }} \
{% endif %}
{% if ipmi_exporter_source_dir is defined and ipmi_exporter_source_dir | length > 0 %}
--config.file={{ ipmi_exporter_config_dir }}/ipmi_local.conf \
{% endif %}
{% if ipmi_exporter_web_source_dir is defined and ipmi_exporter_web_source_dir | length > 0 %}
--web.config.file={{ ipmi_exporter_config_dir }}/web_conf.yaml
{% endif %}
SyslogIdentifier=ipmi_exporter
Restart=on-failure
RestartSec=5
ProtectHome=yes
NoNewPrivileges=yes
ProtectSystem=strict
ProtectControlGroups=true
ProtectKernelModules=true
ProtectKernelTunables=yes
PrivateTmp=true
ProtectSystem=full
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1 @@
---