-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #408 from dobbi84/dobbi84/influxdb_exporter
feat: include influxdb exporter role
- Loading branch information
Showing
19 changed files
with
493 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 @@ | ||
# Ansible Role: influxdb exporter | ||
|
||
## Description | ||
|
||
Deploy prometheus [Influxdb exporter](https://github.com/prometheus/influxdb_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`) | ||
|
||
## 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/influxdb_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.influxdb_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,22 @@ | ||
--- | ||
influxdb_exporter_version: "0.11.5" | ||
influxdb_exporter_binary_url: "https://github.com/{{ _influxdb_exporter_repo }}/releases/download/v{{ influxdb_exporter_version }}/\ | ||
influxdb_exporter-{{ influxdb_exporter_version }}.{{ ansible_system | lower }}-{{ _influxdb_exporter_go_ansible_arch }}.tar.gz" | ||
influxdb_exporter_checksums_url: "https://github.com/{{ _influxdb_exporter_repo }}/releases/download/v{{ influxdb_exporter_version }}/sha256sums.txt" | ||
|
||
influxdb_exporter_web_listen_address: "0.0.0.0:9122" | ||
influxdb_exporter_udp_bind_address: "{{ influxdb_exporter_web_listen_address }}" | ||
influxdb_exporter_web_telemetry_path: "/metrics" | ||
influxdb_exporter_exporter_web_telemetry_path: "/metrics/exporter" | ||
influxdb_exporter_influxdb_sample_expiry: "5m" | ||
influxdb_exporter_log_level: "info" | ||
influxdb_exporter_log_format: "logfmt" | ||
influxdb_exporter_export_timestamps: true | ||
|
||
influxdb_exporter_binary_install_dir: "/usr/local/bin" | ||
influxdb_exporter_system_group: "influxdb-exp" | ||
influxdb_exporter_system_user: "{{ influxdb_exporter_system_group }}" | ||
|
||
influxdb_exporter_config_dir: "/etc/influxdb_exporter" | ||
# Local path to stash the archive and its extraction | ||
influxdb_exporter_local_cache_path: "/tmp/influxdb_exporter-{{ ansible_system | lower }}-{{ _influxdb_exporter_go_ansible_arch }}/{{ influxdb_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 influxdb_exporter | ||
listen: "restart influxdb_exporter" | ||
become: true | ||
ansible.builtin.systemd: | ||
daemon_reload: true | ||
name: influxdb_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,66 @@ | ||
--- | ||
# yamllint disable rule:line-length | ||
argument_specs: | ||
main: | ||
short_description: "Prometheus Influxdb Exporter" | ||
description: | ||
- "Deploy prometheus L(influxdb exporter,https://github.com/prometheus/influxdb_exporter) using ansible" | ||
author: | ||
- "Prometheus Community" | ||
options: | ||
influxdb_exporter_version: | ||
description: "influxdb exporter package version. Also accepts latest as parameter." | ||
default: "0.11.5" | ||
influxdb_exporter_binary_url: | ||
description: "URL of the influxdb exporter binaries .tar.gz file" | ||
default: "https://github.com/{{ _influxdb_exporter_repo }}/releases/download/v{{ influxdb_exporter_version }}/influxdb_exporter-{{ influxdb_exporter_version }}.{{ ansible_system | lower }}-{{ _influxdb_exporter_go_ansible_arch }}.tar.gz" | ||
influxdb_exporter_checksums_url: | ||
description: "URL of the influxdb exporter checksums file" | ||
default: "https://github.com/{{ _influxdb_exporter_repo }}/releases/download/v{{ influxdb_exporter_version }}/sha256sums.txt" | ||
influxdb_exporter_web_listen_address: | ||
description: "Address on which influxdb exporter will listen" | ||
default: "0.0.0.0:9122" | ||
influxdb_exporter_web_telemetry_path: | ||
description: "Path under which to expose metrics" | ||
default: "/metrics" | ||
influxdb_exporter_influxdb_sample_expiry: | ||
description: "How long a sample is valid for" | ||
default: "5m" | ||
influxdb_exporter_udp_bind_address: | ||
description: "Address on which to listen for udp packets" | ||
default: "0.0.0.0:9122" | ||
influxdb_exporter_exporter_web_telemetry_path: | ||
description: "Path under which to expose metrics" | ||
default: "/metrics" | ||
influxdb_exporter_log_level: | ||
default: "info" | ||
description: "Only log messages with the given severity or above" | ||
choices: ["debug", "info", "warn", "error"] | ||
influxdb_exporter_log_format: | ||
default: "logfmt" | ||
description: "Output format of log messages" | ||
choices: ["logfmt", "json"] | ||
influxdb_exporter_export_timestamps: | ||
default: true | ||
description: "Export timestamps of points" | ||
influxdb_exporter_binary_install_dir: | ||
description: | ||
- "I(Advanced)" | ||
- "Directory to install influxdb_exporter binary" | ||
default: "/usr/local/bin" | ||
influxdb_exporter_system_group: | ||
description: | ||
- "I(Advanced)" | ||
- "System group for influxdb exporter" | ||
default: "influxdb-exp" | ||
influxdb_exporter_system_user: | ||
description: | ||
- "I(Advanced)" | ||
- "influxdb exporter user" | ||
default: "influxdb-exp" | ||
influxdb_exporter_local_cache_path: | ||
description: 'Local path to stash the archive and its extraction' | ||
default: "/tmp/influxdb_exporter-{{ ansible_system | lower }}-{{ _influxdb_exporter_go_ansible_arch }}/{{ influxdb_exporter_version }}" | ||
influxdb_exporter_config_dir: | ||
description: "Path to directory with influxdb_exporter configuration" | ||
default: "/etc/influxdb_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: "Prometheus Influxdb 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" |
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 @@ | ||
--- | ||
provisioner: | ||
playbooks: | ||
prepare: "${MOLECULE_PROJECT_DIRECTORY}/../../.config/molecule/alternative/prepare.yml" | ||
inventory: | ||
group_vars: | ||
all: | ||
influxdb_exporter_web_listen_address: '127.0.0.1:8080' | ||
|
||
influxdb_exporter_version: 0.11.2 |
27 changes: 27 additions & 0 deletions
27
roles/influxdb_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,27 @@ | ||
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_service(host): | ||
s = host.service("influxdb_exporter") | ||
try: | ||
assert s.is_running | ||
except AssertionError: | ||
# Capture service logs | ||
journal_output = host.run('journalctl -u influxdb_exporter --since "1 hour ago"') | ||
print("\n==== journalctl -u influxdb_exporter Output ====\n") | ||
print(journal_output) | ||
print("\n============================================\n") | ||
raise # Re-raise the original assertion error | ||
|
||
|
||
@pytest.mark.parametrize("sockets", [ | ||
"tcp://127.0.0.1:8080", | ||
]) | ||
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: | ||
influxdb_exporter_web_listen_address: "127.0.0.1:9122" |
61 changes: 61 additions & 0 deletions
61
roles/influxdb_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,61 @@ | ||
from __future__ import (absolute_import, division, print_function) | ||
__metaclass__ = type | ||
|
||
from testinfra_helpers import get_target_hosts | ||
|
||
testinfra_hosts = get_target_hosts() | ||
|
||
|
||
def test_files(host): | ||
files = [ | ||
"/etc/systemd/system/influxdb_exporter.service", | ||
"/usr/local/bin/influxdb_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("influxdb-exp").exists | ||
assert "influxdb-exp" in host.user("influxdb-exp").groups | ||
assert host.user("influxdb-exp").shell == "/usr/sbin/nologin" | ||
assert host.user("influxdb-exp").home == "/etc/influxdb_exporter" | ||
|
||
|
||
def test_service(host): | ||
s = host.service("influxdb_exporter") | ||
try: | ||
assert s.is_running | ||
except AssertionError: | ||
# Capture service logs | ||
journal_output = host.run('journalctl -u influxdb_exporter --since "1 hour ago"') | ||
print("\n==== journalctl -u influxdb_exporter Output ====\n") | ||
print(journal_output) | ||
print("\n============================================\n") | ||
raise # Re-raise the original assertion error | ||
|
||
|
||
def test_socket(host): | ||
sockets = [ | ||
"tcp://127.0.0.1:9122" | ||
] | ||
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: | ||
influxdb_exporter_version: latest |
35 changes: 35 additions & 0 deletions
35
roles/influxdb_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,35 @@ | ||
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/influxdb_exporter.service", | ||
"/usr/local/bin/influxdb_exporter" | ||
]) | ||
def test_files(host, files): | ||
f = host.file(files) | ||
assert f.exists | ||
assert f.is_file | ||
|
||
|
||
def test_service(host): | ||
s = host.service("influxdb_exporter") | ||
try: | ||
assert s.is_running | ||
except AssertionError: | ||
# Capture service logs | ||
journal_output = host.run('journalctl -u influxdb_exporter --since "1 hour ago"') | ||
print("\n==== journalctl -u influxdb_exporter Output ====\n") | ||
print(journal_output) | ||
print("\n============================================\n") | ||
raise # Re-raise the original assertion error | ||
|
||
|
||
def test_socket(host): | ||
s = host.socket("tcp://0.0.0.0:9122") | ||
assert s.is_listening |
Oops, something went wrong.