@@ -32,7 +32,9 @@ display_usage() {
3232 echo " Use -g for used and free space of logical volume groups."
3333 echo " Use -p for used and free space of physical volumes."
3434 echo " Use -s for the percentage usage of snapshots."
35+ echo " Use -c for the percentage usage of caches."
3536 echo " Use -t for the percentage usage of thin pools."
37+ echo " Use -a to enable everything."
3638}
3739
3840if [ " $( id -u) " != " 0" ]; then
4749
4850thin_pools=false
4951snapshots=false
52+ caches=false
5053physical=false
5154groups=false
5255
53- while getopts " ahtpsg " opt; do
56+ while getopts " ahtpscg " opt; do
5457 case $opt in
5558 a)
5659 thin_pools=true
5760 snapshots=true
5861 physical=true
5962 groups=true
63+ caches=true
6064 ;;
6165 p)
6266 physical=true
6367 ;;
6468 s)
6569 snapshots=true
6670 ;;
71+ c)
72+ caches=true
73+ ;;
6774 g)
6875 groups=true
6976 ;;
@@ -113,6 +120,20 @@ if [ "$snapshots" = true ]; then
113120 done
114121fi
115122
123+ if [ " $caches " = true ]; then
124+ echo " # HELP node_lvm_caches_allocated percentage of allocated data to a cache"
125+ echo " # TYPE node_lvm_caches_allocated gauge"
126+
127+ lvs_output=$( lvs --noheadings --select ' lv_attr=~[^C.*]' --units b --nosuffix --unquoted --nameprefixes --options lv_uuid,vg_name,data_percent 2> /dev/null)
128+ echo " $lvs_output " | while IFS= read -r line; do
129+ # Skip if the line is empty
130+ [ -z " $line " ] && continue
131+ # shellcheck disable=SC2086
132+ declare $line
133+ echo " node_lvm_caches_allocated{uuid=\" $LVM2_LV_UUID \" , vgroup=\" $LVM2_VG_NAME \" } $LVM2_DATA_PERCENT "
134+ done
135+ fi
136+
116137if [ " $thin_pools " = true ]; then
117138 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)
118139
0 commit comments