feat: add garage specific munin shell scripts

This commit is contained in:
VC
2024-07-05 11:53:37 +02:00
parent 31557c80a2
commit 1da49f8665
6 changed files with 142 additions and 4 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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"

View File

@@ -0,0 +1,2 @@
[garage*]
env.BEARER {{ garage_admin_token }}