Skip to content

Instantly share code, notes, and snippets.

@ejholmes
Last active August 20, 2017 14:16
Show Gist options
  • Save ejholmes/be962ed2fcbda091a1da592d4a272b08 to your computer and use it in GitHub Desktop.
Save ejholmes/be962ed2fcbda091a1da592d4a272b08 to your computer and use it in GitHub Desktop.
Generate dogstatsd metrics from iStats
#!/bin/bash
#
# while true; do istats --no-graphs; sleep 10; done | ./parse.sh > /dev/udp/127.0.0.1/8125
fan_speed="Fan ([[:digit:]]+) speed: (.*) RPM"
cpu_temp="CPU temp: (.*)°C"
battery_temp="Battery temp: (.*)°C"
current_charge="Current charge: (.*) mAh (.*)%"
max_charge="Maximum charge: (.*) mAh (.*)%"
while read line; do
if [[ $line =~ $fan_speed ]]; then
echo "macbook.fan.speed:${BASH_REMATCH[2]}|g|#fan:${BASH_REMATCH[1]}"
fi
if [[ $line =~ $cpu_temp ]]; then
echo "macbook.cpu.temp:${BASH_REMATCH[1]}|g"
fi
if [[ $line =~ $battery_temp ]]; then
echo "macbook.battery.temp:${BASH_REMATCH[1]}|g"
fi
if [[ $line =~ $current_charge ]]; then
echo "macbook.battery.charge:${BASH_REMATCH[1]}|g"
echo "macbook.battery.pct:${BASH_REMATCH[2]}|g"
fi
if [[ $line =~ $max_charge ]]; then
echo "macbook.battery.max:${BASH_REMATCH[1]}|g"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment