Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions roles/nvme_exporter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<p><img src="https://www.circonus.com/wp-content/uploads/2015/03/sol-icon-itOps.png" alt="graph logo" title="graph" align="right" height="60" /></p>

# Ansible Role: NVMe exporter

## Description

Deploy prometheus [NVMe exporter](https://github.com/E4-Computer-Engineering/nvme-exporter) using ansible.

## Requirements

- gnu-tar on Mac deployer host (`brew install gnu-tar`)
- The `nvme-cli` package (version 2.3 or above) and root privileges are recommended on the target host for full functionality. The exporter still starts without them, but scrapes will fail and increment the `nvme_exporter_scrape_failures_total` metric.

## Role Variables

All variables which can be overridden are stored in [defaults/main.yml](defaults/main.yml) file as well as in [meta/argument_specs.yml](meta/argument_specs.yml).
Please refer to the [collection docs](https://prometheus-community.github.io/ansible/branch/main/nvme_exporter_role.html) for description and default values of the variables.

## Example

### Playbook

Use it in a playbook as follows:

```yaml
- hosts: all
roles:
- prometheus.prometheus.nvme_exporter
```

### Demo site

We provide an example site that demonstrates a full monitoring solution based on prometheus and grafana. The repository with code and links to running instances is [available on github](https://github.com/prometheus/demo-site) and the site is hosted on [DigitalOcean](https://digitalocean.com).

## Local Testing

The preferred way of locally testing the role is to use Docker and [molecule](https://github.com/ansible-community/molecule) (v3.x). You will have to install Docker on your system. See "Get started" for a Docker package suitable for your system. Running your tests is as simple as executing `molecule test`.

## Continuous Integration

Combining molecule and circle CI allows us to test how new PRs will behave when used with multiple ansible versions and multiple operating systems. This also allows use to create test scenarios for different role configurations. As a result we have quite a large test matrix which can take more time than local testing, so please be patient.

## Contributing

See [contributor guideline](CONTRIBUTING.md).

## Troubleshooting

See [troubleshooting](TROUBLESHOOTING.md).

## License

This project is licensed under MIT License. See [LICENSE](/LICENSE) for more details.
23 changes: 23 additions & 0 deletions roles/nvme_exporter/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
nvme_exporter_version: 3.0.0
nvme_exporter_binary_url: "https://github.com/{{ _nvme_exporter_repo }}/releases/download/v{{ nvme_exporter_version }}/\
nvme_exporter_{{ nvme_exporter_version }}_{{ ansible_facts['system'] | lower }}_{{ _nvme_exporter_go_ansible_arch }}.tar.gz"
nvme_exporter_checksums_url: "https://github.com/{{ _nvme_exporter_repo }}/releases/download/v{{ nvme_exporter_version }}/checksums.txt"

nvme_exporter_web_listen_address: "0.0.0.0:9998"
nvme_exporter_web_telemetry_path: "/metrics"

# Collector management. When nvme_exporter_disable_defaults is true only the
# collectors listed in nvme_exporter_enabled_collectors are enabled. Collectors
# in nvme_exporter_disabled_collectors are always disabled.
nvme_exporter_disable_defaults: false
nvme_exporter_enabled_collectors: []
nvme_exporter_disabled_collectors: []

nvme_exporter_binary_install_dir: "/usr/local/bin"
nvme_exporter_system_group: "nvme-exp"
nvme_exporter_system_user: "{{ nvme_exporter_system_group }}"

nvme_exporter_config_dir: "/etc/nvme_exporter"
# Local path to stash the archive and its extraction
nvme_exporter_local_cache_path: "/tmp/nvme_exporter-{{ ansible_facts['system'] | lower }}-{{ _nvme_exporter_go_ansible_arch }}/{{ nvme_exporter_version }}"
10 changes: 10 additions & 0 deletions roles/nvme_exporter/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- name: Restart nvme_exporter
listen: "restart nvme_exporter"
become: true
ansible.builtin.systemd:
daemon_reload: true
name: nvme_exporter
state: restarted
when:
- not ansible_check_mode
62 changes: 62 additions & 0 deletions roles/nvme_exporter/meta/argument_specs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
# yamllint disable rule:line-length
argument_specs:
main:
short_description: "Prometheus NVMe Exporter"
description:
- "Deploy prometheus L(NVMe exporter,https://github.com/E4-Computer-Engineering/nvme-exporter) using ansible"
author:
- "Prometheus Community"
options:
nvme_exporter_version:
description: "NVMe exporter package version. Also accepts latest as parameter."
default: "3.0.0"
nvme_exporter_binary_url:
description: "URL of the NVMe exporter binaries .tar.gz file"
default: "https://github.com/{{ _nvme_exporter_repo }}/releases/download/v{{ nvme_exporter_version }}/nvme_exporter_{{ nvme_exporter_version }}_{{ ansible_facts['system'] | lower }}_{{ _nvme_exporter_go_ansible_arch }}.tar.gz"
nvme_exporter_checksums_url:
description: "URL of the NVMe exporter checksums file"
default: "https://github.com/{{ _nvme_exporter_repo }}/releases/download/v{{ nvme_exporter_version }}/checksums.txt"
nvme_exporter_web_listen_address:
description: "Address on which NVMe exporter will listen"
default: "0.0.0.0:9998"
nvme_exporter_web_telemetry_path:
description: "Path under which to expose metrics"
default: "/metrics"
nvme_exporter_disable_defaults:
description: "Disable all default collectors. Only the collectors listed in O(nvme_exporter_enabled_collectors) will be enabled."
type: "bool"
default: false
nvme_exporter_enabled_collectors:
description:
- "List of collectors to enable explicitly (for example C(info), C(smart), C(ocp))."
- "Mostly useful in combination with O(nvme_exporter_disable_defaults)."
type: "list"
elements: "str"
default: []
nvme_exporter_disabled_collectors:
description: "List of collectors to disable explicitly (for example C(ocp))."
type: "list"
elements: "str"
default: []
nvme_exporter_binary_install_dir:
description:
- "I(Advanced)"
- "Directory to install nvme_exporter binary"
default: "/usr/local/bin"
nvme_exporter_system_group:
description:
- "I(Advanced)"
- "System group for NVMe exporter"
default: "nvme-exp"
nvme_exporter_system_user:
description:
- "I(Advanced)"
- "NVMe exporter user"
default: "nvme-exp"
nvme_exporter_local_cache_path:
description: "Local path to stash the archive and its extraction"
default: "/tmp/nvme_exporter-{{ ansible_facts['system'] | lower }}-{{ _nvme_exporter_go_ansible_arch }}/{{ nvme_exporter_version }}"
nvme_exporter_config_dir:
description: "Path to directory with nvme_exporter configuration"
default: "/etc/nvme_exporter"
27 changes: 27 additions & 0 deletions roles/nvme_exporter/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
galaxy_info:
author: "Prometheus Community"
description: "NVMe exporter"
license: "Apache"
min_ansible_version: "2.14"
platforms:
- name: "Ubuntu"
versions:
- "jammy"
- "noble"
- name: "Debian"
versions:
- "bullseye"
- "bookworm"
- name: "EL"
versions:
- "9"
- "10"
galaxy_tags:
- "monitoring"
- "prometheus"
- "exporter"
- "metrics"
- "system"
- "nvme"
- "smart"
19 changes: 19 additions & 0 deletions roles/nvme_exporter/molecule/alternative/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
provisioner:
playbooks:
prepare: "${MOLECULE_PROJECT_DIRECTORY}/../../.config/molecule/alternative/prepare.yml"
inventory:
group_vars:
all:
nvme_exporter_local_cache_path: "/tmp/nvme_exporter-linux-amd64"
nvme_exporter_web_listen_address: "127.0.0.1:8080"
nvme_exporter_web_telemetry_path: "/nvme-metrics"
nvme_exporter_disable_defaults: true
nvme_exporter_enabled_collectors:
- "info"
- "smart"
nvme_exporter_disabled_collectors:
- "ocp"
nvme_exporter_version: 2.2.0
nvme_exporter_binary_url: "https://github.com/E4-Computer-Engineering/nvme-exporter/releases/download/v{{\
\ nvme_exporter_version }}/nvme_exporter_{{ nvme_exporter_version }}_linux_amd64.tar.gz"
53 changes: 53 additions & 0 deletions roles/nvme_exporter/molecule/alternative/tests/test_alternative.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

from testinfra_helpers import get_target_hosts

testinfra_hosts = get_target_hosts()


def test_directories(host):
dirs = [
"/etc/nvme_exporter"
]
for dir in dirs:
d = host.file(dir)
assert d.is_directory
assert d.exists


def test_service(host):
s = host.service("nvme_exporter")
try:
assert s.is_running
except AssertionError:
# Capture service logs
journal_output = host.run('journalctl -u nvme_exporter --since "1 hour ago"')
print("\n==== journalctl -u nvme_exporter Output ====\n")
print(journal_output)
print("\n============================================\n")
raise # Re-raise the original assertion error


def test_protecthome_property(host):
s = host.service("nvme_exporter")
p = s.systemd_properties
assert p.get("ProtectHome") == "yes"


def test_collector_flags(host):
f = host.file("/etc/systemd/system/nvme_exporter.service")
assert f.contains("--collector.disable-defaults")
assert f.contains("--collector.info")
assert f.contains("--collector.smart")
assert f.contains("--no-collector.ocp")
assert f.contains("--web.telemetry-path=/nvme-metrics")


def test_socket(host):
sockets = [
"tcp://127.0.0.1:8080"
]
for socket in sockets:
s = host.socket(socket)
assert s.is_listening
6 changes: 6 additions & 0 deletions roles/nvme_exporter/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
provisioner:
inventory:
group_vars:
all:
nvme_exporter_web_listen_address: "127.0.0.1:9998"
76 changes: 76 additions & 0 deletions roles/nvme_exporter/molecule/default/tests/test_default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

from testinfra_helpers import get_target_hosts

testinfra_hosts = get_target_hosts()


def test_directories(host):
dirs = [
"/etc/nvme_exporter"
]
for dir in dirs:
d = host.file(dir)
assert d.is_directory
assert d.exists


def test_files(host):
files = [
"/etc/systemd/system/nvme_exporter.service",
"/usr/local/bin/nvme_exporter"
]
for file in files:
f = host.file(file)
assert f.exists
assert f.is_file


def test_permissions_didnt_change(host):
dirs = [
"/etc",
"/root",
"/usr",
"/var"
]
for file in dirs:
f = host.file(file)
assert f.exists
assert f.is_directory
assert f.user == "root"
assert f.group == "root"


def test_user(host):
assert host.group("nvme-exp").exists
assert "nvme-exp" in host.user("nvme-exp").groups
assert host.user("nvme-exp").shell == "/usr/sbin/nologin"


def test_service(host):
s = host.service("nvme_exporter")
try:
assert s.is_running
except AssertionError:
# Capture service logs
journal_output = host.run('journalctl -u nvme_exporter --since "1 hour ago"')
print("\n==== journalctl -u nvme_exporter Output ====\n")
print(journal_output)
print("\n============================================\n")
raise # Re-raise the original assertion error


def test_protecthome_property(host):
s = host.service("nvme_exporter")
p = s.systemd_properties
assert p.get("ProtectHome") == "yes"


def test_socket(host):
sockets = [
"tcp://127.0.0.1:9998"
]
for socket in sockets:
s = host.socket(socket)
assert s.is_listening
6 changes: 6 additions & 0 deletions roles/nvme_exporter/molecule/latest/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
provisioner:
inventory:
group_vars:
all:
nvme_exporter_version: latest
41 changes: 41 additions & 0 deletions roles/nvme_exporter/molecule/latest/tests/test_latest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

from testinfra_helpers import get_target_hosts
import pytest

testinfra_hosts = get_target_hosts()


@pytest.mark.parametrize("files", [
"/etc/systemd/system/nvme_exporter.service",
"/usr/local/bin/nvme_exporter"
])
def test_files(host, files):
f = host.file(files)
assert f.exists
assert f.is_file


def test_service(host):
s = host.service("nvme_exporter")
try:
assert s.is_running
except AssertionError:
# Capture service logs
journal_output = host.run('journalctl -u nvme_exporter --since "1 hour ago"')
print("\n==== journalctl -u nvme_exporter Output ====\n")
print(journal_output)
print("\n============================================\n")
raise # Re-raise the original assertion error


def test_protecthome_property(host):
s = host.service("nvme_exporter")
p = s.systemd_properties
assert p.get("ProtectHome") == "yes"


def test_socket(host):
s = host.socket("tcp://0.0.0.0:9998")
assert s.is_listening
Loading
Loading