Last active
July 8, 2018 05:54
-
-
Save odekopoon/b41ba0f1c1c0b7664e1cd2c280944018 to your computer and use it in GitHub Desktop.
Mackerel カスタムメトリック inspired by ZabbixでMuninのMemoryグラフを再現する https://www.riscascape.net/archives/6588
This file contains 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/sh | |
if [ "$MACKEREL_AGENT_PLUGIN_META" = "1" ]; then | |
/bin/cat << 'EOF'; | |
# mackerel-agent-plugin | |
{ | |
"graphs": { | |
"memory": { | |
"label": "Memory usage - Munin style", | |
"unit": "bytes", | |
"metrics": [ | |
{"name": "available", "label": "Available", "stacked": false}, | |
{"name": "mem_total", "label": "MemTotal", "stacked": false}, | |
{"name": "swapd", "label": "Swapd", "stacked": true}, | |
{"name": "unused", "label": "UnUsed", "stacked": true}, | |
{"name": "buffers", "label": "Buffers", "stacked": true}, | |
{"name": "cached", "label": "Cached", "stacked": true}, | |
{"name": "swap_cache", "label": "SwapCached", "stacked": true}, | |
{"name": "slab_rec", "label": "SReclaimable", "stacked": true}, | |
{"name": "slab_unrec", "label": "SUnreclaim", "stacked": true}, | |
{"name": "page_tables", "label": "PageTables", "stacked": true}, | |
{"name": "apps", "label": "Apps", "stacked": true} | |
] | |
} | |
} | |
} | |
EOF | |
exit | |
fi | |
TIMESTAMP=$(date "+%s") | |
TEXT=$(/bin/cat /proc/meminfo | /bin/grep -F -e 'MemTotal:' -e 'MemFree:' -e 'Buffers:' -e 'Cached:' -e 'Slab:' -e 'SReclaimable:' -e 'SUnreclaim:' -e 'PageTables:' -e 'SwapCached:' -e 'SwapTotal:' -e 'SwapFree:' | /bin/awk '{print $2 * 1024}'|/usr/bin/tr '\n' ',') | |
IFS=',' | |
set -- $TEXT | |
MemTotal=$1 | |
MemFree=$2 | |
Buffers=$3 | |
Cached=$4 | |
SwapCached=$5 | |
SwapTotal=$6 | |
SwapFree=$7 | |
Slab=$8 | |
SReclaimable=$9 | |
SUnreclaim=${10} | |
PageTables=${11} | |
available=$(/usr/bin/expr $MemFree + $Buffers + $Cached + $SReclaimable + $SwapCached) | |
apps=$(/usr/bin/expr $MemTotal - $MemFree - $Buffers - $Cached - $Slab - $PageTables - $SwapCached) | |
swap=$(/usr/bin/expr $SwapTotal - $SwapFree) | |
echo -e $(/bin/cat << EOF; | |
memory.mem_total\t$MemTotal\t$TIMESTAMP | |
memory.mem_available\t$mem_available\t$TIMESTAMP | |
memory.apps\t$apps\t$TIMESTAMP | |
memory.page_tables\t$PageTables\t$TIMESTAMP | |
memory.swap_cache\t$SwapCached\t$TIMESTAMP | |
memory.slab_rec\t$SReclaimable\t$TIMESTAMP | |
memory.slab_unrec\t$SUnreclaim\t$TIMESTAMP | |
memory.cached\t$Cached\t$TIMESTAMP | |
memory.buffers\t$Buffers\t$TIMESTAMP | |
memory.unused\t$MemFree\t$TIMESTAMP | |
memory.swapd\t$swap\t$TIMESTAMP | |
EOF | |
) | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment