Skip to content

Commit

Permalink
Ajoute des graphes Munin pour la taille de certains dossiers
Browse files Browse the repository at this point in the history
  • Loading branch information
philippemilink committed Jan 5, 2025
1 parent 10f13d7 commit d344419
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 3 deletions.
70 changes: 70 additions & 0 deletions roles/munin/files/plugins/du_
Original file line number Diff line number Diff line change
@@ -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
41 changes: 38 additions & 3 deletions roles/munin/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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"
5 changes: 5 additions & 0 deletions roles/munin/templates/plugin-conf.d/du_backup.j2
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions roles/munin/templates/plugin-conf.d/du_prod.j2
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d344419

Please sign in to comment.