Last active
August 20, 2017 14:16
-
-
Save ejholmes/be962ed2fcbda091a1da592d4a272b08 to your computer and use it in GitHub Desktop.
Generate dogstatsd metrics from iStats
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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