Skip to content

Instantly share code, notes, and snippets.

@itchyny
Last active February 28, 2023 00:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itchyny/03bcc3ad50b3e4a157ec61d023e39900 to your computer and use it in GitHub Desktop.
Save itchyny/03bcc3ad50b3e4a157ec61d023e39900 to your computer and use it in GitHub Desktop.
Mackerel plugin for file count
#!/bin/zsh
if [[ "$MACKEREL_AGENT_PLUGIN_META" == 1 ]]; then
cat <<EOF
# mackerel-agent-plugin
{
"graphs": {
"filecount.#": {
"label": "File count",
"unit": "integer",
"metrics": [
{
"label": "total",
"name": "total"
}
]
}
}
}
EOF
exit 0
fi
for f in ~/{,Documents,Downloads,Desktop,Dropbox}; do
printf 'filecount.%s.total\t%s\t%s\n' \
"${(L)${${${${f/#$HOME/home}//\//_}#_}%_}#home_}" \
"$(set -- "$f"/*(DN) && echo "$#")" \
"$(date +%s)"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment