From d3444193c2051aedaf3747d578cec1e89f307a48 Mon Sep 17 00:00:00 2001 From: Philippe MILINK Date: Sun, 5 Jan 2025 23:00:12 +0100 Subject: [PATCH] Ajoute des graphes Munin pour la taille de certains dossiers --- roles/munin/files/plugins/du_ | 70 +++++++++++++++++++ roles/munin/tasks/main.yml | 41 ++++++++++- .../templates/plugin-conf.d/du_backup.j2 | 5 ++ .../munin/templates/plugin-conf.d/du_prod.j2 | 12 ++++ 4 files changed, 125 insertions(+), 3 deletions(-) create mode 100755 roles/munin/files/plugins/du_ create mode 100644 roles/munin/templates/plugin-conf.d/du_backup.j2 create mode 100644 roles/munin/templates/plugin-conf.d/du_prod.j2 diff --git a/roles/munin/files/plugins/du_ b/roles/munin/files/plugins/du_ new file mode 100755 index 0000000..fce95b1 --- /dev/null +++ b/roles/munin/files/plugins/du_ @@ -0,0 +1,70 @@ +#!/bin/bash + +: <<=cut + +=head1 NAME + +du - Size of directories + +=head1 CONFIGURATION + +Put this file in "/usr/local/share/munin/plugins/du_". Then, create a symbolic +link to this file called, for instance, "du_work". "work" will be the name of +the graph. + +The configuration should look like the following: + +[du_work] + env.directories /path/to/dir1 /path/to/dir2 + env.prefix /path/to/ + env.critical 1073741824 + +- "directories" contains a space-separated list of directories to report size of. +- "prefix" (optionnal) is the prefix of directories to hide in graph labels. +- "critical" (optionnal) is the critical size (in bytes) for all directories. + +=cut + +GRAPH_NAME=${0##*du_} +DIRECTORIES=${directories:-UNSET} +CRITICAL=${critical:-UNSET} +PREFIX=${prefix:-UNSET} + + +case $1 in + config) + echo "graph_title Directory size $GRAPH_NAME" + echo "graph_category disk" + echo "graph_args --base 1024 -l 0" + echo "graph_vlabel Size" + echo "graph_info Graph of size occupied by directories" + + if [ "$DIRECTORIES" != "UNSET" ]; then + for d in $DIRECTORIES + do + slug=$(echo $d | sed 's/\//_/g') + + if [ "$PREFIX" != "UNSET" ]; then + echo "${slug}.label ${d#"$PREFIX"}" + else + echo "${slug}.label $d" + fi + echo "${slug}.type GAUGE" + echo "${slug}.draw LINE1" + + if [ "$CRITICAL" != "UNSET" ]; then + echo "${slug}.critical $CRITICAL" + fi + done + fi + + exit 0;; +esac + +if [ "$DIRECTORIES" != "UNSET" ]; then + for d in $DIRECTORIES + do + slug=$(echo $d | sed 's/\//_/g') + echo "${slug}.value $(du -sb $d | cut -f 1)" + done +fi diff --git a/roles/munin/tasks/main.yml b/roles/munin/tasks/main.yml index c367e91..25ebca0 100644 --- a/roles/munin/tasks/main.yml +++ b/roles/munin/tasks/main.yml @@ -73,11 +73,14 @@ dest: "{{ munin_available_plugins_dir }}/zmd" mode: u=rwx,g=rx,o=rx -- name: copy typesense munin plugin +- name: copy typesense and du_ munin plugin ansible.builtin.copy: - src: plugins/typesense - dest: "{{ munin_available_plugins_dir }}/typesense" + src: "plugins/{{ item }}" + dest: "{{ munin_available_plugins_dir }}/{{ item }}" mode: u=rwx,g=rx,o=rx + with_items: + - typesense + - du_ - name: create symlinks for munin plugins ansible.builtin.file: @@ -104,6 +107,24 @@ - { src: postfix_mailvolume, dest: postfix_mailvolume } when: installed_postfix_check is succeeded +- name: create symlink to du_backup munin plugin for beta server + ansible.builtin.file: + src: "{{ munin_available_plugins_dir }}/du_" + dest: /etc/munin/plugins/du_backup + state: link + when: env == "beta" + +- name: create symlink to du_ munin plugins for prod server + ansible.builtin.file: + src: "{{ munin_available_plugins_dir }}/du_" + dest: "/etc/munin/plugins/du_{{ item }}" + state: link + with_items: + - mysql-backup + - zds-data + - zds-db + when: env == "prod" + - name: copy configuration file of wget_page munin plugin ansible.builtin.template: src: plugin-conf.d/wget_page.j2 @@ -122,3 +143,17 @@ regexp: ^env.mysqluser root line: env.mysqluser root when: env == "beta" + +- name: copy configuration file of du_backup munin plugin for beta server + ansible.builtin.template: + src: plugin-conf.d/du_backup.j2 + dest: /etc/munin/plugin-conf.d/du_backup + mode: u=rw,g=r,o=r + when: env == "beta" + +- name: copy configuration file of du_munin plugins for prod server + ansible.builtin.template: + src: plugin-conf.d/du_prod.j2 + dest: /etc/munin/plugin-conf.d/du + mode: u=rw,g=r,o=r + when: env == "prod" diff --git a/roles/munin/templates/plugin-conf.d/du_backup.j2 b/roles/munin/templates/plugin-conf.d/du_backup.j2 new file mode 100644 index 0000000..703caee --- /dev/null +++ b/roles/munin/templates/plugin-conf.d/du_backup.j2 @@ -0,0 +1,5 @@ +[du_backup] +user root +env.directories {{ backupdir }}/data {{ backupdir }}/db {{ backupdir }}/matomo {{ backupdir }}/vaultwarden +env.prefix {{ backupdir }}/ +env.critical 161061273600 # 150 Go diff --git a/roles/munin/templates/plugin-conf.d/du_prod.j2 b/roles/munin/templates/plugin-conf.d/du_prod.j2 new file mode 100644 index 0000000..e558b3e --- /dev/null +++ b/roles/munin/templates/plugin-conf.d/du_prod.j2 @@ -0,0 +1,12 @@ +[du_mysql-backup] +user root +env.directories /var/backups/mysql + +[du_zds-data] +user root +env.directories {{ datadir }}/contents-private {{ datadir }}/contents-public {{ datadir }}/media {{ datadir }}/static +env.prefix {{ datadir }} + +[du_zds-db] +user root +env.directories /var/lib/mysql/prod