Containerization with Docker

Chapter 10
Observability, Analytics and Troubleshooting

Diploma in DevOps
Containerization with Docker   •   Diploma

Observability, Analytics and Troubleshooting

Introduction and Context

Containerized systems are dynamic: containers are created, replaced, scaled, rescheduled and connected to changing networks. This flexibility improves delivery and utilization, but it also makes failures more difficult to understand. A process may be healthy inside a container while the service is inaccessible through a load balancer. A container may restart because of an application defect, memory pressure, an invalid configuration, or an orchestration policy. Effective operations therefore require more than checking whether a container is running.

Observability is the practice of understanding the internal state of a system from the evidence it produces. In Docker-based environments, this evidence includes logs, metrics, events, health-check results, traces, configuration, deployment records and user-impact indicators. Troubleshooting is the disciplined process of using that evidence to form, test and eliminate hypotheses about a failure.

Observability is not identical to monitoring. Monitoring usually asks whether known conditions are within acceptable limits. Observability also supports investigation of previously unknown failure modes. A monitoring alert might report that error rate exceeds 5 percent; observability helps determine whether the cause is a code defect, database saturation, network failure or incorrect deployment.

Learning Objectives

By the end of this chapter, students should be able to:

  • distinguish logs, metrics, events, health checks and traces;
  • design useful Docker observability signals and operational indicators;
  • calculate and interpret rates, percentiles, availability and error budgets;
  • investigate container failures using evidence rather than guesswork;
  • apply a structured troubleshooting workflow;
  • make evidence-based incident, reliability and capacity decisions; and
  • recognize limitations, governance risks and emerging practices in observability.

1. The Observability Model

A useful operational model has three related layers:

  1. Signals are the raw evidence produced by systems.
  2. Indicators are measurements derived from signals and connected to service objectives.
  3. Decisions are operational actions based on interpreted indicators.

For example, an application emits structured access logs and request-duration metrics. These are used to calculate the 95th-percentile latency and the proportion of failed requests. If the error-rate objective is violated, an operator may pause a deployment, roll back an image or add capacity.

Observability should cover several dimensions:

  • What happened? Logs and events provide records of actions and state changes.
  • How much or how often? Metrics quantify rates, counts, durations and resource use.
  • Where did the request travel? Traces show a request across services.
  • Is the service usable? Health checks and synthetic tests assess readiness and availability.
  • What changed? Deployment, configuration and infrastructure records provide context.

No single signal is sufficient. Logs may explain a failure but cannot easily show its population-wide frequency. Metrics show trends but often omit detailed context. Traces reveal dependency latency but may be sampled. Sound diagnosis correlates multiple signals using time, service, container, host, request and deployment identifiers.

2. Logs: Contextual Records of Events

A log is a timestamped record describing an occurrence. Application logs may report authentication failures, request completion, database errors or business events. Container logs commonly represent the application's standard output and standard error streams, which Docker can collect through a logging driver.

2.1 Qualities of effective logs

Useful logs are:

  • Structured: JSON or another parseable format is preferable to unplanned text.
  • Contextual: Include service name, environment, severity, timestamp, request or trace ID, operation and relevant outcome.
  • Consistent: Use stable field names and severity meanings.
  • Actionable: Explain what occurred and what an operator can investigate.
  • Safe: Exclude passwords, access tokens, unnecessary personal data and confidential payloads.
  • Bounded: Avoid logging huge payloads or repeatedly logging the same event in a tight loop.

A useful event might contain timestamp, level, service, container_id, event, request_id, trace_id, duration_ms and status_code. The exact schema may differ, but consistency is essential for search and aggregation.

2.2 Severity and logging strategy

Severity levels should represent operational meaning rather than developer preference. A typical policy distinguishes debug information, normal informational events, warnings, recoverable errors and critical failures. Production systems generally use a lower verbosity than development systems, while allowing temporary, controlled increases during diagnosis.

Docker log collection must account for rotation and retention. A container that continuously writes logs can fill a host filesystem, causing unrelated services to fail. Retention should reflect troubleshooting needs, legal obligations, storage cost and privacy requirements. Central collection is valuable because containers are ephemeral: local files may disappear when a container is replaced.

3. Metrics and Operational Indicators

A metric is a numerical observation recorded over time. Common metric types include:

  • Counter: A cumulative value that increases, such as total requests or total failures. Rates are usually derived from counters.
  • Gauge: A value that may increase or decrease, such as memory usage or active connections.
  • Histogram: Observations grouped into buckets, useful for latency and size distributions.
  • Summary: A client- or library-calculated distribution summary, often including quantiles; its aggregation properties require care.

Metrics should be designed around questions. “How many containers exist?” is less operationally useful than “How many requests are failing by endpoint and version?” Useful dimensions include service, route, status class, environment and deployment version. Excessive dimensions, especially unbounded identifiers such as user IDs or request IDs, create high cardinality and may overwhelm a metrics system.

3.1 Rates and error ratios

For an interval, an event rate can be calculated as:

rate = ΔN ÷ Δt

Here, ΔN is the change in event count and Δt is elapsed time. If 300 requests arrive in 60 seconds, the average request rate is 5 requests per second. Rates are meaningful only when the interval and population are specified.

An error ratio is:

error ratio = failed requests ÷ total requests

If 240 of 12,000 requests fail, the error ratio is 0.02, or 2 percent. The calculation assumes that failed and total requests are measured over the same interval and that the counting definitions are consistent.

3.2 Percentiles and latency

Mean latency can conceal a poor user experience when a small but important fraction of requests is slow. The p95 latency is the value at or below which approximately 95 percent of observations fall; approximately 5 percent are slower. The p99 describes the slower tail more strictly. Percentiles must be calculated from a sufficiently representative sample and should not be averaged across services or time periods without appropriate distribution data.

For example, if a service has a p95 latency of 420 ms, this does not mean every request takes 420 ms or that the average is 420 ms. It means the 95th percentile of the selected population is 420 ms.

3.3 Resource utilization

CPU utilization, memory working set, disk space, network throughput, file descriptors and container restarts are common infrastructure indicators. Utilization is not automatically a problem. A high CPU value may be normal during a batch job, while a moderate memory value may be dangerous if it is increasing continuously and approaching a limit.

A simple utilization ratio is:

utilization = observed resource use ÷ available resource capacity

The numerator and denominator must refer to comparable resources and time periods. A host with four CPU cores using two cores has 0.5, or 50 percent, CPU utilization under this simplified interpretation. Actual platform measurements may use CPU time, quotas and throttling semantics, so the metric definition must be checked before interpretation.

3.4 Service-level indicators and objectives

A service-level indicator (SLI) is a quantitative measure of service performance, such as successful request proportion or latency. A service-level objective (SLO) is a target for an SLI over a stated period. A service-level agreement (SLA) is an external commitment, often with business or financial consequences.

An availability SLI can be expressed as:

availability = good events ÷ valid events

If 99,500 of 100,000 valid requests meet the defined success criteria, availability is 99.5 percent. The definition of “good” and “valid” must be explicit. For example, health-check requests may be excluded from a user-facing availability SLI if they do not represent real user transactions.

The error budget is the allowable unreliability:

error budget = 1 − SLO

For a 99.9 percent monthly availability objective, the error budget is 0.1 percent of the objective period. If a 30-day month is approximated as 43,200 minutes, the time budget is:

43,200 × 0.001 = 43.2 minutes

This is an approximation because calendar months have different lengths and because request-based objectives may not be time-based. Error budgets support decisions: if the budget is being consumed rapidly, risky releases may be paused and reliability work prioritized.

4. Docker Events and Health Checks

Docker events record changes such as container creation, start, stop, die, restart, image pull and network activity. Events are particularly useful for reconstructing timelines. A metric may show that restarts increased at 10:14; events may reveal that containers exited with a particular status immediately after a deployment.

Events are not a complete audit trail. Retention, collection configuration and platform boundaries affect what is available. Operators should correlate event times with deployment records, host logs and application logs.

4.1 Health checks

A Docker health check executes a command or test that reports whether an application is functioning according to a defined criterion. Its result is distinct from the container process state. A process can remain running while the application is unable to serve requests; conversely, a temporary dependency failure may make a health check fail even though the application itself is operating correctly.

A good health check is:

  • fast and inexpensive;
  • representative of the service's ability to perform its intended role;
  • independent enough to avoid false positives;
  • explicit about dependencies; and
  • configured with suitable interval, timeout, retry and start-up grace behavior.

Two concepts should be distinguished:

  • Liveness: Should the process be restarted, or is it still capable of recovery?
  • Readiness: Should traffic be sent to the instance now?

A liveness check that tests every downstream dependency can cause restart storms when a database is temporarily unavailable. A readiness check may reasonably fail during dependency loss, removing the instance from traffic without repeatedly restarting it.

5. Distributed Tracing

A trace follows one transaction across components. It is composed of spans, where each span represents an operation such as an HTTP request, database query or message-processing step. Spans normally carry a trace identifier, span identifier, parent relationship, timing and attributes.

Tracing helps answer questions that logs and metrics cannot answer efficiently: Which dependency consumed most of the request time? Where did a timeout originate? Did one request cross an unexpected service boundary? Correlation IDs allow operators to move from a metric anomaly to a trace and then to related logs.

Tracing has costs and limitations. Instrumentation must propagate context correctly across HTTP, messaging and asynchronous work. Sampling reduces storage and processing costs but may omit rare failures. Sensitive data should not be placed indiscriminately in span attributes. Trace duration is also not automatically equivalent to user-perceived latency if work occurs outside the traced path.

6. A Disciplined Troubleshooting Method

Troubleshooting should be hypothesis-driven rather than based on random commands. The following workflow is suitable for Docker environments.

Step 1: Define the symptom and impact

State what users or dependent systems experience, when it began, which operations are affected and how severe the impact is. Distinguish a total outage from elevated latency or a single failing endpoint. Record the time zone and use synchronized clocks where possible.

Step 2: Establish the change timeline

Identify recent image deployments, configuration changes, secret rotation, host maintenance, scaling actions, network changes and dependency incidents. Temporal correlation is not proof of causation, but it prioritizes investigation.

Step 3: Check scope

Compare affected and unaffected containers, hosts, zones, versions, routes and tenants. If only one image version is failing, the deployment becomes a strong hypothesis. If all services on one host fail, host or network conditions become more likely.

Step 4: Inspect state and events

Examine container status, exit codes, restart counts, health state, resource limits, mounts, networks and recent Docker events. A restart loop, an unhealthy state or an immediate exit provides a direction, not a final diagnosis.

Step 5: Correlate signals

Use the same time window and identifiers across logs, metrics and traces. For example, rising latency, database timeout logs and traces showing long database spans provide stronger evidence than any single observation.

Step 6: Form and test hypotheses

A hypothesis should predict observable evidence. For “memory exhaustion caused restarts,” expected evidence may include increasing memory usage, an out-of-memory event, termination status and a restart near the event time. If those observations are absent, lower the hypothesis's priority.

Step 7: Mitigate safely

Possible actions include rollback, traffic reduction, disabling a feature, increasing capacity, replacing a corrupted container or isolating a dependency. Prefer reversible actions. Record commands and decisions so that the incident remains auditable.

Step 8: Verify recovery

Recovery requires more than a green container state. Confirm user-facing success rate, latency, health, queue depth, dependency behavior and absence of recurrence. Continue observation for an appropriate period.

Step 9: Learn and improve

After stabilization, identify contributing conditions, detection gaps and effective actions. A blameless review should produce concrete improvements such as better instrumentation, safer limits, clearer runbooks, tests or deployment controls.

7. Common Failure Patterns

SymptomPossible evidenceInvestigation direction
Container exits immediatelyExit code, startup logs, failed configurationValidate command, environment, files and permissions
Repeated restartsEvents, health failures, memory pressureSeparate application crash, failed liveness and resource termination
Requests time outTraces, connection metrics, dependency logsExamine network path, pools, downstream latency and timeouts
High latency with normal CPUTrace spans, queue depth, database metricsInvestigate I/O, locks, external services and contention
Image starts on one host but not anotherHost events, architecture, mounts, runtime versionsCompare host resources, platform and configuration
Disk fills unexpectedlyContainer logs, writable layers, volumesApply rotation, retention and storage-growth controls

A common mistake is to treat a restart as the cause. A restart is usually an effect. The cause may be an application crash, failed health check, manual action, resource limit or host failure.

8. Capacity and Performance Decisions

Observability supports capacity planning when measurements are interpreted over time. A single CPU snapshot cannot establish that more hosts are needed. Operators should examine demand growth, saturation, queueing, latency, error rates and headroom.

For a stable system, Little's Law provides a useful relationship:

L = λW

Here, L is the average number of items in the system, λ is the average arrival rate, and W is the average time an item spends in the system. Units must be consistent: requests and requests per second produce seconds. The relationship assumes a stable system over the observation period, with a meaningful definition of the system boundary.

If a service receives 20 requests per second and the average response time is 0.5 seconds, the average number of in-flight requests is approximately:

L = 20 × 0.5 = 10 requests

This does not directly determine the number of containers required. Container capacity depends on concurrency limits, CPU, memory, dependency behavior and performance targets. Nevertheless, a rising response time at stable arrival rate implies increasing in-flight work and may indicate saturation or a bottleneck.

Capacity decisions should use forecasts and stress tests, not only historical averages. Plan for peaks, failure of one instance, deployment surges, log volume and monitoring-system overhead. Scaling can also worsen a problem: adding application instances may overload a database or increase cache misses.

9. Applied Case: Illustrative Checkout Incident

Background

A fictional online retailer runs a Dockerized checkout service, payment adapter and inventory service. After a release, customers report intermittent checkout delays. The checkout container remains in a running state.

Problem

The initial dashboard shows CPU below 60 percent and no host failures. However, the checkout p95 latency rises from 450 ms to 2.4 seconds, and the error ratio reaches 3 percent. The SLO is 99.5 percent successful checkouts.

Analysis

Operators first compare versions and find that nearly all failures occur on the new checkout image. Traces show that slow requests contain database spans lasting several seconds. Logs contain repeated connection-pool timeout messages, but the logs lack a deployment version field, making aggregation difficult. Database metrics show connection utilization near its configured maximum. Docker events show no restart storm, so container replacement is not the primary cause.

The evidence supports a resource-contention hypothesis: the new release performs an additional query for each checkout and consumes the database connection pool more rapidly. CPU and container status did not reveal the bottleneck because the constrained resource was downstream.

Approach and solution

The incident team pauses the rollout and routes traffic to the previous image. Latency and error rates recover. They then reproduce the release in a staging environment, confirm the extra query, and redesign the operation to use a single optimized query. They add a metric for pool wait time, include version and trace identifiers in structured logs, and establish a deployment dashboard comparing old and new versions.

Outcome

The corrected release reduces database spans and maintains the latency objective under expected load. The team also updates the runbook to inspect dependency saturation whenever application latency rises without corresponding CPU saturation.

Learning points

  1. A running container is not proof of a healthy service.
  2. Downstream saturation can explain application symptoms without high application CPU.
  3. Version labels and trace correlation shorten diagnosis.
  4. Rollback is a valid mitigation, but permanent improvement requires identifying the causal change.
  5. Indicators should represent user outcomes as well as infrastructure state.

10. Governance, Security and Ethical Considerations

Observability data can contain sensitive information. Logs and traces may expose personal identifiers, payment-related data, session tokens, internal hostnames or customer behavior. Organizations should apply data minimization, access control, encryption, retention limits and audit logging. Redaction should occur before data reaches broad-access systems where possible.

Monitoring employees or customers without a legitimate purpose can create ethical and legal risks. Policies should define who may access operational data, why it is collected, how long it is retained and how incidents involving sensitive data are handled. Debug logging must not become an uncontrolled channel for data leakage.

Alerting also has a human factor. Excessive false positives cause alert fatigue, while poorly defined alerts delay response. Alerts should identify a meaningful impact, include useful context and have an owner or documented action. Automated remediation should be tested carefully: an aggressive restart policy can amplify an outage, and automatic scaling can overload a dependency.

11. Contemporary Developments and Best Practices

Modern platforms increasingly combine metrics, logs and traces through open instrumentation standards and common collection pipelines. The value is not merely storing more data; it is improving correlation and reducing the time required to move from symptom to cause. eBPF-based tools can provide kernel and network visibility with limited application changes, although they require specialist skills and careful governance.

Artificial intelligence and machine learning can assist anomaly detection, log clustering, event correlation and incident summarization. These techniques should support—not replace—engineering judgment. Models may misclassify rare failures, reproduce bias in historical data, expose sensitive information through prompts or generate confident but unsupported explanations. Any AI-assisted diagnosis should be checked against primary evidence.

Professional practice includes:

  • define SLIs from user and business outcomes;
  • standardize structured logs and correlation identifiers;
  • collect container, host, dependency and deployment evidence;
  • control metric cardinality and log volume;
  • use health checks that distinguish readiness from liveness;
  • retain enough data to investigate while minimizing exposure;
  • test dashboards and alerts during realistic failure exercises;
  • document runbooks and reversible mitigations;
  • measure recovery and learning, not only detection; and
  • review capacity using trends, peaks, dependencies and failure scenarios.

Chapter Summary

Observability makes system behavior understandable through logs, metrics, events, health checks and traces. Logs provide detailed contextual records; metrics quantify rates, distributions and resource behavior; events establish state-change timelines; health checks assess liveness or readiness; and traces connect work across distributed components. Operational indicators become useful when tied to explicit SLIs, SLOs and user outcomes.

Reliable troubleshooting is evidence-based. Engineers define impact, construct a timeline, compare scope, inspect state, correlate signals, test hypotheses, mitigate safely and verify recovery. Capacity decisions require trends and system relationships rather than isolated snapshots. Mathematical tools such as rates, error ratios, error budgets and Little's Law support interpretation when their assumptions and units are respected. Finally, observability must address privacy, access, retention, alert fatigue and the limitations of automated analysis.

Key Terms

Observability: The ability to understand internal system state from externally produced evidence.

Monitoring: The practice of observing known conditions and alerting when they exceed defined limits.

Log: A timestamped record of an event or activity.

Structured logging: Producing logs in consistent, machine-readable fields.

Metric: A numerical measurement recorded over time.

Counter: A cumulative metric that normally increases.

Gauge: A metric that may increase or decrease.

Histogram: A distribution representation using value buckets.

Event: A record of a state change or action.

Health check: A test used to assess an application's operational condition.

Liveness: An assessment of whether a process should continue running.

Readiness: An assessment of whether an instance should receive traffic.

Trace: A representation of one transaction across system components.

Span: A timed operation within a trace.

SLI: A quantitative service performance indicator.

SLO: A target value or range for an SLI.

SLA: An external service commitment, often contractual.

Error budget: The permitted unreliability implied by an SLO.

Cardinality: The number of distinct values in a metric dimension.

Hypothesis-driven troubleshooting: Testing explanations against predicted evidence.

Review Questions

Short Answer Questions

  1. What is the difference between monitoring and observability?
  2. Why should request identifiers and trace identifiers be included in structured logs?
  3. Distinguish liveness from readiness checks.
  4. What information does a Docker event provide during troubleshooting?
  5. Why can high container CPU utilization be a misleading indicator of the root cause of latency?

Long Answer Questions

  1. Explain how logs, metrics, events, health checks and traces complement one another in a Docker environment.
  2. Describe a complete hypothesis-driven workflow for investigating a container that repeatedly restarts.
  3. Explain SLIs, SLOs, SLAs and error budgets, including how an error budget can influence release decisions.
  4. Discuss the design principles of useful production logs and the security risks of excessive logging.
  5. Explain how tracing and dependency metrics can identify a bottleneck that is not visible in application CPU metrics.

Analytical / Application Questions

  1. A service receives 40 requests per second, has an average response time of 0.25 seconds and shows increasing queue depth. Use Little's Law to estimate the average in-flight requests, then explain why this estimate alone is insufficient for deciding the number of containers.
  2. After a deployment, p95 latency increases and the error ratio rises, but containers remain running and CPU is moderate. Propose three hypotheses, identify evidence for each, and state a safe first mitigation.
  3. A team wants to add user ID, request ID and full request payload to every metric label and log entry. Evaluate this design with respect to cardinality, privacy, storage cost and troubleshooting value, and recommend a safer alternative.

Multiple Choice Questions with Answers

Question 1

Which signal is most directly suited to showing how a request travels across multiple services?

A. A container restart counter

B. A distributed trace

C. A host disk gauge

D. A Docker image tag

Correct Answer: B. A distributed trace

Question 2

A service receives 12,000 requests and 240 fail in the same interval. What is the error ratio?

A. 0.02 or 2%

B. 0.05 or 5%

C. 0.20 or 20%

D. 2.00 or 200%

Correct Answer: A. 0.02 or 2%

Question 3

Which health-check concept determines whether an instance should receive traffic?

A. Liveness

B. Readiness

C. Restart count

D. Image integrity

Correct Answer: B. Readiness

Question 4

For a 99.9% objective, what is the corresponding error budget as a proportion of the objective period?

A. 0.001

B. 0.009

C. 0.099

D. 0.999

Correct Answer: A. 0.001

Question 5

Which metric type is generally appropriate for total requests processed, from which a rate can be derived?

A. Gauge

B. Counter

C. Histogram bucket only

D. Trace span

Correct Answer: B. Counter

Question 6

A p95 latency of 500 ms means that approximately:

A. The average request takes 500 ms

B. 95% of the selected observations are at or below 500 ms

C. Every request takes at least 500 ms

D. 5% of requests succeed

Correct Answer: B. 95% of the selected observations are at or below 500 ms

Question 7

According to Little's Law, if the arrival rate is 20 requests per second and average response time is 0.5 seconds, the average number of in-flight requests is:

A. 4

B. 10

C. 20

D. 40

Correct Answer: B. 10

Question 8

Which troubleshooting action should normally occur before selecting a root cause?

A. Delete all stopped containers

B. Form hypotheses and test them against evidence

C. Increase every resource limit

D. Disable all health checks

Correct Answer: B. Form hypotheses and test them against evidence

Question 9

Which practice creates a high-cardinality metrics problem?

A. Using a bounded status-code label

B. Aggregating requests by service

C. Using unbounded user IDs as metric labels

D. Recording a deployment version

Correct Answer: C. Using unbounded user IDs as metric labels

Question 10

Why can a running container still provide a poor user experience?

A. Container state proves network availability

B. The process may be running while the application is slow or unable to serve requests

C. Running containers cannot emit logs

D. Docker automatically validates all dependencies

Correct Answer: B. The process may be running while the application is slow or unable to serve requests

Containerization with Docker
Chapter 10 of 15