Skip to content
This repository was archived by the owner on Mar 9, 2024. It is now read-only.

Commit 4a73487

Browse files
committed
first version passing CI tests
1 parent 7a91731 commit 4a73487

File tree

12 files changed

+163
-12
lines changed

12 files changed

+163
-12
lines changed

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,22 @@
88

99
## Description
1010

11-
Deploy [process_exporter](https://github.com/ncabatoff/process_exporter) using ansible.
11+
Deploy [process_exporter](https://github.com/ncabatoff/process-exporter) using ansible.
1212

1313
## Requirements
1414

15-
- Ansible >= 2.5 (It might work on previous versions, but we cannot guarantee it)
15+
- Ansible >= 2.6 (It might work on previous versions, but we cannot guarantee it)
1616

1717
## Role Variables
1818

1919
All variables which can be overridden are stored in [defaults/main.yml](defaults/main.yml) file as well as in table below.
2020

2121
| Name | Default Value | Description |
2222
| -------------- | ------------- | -----------------------------------|
23+
| `process_exporter_version` | "0.5.0" | Process exporter package version. Also accepts latest as parameter |
2324
| `process_exporter_web_listen_address` | "0.0.0.0:9256" | Address on which process_exporter will listen |
25+
| `process_exporter_config_dir` | "/etc/process_exporter" | Path to directory with process_exporter configuration |
26+
| `process_exporter_names` | [] | Processes which should be monitored. Syntax is the same as in https://github.com/ncabatoff/process-exporter#using-a-config-file |
2427

2528
## Example
2629

@@ -33,10 +36,6 @@ Use it in a playbook as follows:
3336
- cloudalchemy.process_exporter
3437
```
3538
36-
### Demo site
37-
38-
We provide demo site for full monitoring solution based on prometheus and grafana. Repository with code and links to running instances is [available on github](https://github.com/cloudalchemy/demo-site) and site is hosted on [DigitalOcean](https://digitalocean.com).
39-
4039
## Local Testing
4140
4241
The preferred way of locally testing the role is to use Docker and [molecule](https://github.com/metacloud/molecule) (v2.x). You will have to install Docker on your system. See "Get started" for a Docker package suitable to for your system.
@@ -50,7 +49,7 @@ tox
5049
```
5150
To run a custom molecule command on custom environment with only default test scenario:
5251
```sh
53-
tox -e py27-ansible25 -- molecule test -s default
52+
tox -e py27-ansible28 -- molecule test -s default
5453
```
5554
For more information about molecule go to their [docs](http://molecule.readthedocs.io/en/latest/).
5655

defaults/main.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
---
2+
process_exporter_version: "0.5.0"
3+
24
process_exporter_web_listen_address: "0.0.0.0:9256"
5+
6+
process_exporter_config_dir: '/etc/process_exporter'
7+
8+
# Process names
9+
process_exporter_names: []

meta/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ galaxy_info:
1919
- 7
2020
- name: Fedora
2121
versions:
22-
- 30
22+
- 27
2323
galaxy_tags:
2424
- monitoring
2525

molecule/default/molecule.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ platforms:
3737
volumes:
3838
- /sys/fs/cgroup:/sys/fs/cgroup:ro
3939
- name: fedora
40-
image: paulfantom/fedora-molecule:30
40+
image: paulfantom/fedora-molecule:27
4141
docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}"
4242
privileged: true
4343
volumes:

molecule/default/tests/test_default.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,20 @@
55
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
66

77

8+
def test_directories(host):
9+
dirs = [
10+
"/etc/process_exporter"
11+
]
12+
for dir in dirs:
13+
d = host.file(dir)
14+
assert d.is_directory
15+
assert d.exists
16+
17+
818
def test_files(host):
919
files = [
1020
"/etc/systemd/system/process_exporter.service",
21+
"/usr/local/bin/process_exporter",
1122
]
1223
for file in files:
1324
f = host.file(file)

tasks/configure.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,25 @@
77
group: root
88
mode: 0644
99
notify: restart process_exporter
10+
11+
- name: Create/Update configuration file
12+
copy:
13+
dest: "{{ process_exporter_config_dir }}/config.yml"
14+
content: |
15+
process_names:
16+
{{ process_exporter_names | to_nice_yaml }}
17+
backup: false
18+
owner: root
19+
mode: 0640
20+
when:
21+
- process_exporter_names != []
22+
23+
- name: Allow process_exporter port in SELinux on RedHat OS family
24+
seport:
25+
ports: "{{ process_exporter_web_listen_address.split(':')[-1] }}"
26+
proto: tcp
27+
setype: http_port_t
28+
state: present
29+
when:
30+
- ansible_version.full is version_compare('2.4', '>=')
31+
- ansible_selinux.status == "enabled"

tasks/install.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
---
2+
- name: Install dependencies
3+
package:
4+
name: "{{ item }}"
5+
state: present
6+
register: _install_dep_packages
7+
until: _install_dep_packages is success
8+
retries: 5
9+
delay: 2
10+
with_items: "{{ process_exporter_dependencies }}"
11+
212
- name: Create the process_exporter group
313
group:
414
name: "{{ process_exporter_system_group }}"
@@ -14,3 +24,49 @@
1424
system: true
1525
createhome: false
1626
home: /
27+
28+
- name: create prometheus data directory
29+
file:
30+
path: "{{ process_exporter_config_dir }}"
31+
state: directory
32+
owner: "{{ process_exporter_system_user }}"
33+
group: "{{ process_exporter_system_group }}"
34+
mode: 0755
35+
36+
- name: Download process_exporter binary to local folder
37+
become: false
38+
get_url:
39+
url: "https://github.com/ncabatoff/process-exporter/releases/download/v{{ process_exporter_version }}/process-exporter-{{ process_exporter_version }}.linux-{{ go_arch }}.tar.gz"
40+
dest: "/tmp/process-exporter-{{ process_exporter_version }}.linux-{{ go_arch }}.tar.gz"
41+
checksum: "sha256:{{ process_exporter_checksum }}"
42+
register: _download_binary
43+
until: _download_binary is succeeded
44+
retries: 5
45+
delay: 2
46+
delegate_to: localhost
47+
check_mode: false
48+
49+
- name: Unpack process_exporter binary
50+
become: false
51+
unarchive:
52+
src: "/tmp/process-exporter-{{ process_exporter_version }}.linux-{{ go_arch }}.tar.gz"
53+
dest: "/tmp"
54+
creates: "/tmp/process-exporter-{{ process_exporter_version }}.linux-{{ go_arch }}/process-exporter"
55+
delegate_to: localhost
56+
check_mode: false
57+
58+
- name: Create /usr/local/bin
59+
file:
60+
path: /usr/local/bin
61+
state: directory
62+
mode: 0755
63+
64+
- name: Propagate process_exporter binaries
65+
copy:
66+
src: "/tmp/process-exporter-{{ process_exporter_version }}.linux-{{ go_arch }}/process-exporter"
67+
dest: "/usr/local/bin/process_exporter"
68+
mode: 0755
69+
owner: root
70+
group: root
71+
notify: restart process_exporter
72+
when: not ansible_check_mode

tasks/preflight.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,50 @@
33
fail:
44
msg: "This module only works with systemd"
55
when: ansible_service_mgr != 'systemd'
6+
7+
- name: Get systemd version
8+
command: systemctl --version
9+
changed_when: false
10+
check_mode: false
11+
register: __systemd_version
12+
tags:
13+
- skip_ansible_lint
14+
15+
- name: Naive assertion of proper listen address
16+
assert:
17+
that:
18+
- "':' in process_exporter_web_listen_address"
19+
20+
- block:
21+
- name: Get latest release
22+
uri:
23+
url: "https://api.github.com/repos/ncabatoff/process-exporter/releases/latest"
24+
method: GET
25+
return_content: true
26+
status_code: 200
27+
body_format: json
28+
validate_certs: false
29+
user: "{{ lookup('env', 'GH_USER') | default(omit) }}"
30+
password: "{{ lookup('env', 'GH_TOKEN') | default(omit) }}"
31+
no_log: true
32+
register: _latest_release
33+
until: _latest_release.status == 200
34+
retries: 5
35+
36+
- name: "Set process_exporter version to {{ _latest_release.json.tag_name[1:] }}"
37+
set_fact:
38+
process_exporter_version: "{{ _latest_release.json.tag_name[1:] }}"
39+
when: process_exporter_version == "latest"
40+
delegate_to: localhost
41+
run_once: true
42+
43+
- name: Get checksum list from github
44+
set_fact:
45+
_checksums: "{{ lookup('url', 'https://github.com/ncabatoff/process-exporter/releases/download/v' + process_exporter_version + '/' + 'process-exporter_' + process_exporter_version + '_checksums.txt', wantlist=True) | list }}"
46+
run_once: true
47+
48+
- name: "Get checksum for {{ go_arch }} architecture"
49+
set_fact:
50+
process_exporter_checksum: "{{ item.split(' ')[0] }}"
51+
with_items: "{{ _checksums }}"
52+
when: "('linux-' + go_arch + '.tar.gz') in item"

templates/process_exporter.service.j2

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
{{ ansible_managed | comment }}
22

33
[Unit]
4-
Description=process_exporter
4+
Description=Process Exporter for Prometheus
55
After=network-online.target
66
StartLimitInterval=0
77

88
[Service]
99
Type=simple
1010
User={{ process_exporter_system_user }}
1111
Group={{ process_exporter_system_group }}
12-
ExecStart=/usr/local/bin/process_exporter
12+
ExecStart=/usr/local/bin/process_exporter \
13+
{% if process_exporter_names != [] -%}
14+
--config.path {{ process_exporter_config_dir }}/config.yaml \
15+
{% endif -%}
16+
--web.listen-address={{ process_exporter_web_listen_address }}
17+
1318
SyslogIdentifier=process_exporter
1419
Restart=always
1520
RestartSec=1

vars/debian.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
---
2+
process_exporter_dependencies: []

0 commit comments

Comments
 (0)