Skip to content

Commit

Permalink
Merge pull request #45 from systemli/add-option-for-textfile-collector
Browse files Browse the repository at this point in the history
Add Option to enable Prometheus Textfile Collector
  • Loading branch information
0x46616c6b authored Apr 7, 2024
2 parents e14f4d0 + adbda17 commit 6e006c9
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 11 deletions.
10 changes: 7 additions & 3 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ userli_wkd_directory: "/var/www/html"
userli_wkd_format: "advanced" # or 'advanced' or 'direct'

# to trigger a deployment or initial rollout use "-e userli_update=True" in command line
userli_update: false
userli_update: False

# extra reserved local parts
userli_extra_reserved_names: []
Expand All @@ -31,10 +31,14 @@ 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"
userli_prometheus_textfile_collector_on_calendar: "*-*-* *:*:00"

# munin integration
userli_munin: false
userli_munin: False

userli_primary: true
userli_primary: True
userli_webserver: apache2

# Set default language for navbar
Expand Down
12 changes: 12 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,15 @@
ansible.builtin.service:
name: "{{ userli_webserver }}"
state: restarted

- name: Reload systemd daemon
ansible.builtin.systemd:
daemon_reload: true

- name: Restart userli-collector
ansible.builtin.service:
name: "{{ item }}"
state: restarted
loop:
- userli-collector.service
- userli-collector.timer
1 change: 0 additions & 1 deletion molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---

- name: Converge
hosts: all
become: true
Expand Down
7 changes: 3 additions & 4 deletions molecule/default/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
become: true
pre_tasks:
- name: Run the equivalent of "apt-get update" before installing packages
apt:
ansible.builtin.apt:
update_cache: yes

- name: Install cron for testing in docker containers
apt:
ansible.builtin.apt:
pkg: cron
update_cache: yes
roles:
- weareinteractive.apt
- geerlingguy.apache
Expand All @@ -25,7 +24,7 @@
extra_parameters: |
SetEnv APP_ENV prod
apt_packages:
- acl # support for unpriviledged become_user
- acl # support for unpriviledged become_user
- unzip
php_default_version_debian: "{% if ansible_distribution_release == 'bullseye' %}7.4{% else %}8.2{% endif %}"
php_packages:
Expand Down
1 change: 0 additions & 1 deletion molecule/default/requirements.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---

roles:
- name: weareinteractive.apt
- name: geerlingguy.apache
Expand Down
1 change: 0 additions & 1 deletion requirements.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---

collections:
- community.general
- community.mysql
5 changes: 4 additions & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,7 @@
- name: Import Munin tasks
ansible.builtin.import_tasks: munin.yml
when: userli_munin | bool
tags: munin

- name: Import metrics tasks
ansible.builtin.import_tasks: metrics.yml
when: userli_prometheus_textfile_collector_enabled | bool
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
12 changes: 12 additions & 0 deletions templates/userli-collector.service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=Userli Prometheus Textfile Collector
After=systemd-modules-load.service
DefaultDependencies=no

[Service]
Type=oneshot
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 6e006c9

Please sign in to comment.