Create a gist now

Instantly share code, notes, and snippets.

X240 Battery Plugin for Mackerel.io
#!/bin/bash
#
# [plugin.metrics.battery]
# command = "/path/to/x240battery.sh"
#
LANG=C
if [ x$MACKEREL_AGENT_PLUGIN_META = x1 ]; then
cat <<EOF
# mackerel-agent-plugin
{
"graphs": {
"battery": {
"label": "X240 Battery capacity",
"unit": "integer",
"metrics": [
{ "name": "BAT0", "label": "Front battery" },
{ "name": "BAT1", "label": "Rear battery" }
]
}
}
}
EOF
exit 0
fi
cap0=$(cat /sys/class/power_supply/BAT0/capacity)
cap1=$(cat /sys/class/power_supply/BAT1/capacity)
echo -n "battery.BAT0 ${cap0} "
date +%s
echo -n "battery.BAT1 ${cap1} "
date +%s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment