-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Zhang, Chaoyue (Jack) <jackzhang@telenavsoftware.com>
- Loading branch information
Showing
16 changed files
with
502 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<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: Nvidia GPU exporter | ||
|
||
## Description | ||
|
||
Deploy prometheus [Nvidia GPU exporter ](https://github.com/utkuozdemir/nvidia_gpu_exporter) using ansible. | ||
|
||
## Requirements | ||
|
||
- Ansible >= 2.9 (It might work on previous versions, but we cannot guarantee it) | ||
- gnu-tar on Mac deployer host (`brew install gnu-tar`) | ||
- Passlib is required when using the basic authentication feature (`pip install passlib[bcrypt]`) | ||
|
||
## 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/nvidia_gpu_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.nvidia_gpu_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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
nvidia_gpu_exporter_version: 1.2.1 | ||
nvidia_gpu_exporter_binary_url: "https://github.com/{{ _nvidia_gpu_exporter_repo }}/releases/download/v{{ nvidia_gpu_exporter_version }}/\ | ||
nvidia_gpu_exporter_{{ nvidia_gpu_exporter_version }}_{{ ansible_system | lower }}_{{ _nvidia_gpu_exporter_go_ansible_arch }}.tar.gz" | ||
nvidia_gpu_exporter_checksums_url: "https://github.com/{{ _nvidia_gpu_exporter_repo }}/releases/download/v{{ nvidia_gpu_exporter_version }}/checksums.txt" | ||
|
||
nvidia_gpu_exporter_web_listen_address: "0.0.0.0:9835" | ||
nvidia_gpu_exporter_web_telemetry_path: "/metrics" | ||
|
||
nvidia_gpu_exporter_binary_install_dir: "/usr/local/bin" | ||
nvidia_gpu_exporter_system_group: "nvidia-gpu-exp" | ||
nvidia_gpu_exporter_system_user: "{{ nvidia_gpu_exporter_system_group }}" | ||
|
||
nvidia_gpu_exporter_config_dir: "/etc/nvidia_gpu_exporter" | ||
# Local path to stash the archive and its extraction | ||
nvidia_gpu_exporter_local_cache_path: "/tmp/nvidia_gpu_exporter-{{ ansible_system | lower }}-{{ _nvidia_gpu_exporter_go_ansible_arch }}/{{ nvidia_gpu_exporter_version }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
- name: Restart nvidia_gpu_exporter | ||
listen: "restart nvidia_gpu_exporter" | ||
become: true | ||
ansible.builtin.systemd: | ||
daemon_reload: true | ||
name: nvidia_gpu_exporter | ||
state: restarted | ||
when: | ||
- not ansible_check_mode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
# yamllint disable rule:line-length | ||
argument_specs: | ||
main: | ||
short_description: "Prometheus Nvidia GPU Exporter" | ||
description: | ||
- "Deploy prometheus L(Nvidia GPU exporter,https://github.com/utkuozdemir/nvidia_gpu_exporter) using ansible" | ||
author: | ||
- "Prometheus Community" | ||
options: | ||
nvidia_gpu_exporter_version: | ||
description: "Nvidia GPU exporter package version. Also accepts latest as parameter." | ||
default: "1.2.1" | ||
nvidia_gpu_exporter_binary_url: | ||
description: "URL of the Nvidia GPU exporter binaries .tar.gz file" | ||
default: "https://github.com/{{ _nvidia_gpu_exporter_repo }}/releases/download/v{{ nvidia_gpu_exporter_version }}/nvidia_gpu_exporter_{{ nvidia_gpu_exporter_version }}_{{ ansible_system | lower }}_{{ _nvidia_gpu_exporter_go_ansible_arch }}.tar.gz" | ||
nvidia_gpu_exporter_checksums_url: | ||
description: "URL of the Nvidia GPU exporter checksums file" | ||
default: "https://github.com/{{ _nvidia_gpu_exporter_repo }}/releases/download/v{{ nvidia_gpu_exporter_version }}/sha256sums.txt" | ||
nvidia_gpu_exporter_web_listen_address: | ||
description: "Address on which Nvidia GPU exporter will listen" | ||
default: "0.0.0.0:9835" | ||
nvidia_gpu_exporter_web_telemetry_path: | ||
description: "Path under which to expose metrics" | ||
default: "/metrics" | ||
nvidia_gpu_exporter_binary_install_dir: | ||
description: | ||
- "I(Advanced)" | ||
- "Directory to install nvidia_gpu_exporter binary" | ||
default: "/usr/local/bin" | ||
nvidia_gpu_exporter_system_group: | ||
description: | ||
- "I(Advanced)" | ||
- "System group for Nvidia GPU exporter" | ||
default: "nvidia-gpu-exp" | ||
nvidia_gpu_exporter_system_user: | ||
description: | ||
- "I(Advanced)" | ||
- "Nvidia GPU exporter user" | ||
default: "nvidia-gpu-exp" | ||
nvidia_gpu_exporter_local_cache_path: | ||
description: "Local path to stash the archive and its extraction" | ||
default: "/tmp/nvidia_gpu_exporter-{{ ansible_system | lower }}-{{ _nvidia_gpu_exporter_go_ansible_arch }}/{{ nvidia_gpu_exporter_version }}" | ||
nvidia_gpu_exporter_config_dir: | ||
description: "Path to directory with nvidia_gpu_exporter configuration" | ||
default: "/etc/nvidia_gpu_exporter" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
galaxy_info: | ||
author: "Prometheus Community" | ||
description: "Nvidia GPU exporter" | ||
license: "Apache" | ||
min_ansible_version: "2.9" | ||
platforms: | ||
- name: "Ubuntu" | ||
versions: | ||
- "focal" | ||
- "jammy" | ||
- "noble" | ||
- name: "Debian" | ||
versions: | ||
- "bullseye" | ||
- name: "EL" | ||
versions: | ||
- "8" | ||
- "9" | ||
galaxy_tags: | ||
- "monitoring" | ||
- "prometheus" | ||
- "exporter" | ||
- "metrics" | ||
- "system" |
14 changes: 14 additions & 0 deletions
14
roles/nvidia_gpu_exporter/molecule/alternative/molecule.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
provisioner: | ||
playbooks: | ||
prepare: "${MOLECULE_PROJECT_DIRECTORY}/../../.config/molecule/alternative/prepare.yml" | ||
inventory: | ||
group_vars: | ||
all: | ||
nvidia_gpu_exporter_local_cache_path: "/tmp/nvidia_gpu_exporter-linux-amd64" | ||
nvidia_gpu_exporter_web_listen_address: | ||
- '127.0.0.1:9835' | ||
- '127.0.1.1:9835' | ||
nvidia_gpu_exporter_version: 1.2.1 | ||
nvidia_gpu_exporter_binary_url: "https://github.com/utkuozdemir/nvidia_gpu_exporter/releases/download/v{{\ | ||
\ nvidia_gpu_exporter_version }}/nvidia_gpu_exporter_{{ nvidia_gpu_exporter_version }}.linux-amd64.tar.gz" |
42 changes: 42 additions & 0 deletions
42
roles/nvidia_gpu_exporter/molecule/alternative/tests/test_alternative.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from __future__ import (absolute_import, division, print_function) | ||
__metaclass__ = type | ||
|
||
from testinfra_helpers import get_target_hosts | ||
import pytest | ||
|
||
testinfra_hosts = get_target_hosts() | ||
|
||
|
||
def test_directories(host): | ||
dirs = [ | ||
"/var/lib/nvidia_gpu_exporter" | ||
] | ||
for dir in dirs: | ||
d = host.file(dir) | ||
assert not d.exists | ||
|
||
|
||
def test_service(host): | ||
s = host.service("nvidia_gpu_exporter") | ||
try: | ||
assert s.is_running | ||
except AssertionError: | ||
# Capture service logs | ||
journal_output = host.run('journalctl -u nvidia_gpu_exporter --since "1 hour ago"') | ||
print("\n==== journalctl -u nvidia_gpu_exporter Output ====\n") | ||
print(journal_output) | ||
print("\n============================================\n") | ||
raise # Re-raise the original assertion error | ||
|
||
|
||
def test_protecthome_property(host): | ||
s = host.service("nvidia_gpu_exporter") | ||
p = s.systemd_properties | ||
assert p.get("ProtectHome") == "yes" | ||
|
||
|
||
@pytest.mark.parametrize("sockets", [ | ||
"tcp://127.0.1.1:9835", | ||
]) | ||
def test_socket(host, sockets): | ||
assert host.socket(sockets).is_listening |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
provisioner: | ||
inventory: | ||
group_vars: | ||
all: | ||
nvidia_gpu_exporter_web_listen_address: "127.0.0.1:9835" |
76 changes: 76 additions & 0 deletions
76
roles/nvidia_gpu_exporter/molecule/default/tests/test_default.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = [ | ||
"/var/lib/nvidia_gpu_exporter" | ||
] | ||
for dir in dirs: | ||
d = host.file(dir) | ||
assert d.is_directory | ||
assert d.exists | ||
|
||
|
||
def test_files(host): | ||
files = [ | ||
"/etc/systemd/system/nvidia_gpu_exporter.service", | ||
"/usr/local/bin/nvidia_gpu_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("nvidia-gpu-exp").exists | ||
assert "nvidia-gpu-exp" in host.user("nvidia-gpu-exp").groups | ||
assert host.user("nvidia-gpu-exp").shell == "/usr/sbin/nologin" | ||
|
||
|
||
def test_service(host): | ||
s = host.service("nvidia_gpu_exporter") | ||
try: | ||
assert s.is_running | ||
except AssertionError: | ||
# Capture service logs | ||
journal_output = host.run('journalctl -u nvidia_gpu_exporter --since "1 hour ago"') | ||
print("\n==== journalctl -u nvidia_gpu_exporter Output ====\n") | ||
print(journal_output) | ||
print("\n============================================\n") | ||
raise # Re-raise the original assertion error | ||
|
||
|
||
def test_protecthome_property(host): | ||
s = host.service("nvidia_gpu_exporter") | ||
p = s.systemd_properties | ||
assert p.get("ProtectHome") == "yes" | ||
|
||
|
||
def test_socket(host): | ||
sockets = [ | ||
"tcp://127.0.0.1:9835" | ||
] | ||
for socket in sockets: | ||
s = host.socket(socket) | ||
assert s.is_listening |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
provisioner: | ||
inventory: | ||
group_vars: | ||
all: | ||
nvidia_gpu_exporter_version: latest |
51 changes: 51 additions & 0 deletions
51
roles/nvidia_gpu_exporter/molecule/latest/tests/test_latest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
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/nvidia_gpu_exporter.service", | ||
"/usr/local/bin/nvidia_gpu_exporter" | ||
]) | ||
def test_files(host, files): | ||
f = host.file(files) | ||
assert f.exists | ||
assert f.is_file | ||
|
||
|
||
def test_directories(host): | ||
dirs = [ | ||
"/var/lib/nvidia_gpu_exporter" | ||
] | ||
for dir in dirs: | ||
d = host.file(dir) | ||
assert d.is_directory | ||
assert d.exists | ||
|
||
|
||
def test_service(host): | ||
s = host.service("nvidia_gpu_exporter") | ||
try: | ||
assert s.is_running | ||
except AssertionError: | ||
# Capture service logs | ||
journal_output = host.run('journalctl -u nvidia_gpu_exporter --since "1 hour ago"') | ||
print("\n==== journalctl -u nvidia_gpu_exporter Output ====\n") | ||
print(journal_output) | ||
print("\n============================================\n") | ||
raise # Re-raise the original assertion error | ||
|
||
|
||
def test_protecthome_property(host): | ||
s = host.service("nvidia_gpu_exporter") | ||
p = s.systemd_properties | ||
assert p.get("ProtectHome") == "read-only" | ||
|
||
|
||
def test_socket(host): | ||
s = host.socket("tcp://0.0.0.0:9835") | ||
assert s.is_listening |
Oops, something went wrong.