Skip to content

Commit a041d4d

Browse files
committed
change ffshmon to run as service and now exports metrics to prometheus
1 parent 37beb95 commit a041d4d

7 files changed

Lines changed: 133 additions & 9 deletions

File tree

‎roles/ffshmon/handlers/main.yml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- name: Restart ffshmon service
2+
ansible.builtin.systemd:
3+
daemon_reload: true
4+
name: ffshmon
5+
state: restarted

‎roles/ffshmon/tasks/install.yml‎

Lines changed: 78 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,89 @@
1-
- name: Install curl
1+
- name: Install ffshmon dependencies
22
ansible.builtin.apt:
3-
name: ['curl']
3+
name: ["curl", "python3-venv", "python3-pip", "sudo", "logrotate"]
4+
- name: Add ffshmon system user
5+
ansible.builtin.user:
6+
name: ffshmon
7+
system: true
8+
create_home: false
9+
shell: /usr/sbin/nologin
410
- name: Create log directory
511
ansible.builtin.file:
612
path: /var/log/ffshmon
713
state: directory
8-
mode: '0755'
14+
owner: ffshmon
15+
group: ffshmon
16+
mode: "0755"
17+
- name: Create ffshmon log file
18+
ansible.builtin.file:
19+
path: /var/log/ffshmon/ffshmon.log
20+
state: touch
21+
owner: ffshmon
22+
group: ffshmon
23+
mode: "0640"
24+
access_time: preserve
25+
modification_time: preserve
26+
notify:
27+
- Restart ffshmon service
28+
- name: Allow root to manage ffshmon repository
29+
ansible.builtin.blockinfile:
30+
path: /etc/gitconfig
31+
create: true
32+
owner: root
33+
group: root
34+
mode: "0644"
35+
block: |
36+
[safe]
37+
directory = /opt/ffshmon
38+
marker: "# {mark} ANSIBLE MANAGED FFSHMON SAFE DIRECTORY"
939
- name: Clone ffshmon repository
1040
ansible.builtin.git:
1141
repo: https://github.com/ffsh/ffshmon.git
1242
dest: /opt/ffshmon
1343
force: true
1444
version: main
15-
- name: Trigger ffshmon regularly
16-
ansible.builtin.cron:
17-
name: "Execute ffshmon"
18-
minute: "*/30"
19-
job: "python3 /opt/ffshmon/wireguard.py check --user {{ ffshmon_mail }} --password {{ ffshmon_pw }} --log /var/log/ffshmon/ffshmon.log"
45+
- name: Install ffshmon Python dependencies
46+
ansible.builtin.pip:
47+
requirements: /opt/ffshmon/requirements.txt
48+
virtualenv: /opt/ffshmon/.venv
49+
virtualenv_command: python3 -m venv
50+
- name: Adjust ffshmon permissions
51+
ansible.builtin.file:
52+
path: /opt/ffshmon
53+
owner: ffshmon
54+
group: ffshmon
55+
recurse: true
56+
state: directory
57+
- name: Configure ffshmon sudo permissions
58+
ansible.builtin.template:
59+
src: templates/ffshmon.sudoers
60+
dest: /etc/sudoers.d/ffshmon
61+
owner: root
62+
group: root
63+
mode: "0440"
64+
validate: "visudo -cf %s"
65+
- name: Configure ffshmon log rotation
66+
ansible.builtin.template:
67+
src: templates/ffshmon.logrotate
68+
dest: /etc/logrotate.d/ffshmon
69+
owner: root
70+
group: root
71+
mode: "0644"
72+
- name: Install ffshmon service
73+
ansible.builtin.template:
74+
src: templates/ffshmon.service
75+
dest: /etc/systemd/system/ffshmon.service
76+
owner: root
77+
group: root
78+
mode: "0600"
79+
notify:
80+
- Restart ffshmon service
81+
82+
- name: Flush handlers
83+
ansible.builtin.meta: flush_handlers
84+
85+
- name: Enable ffshmon service
86+
ansible.builtin.systemd:
87+
enabled: true
88+
state: started
89+
name: ffshmon
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/var/log/ffshmon/ffshmon.log {
2+
daily
3+
rotate 7
4+
compress
5+
delaycompress
6+
missingok
7+
notifempty
8+
copytruncate
9+
create 0640 ffshmon ffshmon
10+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[Unit]
2+
Description=ffshmon WireGuard health monitor
3+
After=network-online.target
4+
Wants=network-online.target
5+
6+
[Service]
7+
Type=simple
8+
WorkingDirectory=/opt/ffshmon
9+
User=ffshmon
10+
Group=ffshmon
11+
ExecStart=/opt/ffshmon/.venv/bin/python /opt/ffshmon/wireguard.py serve --user {{ ffshmon_mail }} --password {{ ffshmon_pw }} --log /var/log/ffshmon/ffshmon.log --loglevel WARNING --host 127.0.0.1 --port 8000 --interval 300
12+
Restart=on-failure
13+
ProtectHome=true
14+
PrivateTmp=true
15+
ProtectKernelModules=true
16+
ProtectKernelLogs=true
17+
ProtectClock=true
18+
19+
[Install]
20+
WantedBy=multi-user.target
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ffshmon ALL=(root) NOPASSWD: /usr/bin/systemctl stop fastd@ffsh.service
2+
ffshmon ALL=(root) NOPASSWD: /usr/bin/systemctl show -p SubState fastd@ffsh.service
3+
ffshmon ALL=(root) NOPASSWD: /usr/bin/systemctl stop wg-quick@exit.service
4+
ffshmon ALL=(root) NOPASSWD: /usr/bin/systemctl restart wg-quick@exit.service
5+
ffshmon ALL=(root) NOPASSWD: /usr/bin/python3 /opt/wg-conf-gen/wg-conf-gen.py recreate

‎roles/nginx/templates/gw-status.conf‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ server {
2525
proxy_pass http://127.0.0.1:9100/;
2626
}
2727

28+
{% if enable_wireguard_exit | default(false) | bool %}
29+
location /ffshmon/ {
30+
proxy_pass http://127.0.0.1:8000/;
31+
}
32+
{% endif %}
33+
2834
## TLS
2935
ssl_certificate /etc/letsencrypt/live/{{ inventory_hostname }}.freifunk-suedholstein.de/fullchain.pem;
3036
ssl_certificate_key /etc/letsencrypt/live/{{ inventory_hostname }}.freifunk-suedholstein.de/privkey.pem;
@@ -39,6 +45,6 @@ server {
3945
# HSTS (ngx_http_headers_module is required) (63072000 seconds)
4046
add_header Strict-Transport-Security "max-age=63072000" always;
4147

42-
48+
4349
}
4450

‎roles/prometheus/templates/prometheus.yml.j2‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ scrape_configs:
3939
static_configs:
4040
- targets: ["beste.freifunk-suedholstein.de", "brunsbach.freifunk-suedholstein.de", "trave.freifunk-suedholstein.de"]
4141

42+
- job_name: "ffshmon"
43+
44+
metrics_path: /ffshmon/metrics
45+
scheme: https
46+
47+
static_configs:
48+
- targets: ["beste.freifunk-suedholstein.de", "brunsbach.freifunk-suedholstein.de", "trave.freifunk-suedholstein.de"]
49+
4250
- job_name: "services"
4351

4452
metrics_path: stats/metrics

0 commit comments

Comments
 (0)