2024-10-19 16:24:29 +02:00

71 lines
1.3 KiB
Bash
Executable File

#!/bin/sh
# -*- sh -*-
: << =cut
=head1 NAME
ina219 - Plugin to measure power consumption.
=head1 NOTES
=head1 AUTHOR
Contributed by Florian Klemenz
=head1 LICENSE
GPLv2
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=cut
. $MUNIN_LIBDIR/plugins/plugin.sh
if [ "$1" = "autoconf" ]; then
echo yes
exit 0
fi
if [ "$1" = "config" ]; then
echo 'graph_title Power'
echo 'graph_args --base 1 -l 0 '
echo 'graph_scale no'
echo 'graph_vlabel mW'
echo 'graph_category power'
echo 'power.label power'
echo 'power.draw LINE'
print_warning power
print_critical power
exit 0
fi
ROUNDS=5
VOLTAGE=0
CURRENT=0
POWER=0
for i in $(seq ${ROUNDS}); do
RESULT=$(/usr/bin/ina219)
VOLTAGE_RAW=$(echo $RESULT | /bin/sed 's/\([0-9]\+\)mV \+\([0-9\.]\+\)mA/\1/')
VOLTAGE=$(echo "scale=3; $VOLTAGE+$VOLTAGE_RAW" | /usr/bin/bc)
CURRENT_RAW=$(echo $RESULT | /bin/sed 's/\([0-9]\+\)mV \+\([0-9\.]\+\)mA/\2/')
CURRENT=$(echo "scale=3; $CURRENT+$CURRENT_RAW" | /usr/bin/bc)
done
VOLTAGE=$(echo "scale=3; $VOLTAGE/$ROUNDS" | /usr/bin/bc)
CURRENT=$(echo "scale=3; $CURRENT/$ROUNDS" | /usr/bin/bc)
POWER=$(echo "scale=3; $VOLTAGE*$CURRENT/1000000" | /usr/bin/bc)
echo "power.value $POWER"