aboutsummaryrefslogtreecommitdiffstats
path: root/ansible/roles/munin-node
diff options
context:
space:
mode:
Diffstat (limited to 'ansible/roles/munin-node')
-rw-r--r--ansible/roles/munin-node/defaults/main.yml3
-rw-r--r--ansible/roles/munin-node/handlers/main.yml7
-rw-r--r--ansible/roles/munin-node/tasks/main.yml74
-rw-r--r--ansible/roles/munin-node/templates/munin-node.conf.j261
-rw-r--r--ansible/roles/munin-node/templates/plugin.conf.j215
-rw-r--r--ansible/roles/munin-node/templates/plugins/ldap01/.gitkeep0
-rw-r--r--ansible/roles/munin-node/templates/plugins/lovelace/dovecot_maildirs.sh.j264
-rw-r--r--ansible/roles/munin-node/templates/plugins/lovelace/lovering_inheritance.py.j267
8 files changed, 291 insertions, 0 deletions
diff --git a/ansible/roles/munin-node/defaults/main.yml b/ansible/roles/munin-node/defaults/main.yml
new file mode 100644
index 0000000..60e2230
--- /dev/null
+++ b/ansible/roles/munin-node/defaults/main.yml
@@ -0,0 +1,3 @@
+---
+munin_node__plugin_packages: "{{ ('databases' in group_names) | ternary(['libdbd-pg-perl'], []) }}"
+munin_node__plugins: []
diff --git a/ansible/roles/munin-node/handlers/main.yml b/ansible/roles/munin-node/handlers/main.yml
new file mode 100644
index 0000000..cf8e23d
--- /dev/null
+++ b/ansible/roles/munin-node/handlers/main.yml
@@ -0,0 +1,7 @@
+---
+- name: Restart munin-node service
+ service:
+ name: munin-node
+ state: restarted
+ tags:
+ - role::munin-node
diff --git a/ansible/roles/munin-node/tasks/main.yml b/ansible/roles/munin-node/tasks/main.yml
new file mode 100644
index 0000000..9c9026e
--- /dev/null
+++ b/ansible/roles/munin-node/tasks/main.yml
@@ -0,0 +1,74 @@
+---
+- name: Install munin-node & plugin packages
+ package:
+ name: "{{ ['munin-node'] + munin_node__plugin_packages }}"
+ state: present
+ tags:
+ - role::munin-node
+
+- name: Template munin-node configuration file
+ template:
+ src: munin-node.conf.j2
+ dest: /etc/munin/munin-node.conf
+ owner: root
+ group: root
+ mode: "0444"
+ tags:
+ - role::munin-node
+ notify:
+ - Restart munin-node service
+
+- name: Template munin plugin configuration file
+ template:
+ src: plugin.conf.j2
+ dest: /etc/munin/plugin-conf.d/custom
+ owner: root
+ group: root
+ mode: "0444"
+ tags:
+ - role::munin-node
+ notify:
+ - Restart munin-node service
+
+- name: Enable non-default munin plugins
+ file:
+ src: "/usr/share/munin/plugins/{{ item.src }}"
+ dest: "/etc/munin/plugins/{{ item.dest | default(item.src) }}"
+ state: link
+ loop: "{{ munin_node__plugins }}"
+ tags:
+ - role::munin-node
+ notify:
+ - Restart munin-node service
+
+- name: Copy custom munin plugins
+ template:
+ src: "{{ item }}"
+ # Split two levels of file extensions
+ dest: "/etc/munin/plugins/{{ item | basename | splitext | first | splitext | first }}"
+ owner: root
+ group: root
+ mode: "0555"
+ loop_control:
+ # I love representing data modification logic in YAML!
+ label: "{{ item | basename | splitext | first | splitext | first }}"
+ with_fileglob: "../templates/plugins/{{ ansible_hostname }}/*"
+ tags:
+ - role::munin-node
+
+- name: Disable some unneeded plugins
+ file:
+ path: "/etc/munin/plugins/{{ item }}"
+ state: absent
+ loop:
+ - squeezebox_albums
+ - squeezebox_artists
+ - squeezebox_genres
+ - squeezebox_signalstrength
+ - squeezebox_songs
+ - squeezebox_volume
+ - squeezebox_years
+ tags:
+ - role::munin-node
+ notify:
+ - Restart munin-node service
diff --git a/ansible/roles/munin-node/templates/munin-node.conf.j2 b/ansible/roles/munin-node/templates/munin-node.conf.j2
new file mode 100644
index 0000000..4e89883
--- /dev/null
+++ b/ansible/roles/munin-node/templates/munin-node.conf.j2
@@ -0,0 +1,61 @@
+# Managed by Ansible
+
+log_level 4
+log_file /var/log/munin/munin-node.log
+pid_file /var/run/munin/munin-node.pid
+
+background 1
+setsid 1
+
+user root
+group root
+
+# This is the timeout for the whole transaction.
+# Units are in sec. Default is 15 min
+#
+# global_timeout 900
+
+# This is the timeout for each plugin.
+# Units are in sec. Default is 1 min
+#
+# timeout 60
+
+# Regexps for files to ignore
+ignore_file [\#~]$
+ignore_file DEADJOE$
+ignore_file \.bak$
+ignore_file %$
+ignore_file \.dpkg-(tmp|new|old|dist)$
+ignore_file \.rpm(save|new)$
+ignore_file \.pod$
+
+# Set this if the client doesn't report the correct hostname when
+# telnetting to localhost, port 4949
+#
+host_name {{ ansible_fqdn }}
+
+# A list of addresses that are allowed to connect. This must be a
+# regular expression, since Net::Server does not understand CIDR-style
+# network notation unless the perl module Net::CIDR is installed. You
+# may repeat the allow line as many times as you'd like
+
+allow ^127\.0\.0\.1$
+allow ^::1$
+
+# If you have installed the Net::CIDR perl module, you can use one or more
+# cidr_allow and cidr_deny address/mask patterns. A connecting client must
+# match any cidr_allow, and not match any cidr_deny. Note that a netmask
+# *must* be provided, even if it's /32
+#
+# Example:
+#
+# cidr_allow 127.0.0.1/32
+# cidr_allow 192.0.2.0/24
+# cidr_deny 192.0.2.42/32
+
+# Which address to bind to;
+# host *
+host 127.0.0.1
+
+# And which port
+port 4949
diff --git a/ansible/roles/munin-node/templates/plugin.conf.j2 b/ansible/roles/munin-node/templates/plugin.conf.j2
new file mode 100644
index 0000000..9d2c74c
--- /dev/null
+++ b/ansible/roles/munin-node/templates/plugin.conf.j2
@@ -0,0 +1,15 @@
+# Ansible managed
+
+[dovecot_maildirs]
+user root
+group vmail
+
+[load]
+env.load_warning {{ ansible_processor_nproc * 0.7 }}
+env.load_critical {{ ansible_processor_nproc * 0.85 }}
+
+[memory]
+env.apps_warning 70%
+env.apps_critical 90%
+env.swap_warning 60%
+env.swap_critical 80%
diff --git a/ansible/roles/munin-node/templates/plugins/ldap01/.gitkeep b/ansible/roles/munin-node/templates/plugins/ldap01/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/ansible/roles/munin-node/templates/plugins/ldap01/.gitkeep
diff --git a/ansible/roles/munin-node/templates/plugins/lovelace/dovecot_maildirs.sh.j2 b/ansible/roles/munin-node/templates/plugins/lovelace/dovecot_maildirs.sh.j2
new file mode 100644
index 0000000..b634df3
--- /dev/null
+++ b/ansible/roles/munin-node/templates/plugins/lovelace/dovecot_maildirs.sh.j2
@@ -0,0 +1,64 @@
+#!/bin/sh
+# Ansible managed
+
+cd /var/vmail || exit 1
+
+print_maildir_config() {
+ find . -maxdepth 1 -type d \
+ | tail -n +2 \
+ | awk -F / '{
+ print $2 ".draw AREASTACK"
+ print $2 ".label " $2
+ }'
+}
+
+if [ "$1" = "autoconf" ]; then
+ echo "no"
+ exit
+fi
+
+if [ "$1" = "config" ]; then
+ cat <<EOF
+multigraph dovecot_maildir_sizes
+graph_title Dovecot Maildir sizes
+graph_args --base 1024 -l 0
+graph_vlabel bytes
+graph_category mail
+graph_info Shows the sizes of top mail directories by their respective users
+graph_total Total
+graph_order joe jc
+EOF
+ print_maildir_config
+ cat <<EOF
+multigraph dovecot_maildir_mails
+graph_title Dovecot mails in maildirs
+graph_args --base 1000 -l 0
+graph_vlabel mails
+graph_category mail
+graph_info Shows the amount of mails by user on our Dovecot server
+graph_total Total
+graph_order joe jc
+EOF
+ print_maildir_config
+ exit 0
+fi
+
+echo "multigraph dovecot_maildir_sizes"
+du --bytes --summarize -- * \
+ | awk '{ print $2 ".value " $1 }'
+
+echo "multigraph dovecot_maildir_mails"
+find . \
+ | awk -F / '
+ # Maildir e-mails have the hostname contained in them
+ $0 ~ "{{ ansible_fqdn }}" {
+ total[$2] += 1
+ }
+ END {
+ for (user in total) {
+ print user ".value " total[user]
+ }
+ }
+ '
+
+# vim: ft=sh.jinja2:
diff --git a/ansible/roles/munin-node/templates/plugins/lovelace/lovering_inheritance.py.j2 b/ansible/roles/munin-node/templates/plugins/lovelace/lovering_inheritance.py.j2
new file mode 100644
index 0000000..4e6d315
--- /dev/null
+++ b/ansible/roles/munin-node/templates/plugins/lovelace/lovering_inheritance.py.j2
@@ -0,0 +1,67 @@
+#!/usr/bin/env python3
+# Ansible managed
+
+import datetime
+import random
+import sys
+
+if sys.argv[-1] == "autoconf":
+ print("no")
+ sys.exit(0)
+
+if sys.argv[-1] == "config":
+
+ print("""\
+graph_title Lovering Inheritance
+graph_args --base 1000 -l 0
+graph_vlabel £
+graph_category people
+graph_info This graph shows the insurance that Chris can cash out.
+graph_total Total
+savings.label Savings
+savings.info Base inheritance money Chris paid into his account in 2024
+savings.draw AREASTACK
+interest.label Interest
+interest.info Amount of money gained from interest on the base amount
+interest.draw AREASTACK
+inherited.label Inherited money
+inherited.info Amount inherited from deaths of friends, family and victims
+inherited.draw AREASTACK\
+ """)
+ sys.exit(0)
+
+# Fixed seed to ensure that the bank jitter is constant
+random.seed(1234)
+today = datetime.date.today()
+savings = 740
+interest_per_day = 0.005
+insurance_policy_start = datetime.date(2024, 8, 28)
+days_griefed = (today - insurance_policy_start).days
+accrued_interest = 0
+for _ in range(days_griefed):
+ bank_jitter = random.random()
+ accrued_interest += bank_jitter * (interest_per_day * (savings + accrued_interest))
+
+inherited_money = 0
+
+if days_griefed > 10:
+ # Hassan declared as KIA (he had stocks in Big Oil)
+ inherited_money += 10000
+
+if days_griefed > 60:
+ # Death of Joe (prospect of sale of stolen GPUs)
+ inherited_money += 5000
+
+if days_griefed > 170:
+ # Bella disappears (spent all on chicken and gifts for his wife)
+ inherited_money += 300
+
+if days_griefed > 360:
+ # Lola Banks deploys her Titan missile but burns herself to death
+ inherited_money += 12000
+
+print(f"savings.value {savings}")
+print(f"interest.value {accrued_interest}")
+print(f"inherited.value {inherited_money}")
+
+# vim: ft=python.jinja2: