Skip to content

Commit

Permalink
feat: include influxdb exporter role
Browse files Browse the repository at this point in the history
Include the [Influxdb exporter](https://github.com/prometheus/influxdb_exporter) role.
  • Loading branch information
dobbi84 committed Aug 6, 2024
1 parent dc94de0 commit 91d7350
Show file tree
Hide file tree
Showing 20 changed files with 648 additions and 0 deletions.
54 changes: 54 additions & 0 deletions roles/influxdb_exporter/README.md
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.
23 changes: 23 additions & 0 deletions roles/influxdb_exporter/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
influxdb_exporter_version: "0.11.5"
influxdb_exporter_binary_local_dir: ""
influxdb_exporter_binary_url: "https://github.com/{{ _influxdb_exporter_repo }}/releases/download/v{{ influxdb_exporter_version }}/\
influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{ go_arch }}.tar.gz"
influxdb_exporter_checksums_url: "https://github.com/{{ _influxdb_exporter_repo }}/releases/download/v{{ influxdb_exporter_version }}/sha256sums.txt"
influxdb_exporter_skip_install: false

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 }}"

# Local path to stash the archive and its extraction
influxdb_exporter_archive_path: /tmp
10 changes: 10 additions & 0 deletions roles/influxdb_exporter/handlers/main.yml
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
72 changes: 72 additions & 0 deletions roles/influxdb_exporter/meta/argument_specs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
# 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_skip_install:
description: "influxdb exporter installation tasks gets skipped when set to true."
type: bool
default: false
influxdb_exporter_binary_local_dir:
description:
- "Enables the use of local packages instead of those distributed on github."
- "The parameter may be set to a directory where the C(influxdb_exporter) binary is stored on the host where ansible is run."
- "This overrides the I(influxdb_exporter_version) parameter"
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 }}.linux-{{ go_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_archive_path:
description: 'Local path to stash the archive and its extraction'
default: "/tmp"
25 changes: 25 additions & 0 deletions roles/influxdb_exporter/meta/main.yml
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"
- name: "Debian"
versions:
- "bullseye"
- "buster"
- name: "EL"
versions:
- "8"
- "9"
galaxy_tags:
- "monitoring"
- "prometheus"
- "exporter"
- "metrics"
- "system"
12 changes: 12 additions & 0 deletions roles/influxdb_exporter/molecule/alternative/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
provisioner:
inventory:
group_vars:
all:
influxdb_exporter_binary_local_dir: "/tmp/influxdb_exporter-linux-amd64"
influxdb_exporter_web_listen_address:
- '127.0.0.1:8080'
- '127.0.1.1:8080'

go_arch: amd64
influxdb_exporter_version: 0.11.2
35 changes: 35 additions & 0 deletions roles/influxdb_exporter/molecule/alternative/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
- name: Run local preparation
hosts: localhost
gather_facts: false
tasks:
- name: Download influxdb_exporter binary to local folder
become: false
ansible.builtin.get_url:
url: "https://github.com/prometheus/influxdb_exporter/releases/download/v{{\
\ influxdb_exporter_version }}/influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{\
\ go_arch }}.tar.gz"
dest: "/tmp/influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{ go_arch }}.tar.gz"
mode: 0644
register: _download_binary
until: _download_binary is succeeded
retries: 5
delay: 2
check_mode: false

- name: Unpack influxdb_exporter binary
become: false
ansible.builtin.unarchive:
src: "/tmp/influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{ go_arch }}.tar.gz"
dest: "/tmp"
creates: "/tmp/influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{ go_arch\
\ }}/influxdb_exporter"
check_mode: false

- name: Link to influxdb_exporter binaries directory
become: false
ansible.builtin.file:
src: "/tmp/influxdb_exporter-{{ influxdb_exporter_version }}.linux-amd64"
dest: "/tmp/influxdb_exporter-linux-amd64"
state: link
check_mode: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

import os
import testinfra.utils.ansible_runner
import pytest

testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')


def test_directories(host):
dirs = [
"/var/lib/influxdb_exporter"
]
for dir in dirs:
d = host.file(dir)
assert not d.exists


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",
"tcp://127.0.1.1:8080",
])
def test_socket(host, sockets):
assert host.socket(sockets).is_listening
6 changes: 6 additions & 0 deletions roles/influxdb_exporter/molecule/default/molecule.yml
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"
73 changes: 73 additions & 0 deletions roles/influxdb_exporter/molecule/default/tests/test_default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

import os
import testinfra.utils.ansible_runner

testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')


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


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 == "/"


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
6 changes: 6 additions & 0 deletions roles/influxdb_exporter/molecule/latest/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
provisioner:
inventory:
group_vars:
all:
influxdb_exporter_version: latest
Loading

0 comments on commit 91d7350

Please sign in to comment.