Skip to content

Commit

Permalink
add support for monitoring LVM caches
Browse files Browse the repository at this point in the history
This is basically a copy-paste of the snapshots code, and seems to
work on my end.

Closes: #158

Signed-off-by: Antoine Beaupré <[email protected]>
  • Loading branch information
anarcat committed Jun 6, 2023
1 parent 4098ef9 commit d5b9ef3
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lvm-prom-collector
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ display_usage() {
echo "Use -g for used and free space of logical volume groups."
echo "Use -p for used and free space of physical volumes."
echo "Use -s for the percentage usage of snapshots."
echo "Use -c for the percentage usage of caches."
echo "Use -t for the percentage usage of thin pools."
}

Expand All @@ -45,17 +46,21 @@ fi

thin_pools=false
snapshots=false
caches=false
physical=false
groups=false

while getopts "htpsg" opt; do
while getopts "htpscg" opt; do
case $opt in
p)
physical=true
;;
s)
snapshots=true
;;
c)
caches=true
;;
g)
groups=true
;;
Expand Down Expand Up @@ -105,6 +110,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)

Expand Down

0 comments on commit d5b9ef3

Please sign in to comment.