Alerting on Docker counters from Foglight

In a previous blog we showed how easy it is to send Docker Counters to Foglight, the next natural step is to alert when something goes wrong. 

A reminder our script was called DockerMonitor.sh and the lines sending data to Foglight were 

echo "TABLE DockerData"      #Creating a table called DockerData
echo "START_SAMPLE_PERIOD"      # Starting the sample period
echo "DockerContainers = $(docker ps -aq $1 | wc -l)"
echo "DockerRunningContainers = $(docker ps -q $1 | wc -l)"
echo "DockerCrashedContainers = $(docker ps -a | grep -v -F 'Exited (0)' | grep -c -F 'Exited (')"
echo "DockerAllImages = $(docker images -aq $1 | wc -l)"
echo "DockerImages = $(docker images -q $1 | wc -l)"
echo "DockerDanglingImages = $(docker images --filter "dangling=true" -q --no-trunc $1 | wc -l)"
echo "END_SAMPLE_PERIOD"   # Ending the sample period
echo "END_TABLE"      #End sending data to table

We can now create a rule, lets call it DockerCrashedContainers and choose the right topology object (typically <script-name>_Agent_Table_<Table Name>, in our case DockerMonitor_Agent_Table_DockerData. 

 

We then create severity level variables with the number of crashed containers and the name of the Docker Host

And end with setting the condition as well as the alert message using the variables we defined. 

 

The result is an alarm message indicating what Docker host has crashed containers and how many crashed containers it has. 

 

For more information about building and using rules and sending alerts in Foglight please check the following video or our documentation

About the Author
Golan.Shem-Tov
A Solutions Architect in the Foglight team. Been working in APM and helping customers solve performance issues for over 15 years. I started working as a developer and a team leader and discovered that...