Skip to content

Commit

Permalink
Add Option to enable Prometheus Textfile Collector
Browse files Browse the repository at this point in the history
  • Loading branch information
0x46616c6b committed Mar 30, 2023
1 parent eb36ee6 commit 5912533
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 2 deletions.
4 changes: 4 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ userli_env_vars:
- name: WKD_FORMAT
value: "{{ userli_wkd_format }}"

userli_prometheus_textfile_collector_enabled: False
userli_prometheus_textfile_collector_path: "/var/lib/prometheus/node-exporter/textfile_collector"
userli_prometheus_textfile_collector_on_calendar: "*-*-* *:*:00"

# munin integration
userli_munin: false

Expand Down
13 changes: 12 additions & 1 deletion handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---

- name: restart munin-node
service:
name: munin-node
Expand All @@ -26,3 +25,15 @@
service:
name: "{{ userli_webserver }}"
state: restarted

- name: reload systemd daemon
systemd:
daemon_reload: true

- name: restart userli-collector
service:
name: "{{ item }}"
state: restarted
loop:
- userli-collector.service
- userli-collector.timer
3 changes: 2 additions & 1 deletion molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
---

- name: Converge
hosts: all
become: true
roles:
- ansible-role-userli
vars:
userli_mysql_password: userli
userli_munin: true
userli_prometheus_textfile_collector_enabled: True
4 changes: 4 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@
- import_tasks: deployment.yml
when: userli_update|bool

- import_tasks: metrics.yml
when: userli_prometheus_textfile_collector_enabled|bool
tags: metrics

- import_tasks: munin.yml
when: userli_munin|bool
tags: munin
23 changes: 23 additions & 0 deletions tasks/metrics.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
- name: Copy Textfile Collector Service
ansible.builtin.template:
src: "{{ item }}.j2"
dest: "/etc/systemd/system/{{ item }}"
owner: root
group: root
mode: 0644
notify:
- reload systemd daemon
- restart userli-collector
loop:
- userli-collector.service
- userli-collector.timer

- name: Enable Textfile Collector Service
ansible.builtin.systemd:
name: "{{ item }}"
enabled: yes
state: started
loop:
- userli-collector.service
- userli-collector.timer
13 changes: 13 additions & 0 deletions templates/userli-collector.service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
Description=Userli Prometheus Textfile Collector
After=systemd-modules-load.service
DefaultDependencies=no

[Service]
Type=oneshot
User={{ userli_user }}
ExecStart=/bin/bash -c 'php {{ userli_symfony_path }}/bin/console app:metrics | sponge {{ userli_prometheus_textfile_collector_path }}/userli.prom'
SyslogIdentifier=userli-textfile-collector

[Install]
WantedBy=multi-user.target
9 changes: 9 additions & 0 deletions templates/userli-collector.timer.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=Userli Prometheus Textfile Collector Timer

[Timer]
OnCalendar={{ userli_prometheus_textfile_collector_on_calendar }}
Persistent=true

[Install]
WantedBy=timers.target

0 comments on commit 5912533

Please sign in to comment.