From 1da49f866577899d94cc6715f18a994ad3006c6e Mon Sep 17 00:00:00 2001 From: VC Date: Fri, 5 Jul 2024 11:53:37 +0200 Subject: [PATCH] feat: add garage specific munin shell scripts --- .../munin_client/files/garage_bucket_objects | 36 +++++++++++++++++++ roles/munin_client/files/garage_bucket_size | 36 +++++++++++++++++++ .../files/garage_bucket_unfinished | 36 +++++++++++++++++++ roles/munin_client/tasks/garage.yml | 23 ++++++++++++ roles/munin_client/tasks/main.yml | 13 ++++--- roles/munin_client/templates/garage.j2 | 2 ++ 6 files changed, 142 insertions(+), 4 deletions(-) create mode 100755 roles/munin_client/files/garage_bucket_objects create mode 100755 roles/munin_client/files/garage_bucket_size create mode 100755 roles/munin_client/files/garage_bucket_unfinished create mode 100644 roles/munin_client/tasks/garage.yml create mode 100644 roles/munin_client/templates/garage.j2 diff --git a/roles/munin_client/files/garage_bucket_objects b/roles/munin_client/files/garage_bucket_objects new file mode 100755 index 0000000..1513e99 --- /dev/null +++ b/roles/munin_client/files/garage_bucket_objects @@ -0,0 +1,36 @@ +#!/bin/bash + +# Get the Header +HEADER="Authorization: Bearer ${BEARER}" + +# Create associative array +declare -A BUCKETS=() + +API_BUCKETS_JSON=$(curl -s -H "${HEADER}" "http://[::1]:3903/v0/bucket" | jq -r '.[] | .id + "," + .globalAliases[0]') + +# Populate associative array +for bucket in ${API_BUCKETS_JSON} +do + BUCKETS+=([$(echo ${bucket} | cut -d ',' -f 1)]="$(echo ${bucket} | cut -d ',' -f 2)") +done + +case $1 in + config) + cat << 'EOM' +graph_title Objects by Bucket +graph_vlabel Number of objects +graph_args --base 1000 -l 0 +graph_category garage +EOM + for i in "${!BUCKETS[@]}" + do + echo "${BUCKETS[${i}]}.label ${BUCKETS[${i}]}" + done + exit 0;; +esac + +for i in "${!BUCKETS[@]}" +do + OBJECTS=$(curl -s -H "${HEADER}" "http://[::1]:3903/v0/bucket?id=${i}" | jq -r '.objects') + echo "${BUCKETS[${i}]}.value ${OBJECTS}" +done diff --git a/roles/munin_client/files/garage_bucket_size b/roles/munin_client/files/garage_bucket_size new file mode 100755 index 0000000..2060867 --- /dev/null +++ b/roles/munin_client/files/garage_bucket_size @@ -0,0 +1,36 @@ +#!/bin/bash + +# Get the Header +HEADER="Authorization: Bearer ${BEARER}" + +# Create associative array +declare -A BUCKETS=() + +API_BUCKETS_JSON=$(curl -s -H "${HEADER}" "http://[::1]:3903/v0/bucket" | jq -r '.[] | .id + "," + .globalAliases[0]') + +# Populate associative array +for bucket in ${API_BUCKETS_JSON} +do + BUCKETS+=([$(echo ${bucket} | cut -d ',' -f 1)]="$(echo ${bucket} | cut -d ',' -f 2)") +done + +case $1 in + config) + cat << 'EOM' +graph_title Bytes by Bucket +graph_vlabel Bytes +graph_args --base 1024 -l 0 +graph_category garage +EOM + for i in "${!BUCKETS[@]}" + do + echo "${BUCKETS[${i}]}.label ${BUCKETS[${i}]}" + done + exit 0;; +esac + +for i in "${!BUCKETS[@]}" +do + BYTES=$(curl -s -H "${HEADER}" "http://[::1]:3903/v0/bucket?id=${i}" | jq -r '.bytes') + echo "${BUCKETS[${i}]}.value ${BYTES}" +done diff --git a/roles/munin_client/files/garage_bucket_unfinished b/roles/munin_client/files/garage_bucket_unfinished new file mode 100755 index 0000000..5629313 --- /dev/null +++ b/roles/munin_client/files/garage_bucket_unfinished @@ -0,0 +1,36 @@ +#!/bin/bash + +# Get the Header +HEADER="Authorization: Bearer ${BEARER}" + +# Create associative array +declare -A BUCKETS=() + +API_BUCKETS_JSON=$(curl -s -H "${HEADER}" "http://[::1]:3903/v0/bucket" | jq -r '.[] | .id + "," + .globalAliases[0]') + +# Populate associative array +for bucket in ${API_BUCKETS_JSON} +do + BUCKETS+=([$(echo ${bucket} | cut -d ',' -f 1)]="$(echo ${bucket} | cut -d ',' -f 2)") +done + +case $1 in + config) + cat << 'EOM' +graph_title Unfinished multipart uploads by Bucket +graph_vlabel Number of unfinished multipart uploads +graph_args --base 1000 -l 0 +graph_category garage +EOM + for i in "${!BUCKETS[@]}" + do + echo "${BUCKETS[${i}]}.label ${BUCKETS[${i}]}" + done + exit 0;; +esac + +for i in "${!BUCKETS[@]}" +do + UNFINISHED=$(curl -s -H "${HEADER}" "http://[::1]:3903/v0/bucket?id=${i}" | jq -r '.unfinishedUploads') + echo "${BUCKETS[${i}]}.value ${UNFINISHED}" +done diff --git a/roles/munin_client/tasks/garage.yml b/roles/munin_client/tasks/garage.yml new file mode 100644 index 0000000..fa9d557 --- /dev/null +++ b/roles/munin_client/tasks/garage.yml @@ -0,0 +1,23 @@ +--- + +- name: Put garage plugin configuration + ansible.builtin.template: + src: garage.j2 + dest: /etc/munin/plugin-conf.d/garage + owner: root + group: root + mode: '0640' + +- name: Put garage scripts + ansible.builtin.copy: + src: "files/{{ item }}" + dest: "/etc/munin/plugins/{{ item }}" + owner: root + user: root + mode: '0755' + notify: + - Restart munin-node + loop: + - garage_bucket_objects + - garage_bucket_size + - garage_bucket_unfinished diff --git a/roles/munin_client/tasks/main.yml b/roles/munin_client/tasks/main.yml index 622dd84..3ee8c48 100644 --- a/roles/munin_client/tasks/main.yml +++ b/roles/munin_client/tasks/main.yml @@ -109,12 +109,17 @@ loop: - users +# Useless junks for hypervisors +- name: Execute delete states for hypervisors + ansible.builtin.include_tasks: hypervisors.yml + when: "'hypervisors' in group_names" + # Specific LXC commands - name: Execute specific LXC commands ansible.builtin.include_tasks: lxc.yml when: ansible_facts['virtualization_type'] == "lxc" -# Useless junks for hypervisors -- name: Execute delete states for hypervisors - ansible.builtin.include_tasks: hypervisors.yml - when: "'hypervisors' in group_names" +# Specific garage commands +- name: Execute specific garage commands + ansible.builtin.include_tasks: garage.yml + when: "'garagegw' in inventory_hostname" diff --git a/roles/munin_client/templates/garage.j2 b/roles/munin_client/templates/garage.j2 new file mode 100644 index 0000000..3a2882d --- /dev/null +++ b/roles/munin_client/templates/garage.j2 @@ -0,0 +1,2 @@ +[garage*] +env.BEARER {{ garage_admin_token }}