Skip to content

Instantly share code, notes, and snippets.

@ryochin
Last active May 6, 2021 05:36
Show Gist options
  • Save ryochin/cc369b53c6b991bcb38f2eb0fb94e119 to your computer and use it in GitHub Desktop.
Save ryochin/cc369b53c6b991bcb38f2eb0fb94e119 to your computer and use it in GitHub Desktop.
mackerel plugin for puma processes
#!/bin/sh
#
# [plugin.metrics.puma_process]
# command = ["/usr/bin/mackerel-plugin-puma-process"]
if [ "$MACKEREL_AGENT_PLUGIN_META" = "1" ]; then
echo "# mackerel-agent-plugin"
cat << EOS
{
"graphs": {
"puma.processes": {
"label": "Puma Process",
"unit": "integer",
"metrics": [
{
"name": "total",
"label": "Total Puma Process"
}
]
},
"puma.memory": {
"label": "Puma Memory",
"unit": "bytes",
"metrics": [
{
"name": "total",
"label": "Total Memory"
},
{
"name": "average",
"label": "Average Memory"
}
]
}
}
}
EOS
else
date=`date +%s`
processes="$(ps awwwux | egrep "puma.* worker" | grep -v grep | wc -l)"
echo "puma.processes.total\t${processes}\t${date}"
processes_memory="$(ps auwx | egrep "puma.* worker" | grep -v grep | awk '{print $6 }')"
for process_memory in $processes_memory; do
total_memory=$(( $total_memory + ( $process_memory * 1024) ))
done
echo "puma.memory.total\t${total_memory}\t${date}"
average="$(ps awwwux | egrep "puma.* worker" | grep -v grep | grep -v master | awk '{total_mem = $6 * 1024 + total_mem; total_proc++} END{printf("%d\n", total_mem / total_proc)}')"
echo "puma.memory.average\t${average}\t${date}"
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment