We use file based queues in several components of our monitoring system. They are convenient and reliable. Knowing how many files in a file-based queue is critical to us. If the number of files in a queue is high, probably consumers are behind. If this number is low, probably one or more producers are down.

We can easily monitor the count of files in a folder using one-liner Shell script and StatsBee. Grab StatsBee here for FREE.

echo "NumOfFiles,folder=`pwd`:`ls | wc -l`|c" | nc -w 1 -u localhost 8125

To continuously monitor a folder, we can use while true like below.

while true; do echo "NumOfFiles,folder=`pwd`:`ls | wc -l`|c" | nc -w 1 -u localhost 8125; done

We have a beautiful graph from a simple command line!

It’s a critical metric, so we also add it to a dashboard and set alarm. That’s it for today. Happy Monitoring!

A quick tour of server monitoring with StatsBee:https://www.youtube.com/watch?v=KhYur1icbN4