Initial commit

This commit is contained in:
feedc0de committed 2026-01-23 23:57:50 +01:00
commit b7798739ce
5 files changed
+150

No files matched your search

+15
View File
@@ -0,0 +1,15 @@
# telegraf-bcachefs-input
Telegraf bcachefs monitoring
Add the following config section to your telegraf.yml:
```
[[inputs.exec]]
commands = ["/etc/telegraf/bcachefs.sh"]
data_format = "influx"
```
![example disks table](disks-table.png)
![example disks graphs](disks-graphs.png)
![example disks states](disks-states.png)
+135
View File
@@ -0,0 +1,135 @@
#!/bin/bash
function convert_to_bytes() {
awk '
{
val=$0
num=val
sub(/[KMGT]$/, "", num)
unit=substr(val, length(val), 1)
mul=1
if (unit=="K") mul=1024
else if (unit=="M") mul=1024^2
else if (unit=="G") mul=1024^3
else if (unit=="T") mul=1024^4
printf "%.0f\n", num * mul
}' <<< "$1"
}
FSPATH="/mnt"
UUID=
PARSER_STATE=0
#echo switch to 0
while IFS= read -r line; do
case $PARSER_STATE in
0)
if [[ $line =~ ^Filesystem:[[:space:]]+([^[:space:]]+)$ ]]
then
uuid="${BASH_REMATCH[1]}"
# echo "uuid=$UUID"
elif [[ $line == Data\ type* ]]
then
#echo switch to 1
PARSER_STATE=1
#continue
elif [[ $line == "Compression:" ]]
then
#echo switch to 2
PARSER_STATE=2
#continue
elif [[ $line == "Btree usage:" ]]
then
#echo switch to 3
PARSER_STATE=3
#continue
elif [[ $line == "Pending reconcile:" ]]
then
#echo switch to 4
PARSER_STATE=4
#continue
elif [[ $line =~ ^([^ ]+)\ \(device\ ([0-9]+)\):[[:space:]]+([^[:space:]]+)[[:space:]]+([^[:space:]]+)[[:space:]]+([0-9]+)%$ ]]
then
blockdev="${BASH_REMATCH[3]}"
if [[ ! $blockdev == /dev/* ]]
then
blockdev="/dev/$blockdev"
fi
echo -n "bcachefs,fspath=\"$FSPATH\",UUID=\"$UUID\",devlabel=\"${BASH_REMATCH[1]}\",devid=${BASH_REMATCH[2]},blockdev=\"$blockdev\" mode=\"${BASH_REMATCH[4]}\",usage=${BASH_REMATCH[5]}"
#echo switch to 5 label="$label" devid="$devid" block_device="$block_device" mode="$mode" usage="$usage"
PARSER_STATE=5
#continue
fi
;;
1)
if [[ "$line" == "" ]]
then
#echo switch to 0
PARSER_STATE=0
#continue
fi
;;
2)
if [[ "$line" == "" ]]
then
#echo switch to 0
PARSER_STATE=0
#continue
fi
;;
3)
if [[ "$line" == "" ]]
then
#echo switch to 0
PARSER_STATE=0
#continue
fi
;;
4)
if [[ "$line" == "" ]]
then
#echo switch to 0
PARSER_STATE=0
#continue
fi
;;
5)
if [[ "$line" == "" ]]
then
echo
#echo switch to 0
PARSER_STATE=0
#continue
elif [[ $line =~ ^[[:space:]]*([^:]+):[[:space:]]*(.*)$ ]]; then
field="${BASH_REMATCH[1]// /_}"
rest="${BASH_REMATCH[2]}"
read -r val1 val2 val3 <<<"$rest"
val1="$(convert_to_bytes "$val1")"
echo -n ",${field}_data=$val1"
if [[ ! -z "$val2" ]]
then
echo -n ",${field}_buckets=$val2"
fi
if [[ ! -z "$val3" ]]
then
val3="$(convert_to_bytes "$val3")"
echo -n ",${field}_fragmented=$val3"
fi
#else
#echo unknown?
fi
;;
esac
#if [[ $PARSER_STATE -ne 1 ]]
#then
# echo "Got line: $line"
#fi
done < <(sudo bcachefs fs usage -a "$FSPATH")
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 219 KiB