Zygo / bees

Best-Effort Extent-Same, a btrfs dedupe agent
GNU General Public License v3.0
630 stars 57 forks source link

beesd stats for node exporter #213

Open beeepus opened 2 years ago

beeepus commented 2 years ago

Hi folks,

I just bash dump the stats from beesd to Prometheus node exporter for the collector.textfile.directory like Disclaimer WARNING it creates a temp dir and delete all the files in it. If you don't know/understand how and way don't use it. It can potential delete your system files!

#!/bin/bash

tmpPath="/tmp/beesd.tmp"

test -d "${tmpPath}" || mkdir "${tmpPath}"

rm -f "${tmpPath}/"*

beesdStatsExporter() {
statsFile=$1
statsName=$2

#TOTAL
for stats in $(cat "${statsFile}" |sed -n '/^TOTAL:/,/^RATES:/ p' | head -n -1 | sed -n '2,/^$/ p' | sed 's/^\t//g' | tr ' ' '\n')
do
test -f "${tmpPath}/total_${stats/=*}" || cat > "${tmpPath}/total_${stats/=*}" <<-EOF
# HELP beesd_stats_total_${stats/=*} beesd total ${stats/=*}.
# TYPE beesd_stats_total_${stats/=*} gauge
EOF
echo beesd_stats_total_${stats/=*}\{name=\"${statsName}\"\} ${stats/*=} >> "${tmpPath}/total_${stats/=*}"
done

#RATES
for stats in $(cat "${statsFile}"  |sed -n '/^RATES:/,/^$/ p' | sed -n '2,/^$/ p' | sed 's/^\t//g' | tr ' ' '\n')
do
test -f "${tmpPath}/rates_${stats/=*}" || cat > "${tmpPath}/rates_${stats/=*}" <<-EOF
# HELP beesd_stats_rates_${stats/=*} beesd rates ${stats/=*}.
# TYPE beesd_stats_rates_${stats/=*} gauge
EOF
echo beesd_stats_rates_${stats/=*}\{name=\"${statsName}\"\} ${stats/*=} >> "${tmpPath}/rates_${stats/=*}"
done

}

beesdStatsExporter "/mnt/btr0/beesd/btr0-128MB/beesstats.txt" "btr0"

beesdStatsExporter "/mnt/btr1/beesd/btr1-128MB/beesstats.txt" "btr1"

Using cron */5 * * * * /usr/local/sbin/beesd-exporter.sh | sponge /var/lib/node_exporter/beesd.prom

to publishing it.

Now I wondering what stats are insetting to get my eyes on?

Cheers, beep