A quick and easy way to send counters from a Docker host to Foglight

Scripts agents are an easy way to add to Foglight out of the box monitoring capabilities and can be easily used to send counters from a Docker host to Foglight: 

Step 1 -  Find the commands that get the data.

             The internet is full of examples for using Docker ps and docker images to get a lot of good counters from a Docker server. 
              docker ps -aq $1 | wc -l     # get the number of all containers
              docker ps -q $1 | wc -l       # get the number of running containers
              docker ps -a | grep -v -F 'Exited (0)' | grep -c -F 'Exited ('   # get the number of crashed containers
              docker images -aq $1 | wc -l    # get the number of all images (including intermediate images)
              docker images -q $1 | wc -l      # get the number of images
              docker images --filter "dangling=true" -q --no-trunc $1 | wc -l  # get the number of dangling images

Step 2 -  Send the result of the commands to standard output in a script agent. 

 Step 3 - Upload the script to Foglight, deploy the  cartridge and create an agent.

            The Process is well documented in our documentation,  Videos, and articles

 

The result is docker metrics in Foglight that can be used like any other Foglight metric. 

Anonymous
  • It was requested that I paste the script text for an easy copy/paste.

    Please remember to save the script in UNIX format so you don't get ^M for End of Line.

    #!/bin/sh

    # This agent need to run on a Docker host.

    echo "TABLE DockerData"

    echo "START_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"

    echo "END_TABLE"

Related Content