From aff0998db504f1971b6405f7d65cb6d62538500a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Tue, 6 Jun 2023 18:17:44 -0400 Subject: [PATCH] add support for monitoring LVM caches (Closes: #158) This is basically a copy-paste of the snapshots code, and seems to work on my end. --- lvm-prom-collector | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lvm-prom-collector b/lvm-prom-collector index c3819f5..644646a 100755 --- a/lvm-prom-collector +++ b/lvm-prom-collector @@ -48,7 +48,7 @@ snapshots=false physical=false groups=false -while getopts "htpsg" opt; do +while getopts "htpscg" opt; do case $opt in p) physical=true @@ -56,6 +56,9 @@ while getopts "htpsg" opt; do s) snapshots=true ;; + c) + caches=true + ;; g) groups=true ;; @@ -105,6 +108,20 @@ if [ "$snapshots" = true ]; then done fi +if [ "$caches" = true ]; then + echo "# HELP node_lvm_caches_allocated percentage of allocated data to a cache" + echo "# TYPE node_lvm_caches_allocated gauge" + + lvs_output=$(lvs --noheadings --select 'lv_attr=~[^C.*]' --units b --nosuffix --unquoted --nameprefixes --options lv_uuid,vg_name,data_percent 2>/dev/null) + echo "$lvs_output" | while IFS= read -r line; do + # Skip if the line is empty + [ -z "$line" ] && continue + # shellcheck disable=SC2086 + declare $line + echo "node_lvm_caches_allocated{uuid=\"$LVM2_LV_UUID\", vgroup=\"$LVM2_VG_NAME\"} $LVM2_DATA_PERCENT" + done +fi + if [ "$thin_pools" = true ]; then lvs_output=$(lvs --noheadings --select 'lv_attr=~[^t.*]' --units b --nosuffix --unquoted --nameprefixes --options lv_uuid,vg_name,data_percent,metadata_percent 2>/dev/null)