Bird
0
0

You want to collect CPU and memory usage metrics for multiple containers and save them to a file every minute. Which approach is best?

hard📝 Application Q8 of 15
Docker - Logging and Monitoring
You want to collect CPU and memory usage metrics for multiple containers and save them to a file every minute. Which approach is best?
AUse <code>docker logs</code> to get resource usage logs
BRun <code>docker stats</code> once and redirect output to a file
CUse a script that runs <code>docker stats --no-stream</code> for each container every minute and appends output to a file
DManually check <code>docker inspect</code> for each container every minute
Step-by-Step Solution
Solution:
  1. Step 1: Identify requirement for periodic snapshots

    Collecting metrics every minute means repeated snapshots, not continuous streaming.
  2. Step 2: Evaluate options

    Running docker stats --no-stream repeatedly captures snapshots; redirecting once streams continuous data; logs and inspect do not provide resource metrics.
  3. Final Answer:

    Use a script that runs docker stats --no-stream for each container every minute and appends output to a file -> Option C
  4. Quick Check:

    Periodic metrics collection = repeated --no-stream snapshots [OK]
Quick Trick: Script repeated --no-stream calls for periodic metrics [OK]
Common Mistakes:
  • Redirecting continuous stream once
  • Using logs for resource metrics
  • Using inspect for live metrics

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Docker Quizzes