Skip to content

Instantly share code, notes, and snippets.

@itchyny
Last active August 29, 2015 14:24
Show Gist options
  • Save itchyny/3c2dfb5da43d54e1dfa5 to your computer and use it in GitHub Desktop.
Save itchyny/3c2dfb5da43d54e1dfa5 to your computer and use it in GitHub Desktop.
CPU Temperature metric for Mackerel
#!/bin/bash
if ! [ -f /usr/local/bin/osx-cpu-temp 1>/dev/null 2>&1 ]; then
brew install https://raw.githubusercontent.com/tasuten/homebrew-myformulas/master/osx-cpu-temp.rb > /dev/null 2>&1
fi
if [ x$MACKEREL_AGENT_PLUGIN_META = x1 ]; then
cat << EOF
# mackerel-agent-plugin
{
"graphs": {
"cpu": {
"label": "CPU Temperature",
"unit": "float",
"metrics": [
{ "name": "temperature", "label": "CPU Temperature / deg" }
]
}
}
}
EOF
exit 0
fi
temperature=$(/usr/local/bin/osx-cpu-temp | sed -e 's/[^0-9.]//g' | tr -d '\n')
if (( $(bc <<< "$temperature > 100") == 1 )); then
temperature=30
fi
echo -e "cpu.temperature\t\
$temperature\t\
$(date +%s)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment