74 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
# -*- bash -*-
: << =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
source $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=3
VOLTAGE=0
CURRENT=0
POWER=0
for i in $(seq ${ROUNDS}); do
#ROW="12204mV 184.3mA"
ROW=$(/usr/bin/ina219)
ENTRY=( $ROW )
VOLTAGE_RAW=${ENTRY[0]%mV}
CURRENT_RAW=${ENTRY[1]%mA}
#echo "Voltage: ${VOLTAGE_RAW}"
#echo "Current: ${CURRENT_RAW}"
VOLTAGE=$(echo "scale=3; $VOLTAGE+$VOLTAGE_RAW" | /usr/bin/bc)
CURRENT=$(echo "scale=3; $CURRENT+$CURRENT_RAW" | /usr/bin/bc)
done
#exit 1
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"