Skip to content
Closed
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
2 changes: 1 addition & 1 deletion roles/_common/tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
extra_opts: "{{ _common_binary_unarchive_opts | default(omit, true) }}"
check_mode: false
throttle: 1 # see prometheus-community/ansible#457
when: __common_binary_basename is search('\.zip$|\.tar\.gz$')
when: __common_binary_basename is search('\.zip$|\.tar\.gz$|\.tgz$')

- name: "Check existence of binary install dir"
ansible.builtin.stat:
Expand Down
52 changes: 52 additions & 0 deletions roles/aerospike_exporter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<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: aerospike exporter


Deploy prometheus [aerospike exporter](https://github.com/prometheus/aerospike_exporter) using ansible.

## Requirements

- gnu-tar on Mac deployer host (`brew install gnu-tar`)
- Passlib is required when using the basic authentication feature (`python -m pip install passlib bcrypt==4.0.1`)

## 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/aerospike_exporter_role.html) for description and default values of the variables.

## Example

### Playbook

Use it in a playbook as follows:
```yaml
- hosts: all
collections:
- prometheus.prometheus
roles:
- prometheus.prometheus.aerospike_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.
20 changes: 20 additions & 0 deletions roles/aerospike_exporter/TROUBLESHOOTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Troubleshooting

## Bad requests (HTTP 400)

This role downloads checksums from the Github project to verify the integrity of artifacts installed on your servers. When downloading the checksums, a "bad request" error might occur.

This happens in environments which (knowningly or unknowling) use the [netrc mechanism](https://www.gnu.org/software/inetutils/manual/html_node/The-_002enetrc-file.html) to auto-login into servers.

Unless netrc is needed by your playbook and ansible roles, please unset the var like so:

```
$ NETRC= ansible-playbook ...
```

Or:

```
$ export NETRC=
$ ansible-playbook ...
```
25 changes: 25 additions & 0 deletions roles/aerospike_exporter/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
aerospike_exporter_version: 1.34.0
aerospike_exporter_binary_url: "https://github.com/{{ _aerospike_exporter_repo }}/releases/download/v{{ aerospike_exporter_version }}/\
aerospike-prometheus-exporter_{{ aerospike_exporter_version }}_{{ ansible_architecture }}.tgz"
aerospike_exporter_checksums_url: "{{ aerospike_exporter_binary_url }}.sha256"

aerospike_exporter_web_listen_address: "0.0.0.0:9145"

aerospike_exporter_username: ""
aerospike_exporter_password: ""

aerospike_exporter_config_file: "ape.toml"
aerospike_exporter_host: localhost
aerospike_exporter_port: 3000

aerospike_exporter_tls_server_config: {}

# Internal variables.
aerospike_exporter_binary_install_dir: "/usr/local/bin"
aerospike_exporter_config_dir: "/etc/aerospike_exporter"
aerospike_exporter_system_group: "aerospike-exp"
aerospike_exporter_system_user: "{{ aerospike_exporter_system_group }}"

# Local path to stash the archive and its extraction
aerospike_exporter_local_cache_path: "/tmp/aerospike_exporter-{{ ansible_facts['system'] | lower }}-{{ _aerospike_exporter_go_ansible_arch }}/{{ aerospike_exporter_version }}"
10 changes: 10 additions & 0 deletions roles/aerospike_exporter/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- name: Restart aerospike_exporter
listen: "restart aerospike_exporter"
become: true
ansible.builtin.systemd:
daemon_reload: true
name: aerospike_exporter
state: restarted
when:
- not ansible_check_mode
63 changes: 63 additions & 0 deletions roles/aerospike_exporter/meta/argument_specs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
# yamllint disable rule:line-length
argument_specs:
main:
short_description: "Prometheus Aerospike Exporter"
description:
- "Deploy prometheus L(aerospike_exporter,https://github.com/aerospike/aerospike-prometheus-exporter) using ansible"
author:
- "Prometheus Community"
options:
aerospike_exporter_version:
description: "Aerospike exporter package version. Also accepts latest as parameter."
default: "1.34.0"
aerospike_exporter_binary_url:
description: "URL of the aerospike_exporter binaries .tar.gz file"
default: "https://github.com/{{ _aerospike_exporter_repo }}/releases/download/v{{ aerospike_exporter_version }}/aerospike_exporter-{{ aerospike_exporter_version }}.{{ ansible_facts['system'] | lower }}-{{ _aerospike_exporter_go_ansible_arch }}.tar.gz"
aerospike_exporter_checksums_url:
description: "URL of the aerospike_exporter checksums file"
default: "https://github.com/{{ _aerospike_exporter_repo }}/releases/download/v{{ aerospike_exporter_version }}/sha256sums.txt"
aerospike_exporter_web_listen_address:
description: "Address on which aerospike_exporter will listen"
default: "0.0.0.0:9145"
aerospike_exporter_config_dir:
description: "Path to directory with aerospike_exporter configuration"
default: "/etc/aerospike_exporter"
aerospike_exporter_config_file:
description: "The filename of the exporter aerospike config file"
default: "ape.toml"
aerospike_exporter_host:
description: "The target Aerospike host"
default: "localhost"
aerospike_exporter_port:
description: "The target Aerospike port"
default: 3000
aerospike_exporter_username:
description: "The username for Aerospike login"
default: ""
aerospike_exporter_password:
description: "The password for Aerospike login"
default: ""
aerospike_exporter_tls_server_config:
description:
- "Configuration for TLS authentication."
- "Keys and values are the same as in L(aerospike_exporter docs,https://github.com/aerospike/aerospike-prometheus-exporter/blob/master/https/README.md#sample-config)."
type: "dict"
aerospike_exporter_binary_install_dir:
description:
- "I(Advanced)"
- "Directory to install aerospike_exporter binary"
default: "/usr/local/bin"
aerospike_exporter_system_group:
description:
- "I(Advanced)"
- "System group for Aerospike Exporter"
default: "aerospike-exp"
aerospike_exporter_system_user:
description:
- "I(Advanced)"
- "Aerospike Exporter user"
default: "aerospike-exp"
aerospike_exporter_local_cache_path:
description: "Local path to stash the archive and its extraction"
default: "/tmp/aerospike_exporter-{{ ansible_facts['system'] | lower }}-{{ _aerospike_exporter_go_ansible_arch }}/{{ aerospike_exporter_version }}"
26 changes: 26 additions & 0 deletions roles/aerospike_exporter/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
galaxy_info:
author: "Prometheus Community"
description: "Prometheus Aerospike 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"
- "aerospike"
16 changes: 16 additions & 0 deletions roles/aerospike_exporter/molecule/alternative/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
provisioner:
playbooks:
prepare: "${MOLECULE_PROJECT_DIRECTORY}/../../.config/molecule/alternative/prepare.yml"
inventory:
group_vars:
all:
aerospike_exporter_local_cache_path: "/tmp/aerospike_exporter-linux-amd64"
aerospike_exporter_web_listen_address: '127.0.0.1:8080'
aerospike_exporter_tls_server_config:
cert_file: /etc/aerospike_exporter/tls.cert
key_file: /etc/aerospike_exporter/tls.key
aerospike_exporter_version: 1.34.0
aerospike_exporter_binary_url: "https://github.com/prometheus/aerospike_exporter/releases/download/v{{\
\ aerospike_exporter_version }}/aerospike_exporter-{{ aerospike_exporter_version\
\ }}.linux-amd64.tar.gz"
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("aerospike_exporter")
try:
assert s.is_running
except AssertionError:
# Capture service logs
journal_output = host.run('journalctl -u aerospike_exporter --since "1 hour ago"')
print("\n==== journalctl -u aerospike_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
6 changes: 6 additions & 0 deletions roles/aerospike_exporter/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
provisioner:
inventory:
group_vars:
all:
aerospike_exporter_web_listen_address: "127.0.0.1:9145"
70 changes: 70 additions & 0 deletions roles/aerospike_exporter/molecule/default/tests/test_default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
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/aerospike_exporter"
]
for dir in dirs:
d = host.file(dir)
assert d.is_directory
assert d.exists


def test_files(host):
files = [
"/etc/systemd/system/aerospike_exporter.service",
"/usr/local/bin/aerospike_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("aerospike-exp").exists
assert "aerospike-exp" in host.user("aerospike-exp").groups
assert host.user("aerospike-exp").shell == "/usr/sbin/nologin"


def test_service(host):
s = host.service("aerospike_exporter")
try:
assert s.is_running
except AssertionError:
# Capture service logs
journal_output = host.run('journalctl -u aerospike_exporter --since "1 hour ago"')
print("\n==== journalctl -u aerospike_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:9104"
]
for socket in sockets:
s = host.socket(socket)
assert s.is_listening
6 changes: 6 additions & 0 deletions roles/aerospike_exporter/molecule/latest/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
provisioner:
inventory:
group_vars:
all:
aerospike_exporter_version: latest
35 changes: 35 additions & 0 deletions roles/aerospike_exporter/molecule/latest/tests/test_latest.py
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/aerospike_exporter.service",
"/usr/local/bin/aerospike_exporter"
])
def test_files(host, files):
f = host.file(files)
assert f.exists
assert f.is_file


def test_service(host):
s = host.service("aerospike_exporter")
try:
assert s.is_running
except AssertionError:
# Capture service logs
journal_output = host.run('journalctl -u aerospike_exporter --since "1 hour ago"')
print("\n==== journalctl -u aerospike_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:9104")
assert s.is_listening
Loading
Loading