-
Notifications
You must be signed in to change notification settings - Fork 144
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: Tobias Bauriedel <[email protected]>
- Loading branch information
1 parent
83b5c96
commit fb5b2b2
Showing
16 changed files
with
597 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,81 @@ | ||
# Ansible Role: apache exporter | ||
|
||
Deploy prometheus [apache exporter](https://github.com/Lusitaniae/apache_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/apache_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.apache_exporter | ||
``` | ||
### TLS config | ||
Before running mysqld_exporter role, the user needs to provision their own certificate and key. | ||
```yaml | ||
- hosts: all | ||
pre_tasks: | ||
- name: Create apache_exporter cert dir | ||
ansible.builtin.file: | ||
path: "/etc/apache_exporter" | ||
state: directory | ||
owner: root | ||
group: root | ||
|
||
- name: Create cert and key | ||
community.crypto.x509_certificate: | ||
path: /etc/apache_exporter/tls.cert | ||
csr_path: /etc/apache_exporter/tls.csr | ||
privatekey_path: /etc/apache_exporter/tls.key | ||
provider: selfsigned | ||
collections: | ||
- prometheus.prometheus | ||
roles: | ||
- prometheus.prometheus.apache_exporter | ||
vars: | ||
apache_exporter_tls_server_config: | ||
cert_file: /etc/apache_exporter/tls.cert | ||
key_file: /etc/apache_exporter/tls.key | ||
apache_exporter_basic_auth_users: | ||
randomuser: examplepassword | ||
``` | ||
### 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,24 @@ | ||
--- | ||
apache_exporter_version: 1.0.9 | ||
apache_exporter_binary_url: "https://github.com/{{ _apache_exporter_repo }}/releases/download/v{{ apache_exporter_version }}/\ | ||
apache_exporter-{{ apache_exporter_version }}.{{ ansible_facts['system'] | lower }}-{{ _apache_exporter_go_ansible_arch }}.tar.gz" | ||
apache_exporter_checksums_url: "https://github.com/{{ _apache_exporter_repo }}/releases/download/v{{ apache_exporter_version }}/sha256sums.txt" | ||
|
||
apache_exporter_web_listen_address: "0.0.0.0:9117" | ||
apache_exporter_web_telemetry_path: "/metrics" | ||
apache_exporter_uri: "http://localhost/server-status/?auto" | ||
apache_exporter_timeout_offset: 1 | ||
|
||
apache_exporter_tls_server_config: {} | ||
apache_exporter_http_server_config: {} | ||
apache_exporter_basic_auth_users: {} | ||
|
||
apache_exporter_log_level: "error" | ||
|
||
apache_exporter_binary_install_dir: "/usr/local/bin" | ||
apache_exporter_system_user: "apache-exp" | ||
apache_exporter_system_group: "{{ apache_exporter_system_user }}" | ||
apache_exporter_config_dir: "/etc/apache_exporter" | ||
|
||
# Local path to stash the archive and its extraction | ||
apache_exporter_local_cache_path: "/tmp/apache_exporter-{{ ansible_facts['system'] | lower }}-{{ _apache_exporter_go_ansible_arch }}/{{ apache_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 apache_exporter | ||
listen: "restart apache_exporter" | ||
become: true | ||
ansible.builtin.systemd: | ||
daemon_reload: true | ||
name: apache_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,72 @@ | ||
--- | ||
# yamllint disable rule:line-length | ||
argument_specs: | ||
main: | ||
short_description: "Prometheus apache_exporter" | ||
description: | ||
- "Deploy prometheus L(apache exporter,https://github.com/Lusitaniae/apache_exporter) using ansible" | ||
author: | ||
- "Prometheus Community" | ||
options: | ||
apache_exporter_version: | ||
description: "apache_exporter package version. Also accepts latest as parameter." | ||
default: "1.0.9" | ||
apache_exporter_binary_url: | ||
description: "URL of the apache_exporter binaries .tar.gz file" | ||
default: "https://github.com/{{ _apache_exporter_repo }}/releases/download/v{{ apache_exporter_version }}/apache_exporter_{{ apache_exporter_version }}_{{ ansible_facts['system'] | lower }}-{{ _apache_exporter_go_ansible_arch }}.tar.gz" | ||
apache_exporter_checksums_url: | ||
description: "URL of the apache_exporter checksums file" | ||
default: "https://github.com/{{ _apache_exporter_repo }}/releases/download/v{{ apache_exporter_version }}/apache_exporter_{{ apache_exporter_version }}_checksums.txt" | ||
apache_exporter_web_listen_address: | ||
description: "Address on which apache exporter will listen" | ||
default: "0.0.0.0:9117" | ||
apache_exporter_web_telemetry_path: | ||
description: "Path under which to expose metrics" | ||
default: "/metrics" | ||
apache_exporter_uri: | ||
description: "URI to scrape apache metrics" | ||
default: "http://localhost/server-status/?auto" | ||
apache_exporter_timeout_offset: | ||
description: "Offset to add to the timeout for the scrape" | ||
default: 1 | ||
apache_exporter_tls_server_config: | ||
description: | ||
- "Configuration for TLS authentication." | ||
- "Keys and values are the same as in L(apache_exporter docs,https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md)." | ||
type: "dict" | ||
apache_exporter_http_server_config: | ||
description: | ||
- "Config for HTTP/2 support." | ||
- "Keys and values are the same as in L(apache_exporter docs,https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md)." | ||
type: "dict" | ||
apache_exporter_basic_auth_users: | ||
description: "Dictionary of users and password for basic authentication. Passwords are automatically hashed with bcrypt." | ||
type: "dict" | ||
apache_exporter_log_level: | ||
description: "Only log messages with the given severity or above. One of: [debug, info, warn, error]" | ||
default: "error" | ||
apache_exporter_binary_install_dir: | ||
description: | ||
- "I(Advanced)" | ||
- "Directory to install apache_exporter binary" | ||
default: "/usr/local/bin" | ||
apache_exporter_system_user: | ||
description: | ||
- "I(Advanced)" | ||
- "System user for apache_exporter" | ||
default: "apache-exp" | ||
apache_exporter_system_group: | ||
description: | ||
- "I(Advanced)" | ||
- "System group for apache_exporter" | ||
default: "apache-exp" | ||
apache_exporter_config_dir: | ||
description: | ||
- "I(Advanced)" | ||
- "Directory to store apache_exporter configuration" | ||
default: "/etc/apache_exporter" | ||
apache_exporter_local_cache_path: | ||
description: | ||
- "I(Advanced)" | ||
- "Local path to stash the archive and its extraction" | ||
default: "/tmp/apache_exporter-{{ ansible_facts['system'] | lower }}-{{ _apache_exporter_go_ansible_arch }}/{{ apache_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,26 @@ | ||
--- | ||
galaxy_info: | ||
author: "Prometheus Community" | ||
description: "Prometheus apache_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" | ||
- "apache" |
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 @@ | ||
--- | ||
provisioner: | ||
playbooks: | ||
prepare: "${MOLECULE_PROJECT_DIRECTORY}/../../.config/molecule/alternative/prepare.yml" | ||
inventory: | ||
group_vars: | ||
all: | ||
apache_exporter_web_listen_address: "127.0.0.1:9118" | ||
apache_exporter_tls_server_config: | ||
cert_file: /etc/apache_exporter/tls.cert | ||
key_file: /etc/apache_exporter/tls.key | ||
apache_exporter_http_server_config: | ||
http2: true | ||
apache_exporter_basic_auth_users: | ||
randomuser: examplepassword | ||
apache_exporter_version: 1.0.8 |
61 changes: 61 additions & 0 deletions
61
roles/apache_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,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_directories(host): | ||
dirs = [ | ||
"/etc/apache_exporter" | ||
] | ||
for dir in dirs: | ||
d = host.file(dir) | ||
assert d.is_directory | ||
assert d.exists | ||
|
||
|
||
def test_files(host): | ||
files = [ | ||
"/etc/systemd/system/apache_exporter.service", | ||
"//usr/local/bin/apache_exporter" | ||
] | ||
for file in files: | ||
f = host.file(file) | ||
assert f.exists | ||
assert f.is_file | ||
|
||
|
||
def test_user(host): | ||
assert host.group("apache-exp").exists | ||
assert "apache-exp" in host.user("apache-exp").groups | ||
assert host.user("apache-exp").shell == "/usr/sbin/nologin" | ||
|
||
|
||
def test_service(host): | ||
s = host.service("apache_exporter") | ||
try: | ||
assert s.is_running | ||
except AssertionError: | ||
# Capture service logs | ||
journal_output = host.run('journalctl -u apache_exporter --since "1 hour ago"') | ||
print("\n==== journalctl -u apache_exporter Output ====\n") | ||
print(journal_output) | ||
print("\n============================================\n") | ||
raise # Re-raise the original assertion error | ||
|
||
|
||
def test_protecthome_property(host): | ||
s = host.service("apache_exporter") | ||
p = s.systemd_properties | ||
assert p.get("ProtectHome") == "yes" | ||
|
||
|
||
def test_socket(host): | ||
sockets = [ | ||
"tcp://127.0.0.1:9118" | ||
] | ||
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: | ||
apache_exporter_web_listen_address: "127.0.0.1:9117" |
61 changes: 61 additions & 0 deletions
61
roles/apache_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_directories(host): | ||
dirs = [ | ||
"/etc/apache_exporter" | ||
] | ||
for dir in dirs: | ||
d = host.file(dir) | ||
assert d.is_directory | ||
assert d.exists | ||
|
||
|
||
def test_files(host): | ||
files = [ | ||
"/etc/systemd/system/apache_exporter.service", | ||
"//usr/local/bin/apache_exporter" | ||
] | ||
for file in files: | ||
f = host.file(file) | ||
assert f.exists | ||
assert f.is_file | ||
|
||
|
||
def test_user(host): | ||
assert host.group("apache-exp").exists | ||
assert "apache-exp" in host.user("apache-exp").groups | ||
assert host.user("apache-exp").shell == "/usr/sbin/nologin" | ||
|
||
|
||
def test_service(host): | ||
s = host.service("apache_exporter") | ||
try: | ||
assert s.is_running | ||
except AssertionError: | ||
# Capture service logs | ||
journal_output = host.run('journalctl -u apache_exporter --since "1 hour ago"') | ||
print("\n==== journalctl -u apache_exporter Output ====\n") | ||
print(journal_output) | ||
print("\n============================================\n") | ||
raise # Re-raise the original assertion error | ||
|
||
|
||
def test_protecthome_property(host): | ||
s = host.service("apache_exporter") | ||
p = s.systemd_properties | ||
assert p.get("ProtectHome") == "yes" | ||
|
||
|
||
def test_socket(host): | ||
sockets = [ | ||
"tcp://127.0.0.1:9117" | ||
] | ||
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: | ||
apache_exporter_version: latest |
Oops, something went wrong.