0
0
Dockerdevops~20 mins

Container metrics collection in Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Container Metrics Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Retrieve CPU usage percentage for all running containers
You want to see the CPU usage percentage of all running Docker containers using the docker stats command with JSON output. Which command will correctly show this information?
Adocker stats --no-stream --format '{{.CPUPerc}}'
Bdocker stats --format '{{json .}}' | grep CPUPerc
Cdocker stats --no-stream --format '{{.MemUsage}}'
Ddocker stats --no-stream --format '{{json .}}' | jq '.CPUPerc'
Attempts:
2 left
💡 Hint
Use the --format option to select the CPU percentage field directly.
🧠 Conceptual
intermediate
1:30remaining
Understanding memory usage metrics in Docker stats
Which metric from docker stats shows the current memory usage of a container?
AMemUsage
BMemLimit
CCPUPerc
DNetIO
Attempts:
2 left
💡 Hint
Look for the metric that shows how much memory the container is currently using.
📝 Syntax
advanced
2:30remaining
Correct JSON parsing of Docker stats output
You want to parse the JSON output of docker stats --no-stream --format '{{json .}}' to extract container names and CPU usage. Which jq command correctly extracts these fields as a JSON array of objects?
Ajq '. | {Name, CPUPerc}'
Bjq -s '[.[] | {Name: .Name, CPU: .CPUPerc}]'
Cjq '[.Name, .CPUPerc]'
Djq -r '.Name, .CPUPerc'
Attempts:
2 left
💡 Hint
Use the -s option to read multiple JSON objects as an array.
optimization
advanced
2:00remaining
Efficiently monitor memory usage of a specific container
You want to monitor the memory usage of a container named webapp continuously but only want to see the memory usage percentage updated every 2 seconds. Which command achieves this efficiently?
Adocker stats --format '{{.MemPerc}}' --filter name=webapp --no-stream
Bdocker stats --format '{{.MemPerc}}' --filter name=webapp --interval 2
Cdocker stats --format '{{.MemPerc}}' --no-stream --filter name=webapp
Ddocker stats --format '{{.MemPerc}}' --filter name=webapp
Attempts:
2 left
💡 Hint
By default, docker stats updates every second unless --no-stream is used.
🔧 Debug
expert
3:00remaining
Diagnose why Docker stats JSON parsing fails
You run docker stats --no-stream --format '{{json .}}' and pipe it to jq to parse JSON. But jq reports an error: parse error: Invalid numeric literal at line 1, column 10. What is the most likely cause?
AThe <code>jq</code> command is missing the <code>-r</code> flag to read raw input.
BThe <code>docker stats</code> command does not support JSON output, so the output is invalid.
CThe output contains multiple JSON objects without commas or array brackets, so jq expects a single JSON document.
DThe container names contain special characters that break JSON formatting.
Attempts:
2 left
💡 Hint
Consider how multiple JSON objects are output and how jq expects input.