How to get docker stats with current time?

Viewed 1602

I am checking for the CPU spike in docker containers? I need the timestamp where the CPU spike generates so that I can check the logs for the container for that timestamp.

    #!/bin/sh
    CPU=$(docker stats fb6ed2d1fa52 --format "table {{.CPUPerc}}")
    DATE=`date`
    echo $DATE  $CPU >> cpu_log.txt

But as docker stats gives the live data stream, It's not printing the time. The first line of docker stats execution is not ending, thus it's not running the next lines of the script. How to fix this?

1 Answers
Related