Cloud Monitoring & Cost Optimization

Chapter 7
Monitoring Cloud-Native and Distributed Workloads

Advance Diploma in Cloud Computing
Cloud Monitoring & Cost Optimization   •   Advance Diploma

Monitoring Cloud-Native and Distributed Workloads

Introduction

Cloud-native systems are assembled from virtual machines, containers, Kubernetes objects, serverless functions, managed databases, object stores, networks, queues, and independently deployable microservices. Monitoring such systems is not simply a matter of checking whether a server is powered on. It requires evidence that the whole service is available, responsive, reliable, secure, and economically sustainable.

Distributed workloads create several difficulties. A user request may cross many services; resources may be created and destroyed within seconds; failures may be partial rather than total; and a single metric may contain millions of possible dimensions. Consequently, an effective observability design combines metrics, logs, traces, events, profiles, and cloud-provider metadata. It also connects technical measurements to service-level objectives and cost decisions.

This chapter presents a practical framework for monitoring cloud-native workloads at an advanced-diploma level. It emphasizes signal selection, workload-specific instrumentation, ephemeral resources, high-cardinality data, alert design, and operational decision-making.

Learning objectives

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

  1. Distinguish monitoring, observability, telemetry, logging, tracing, and profiling.
  2. Select meaningful metrics for virtual machines, containers, Kubernetes, serverless, databases, storage, networks, queues, and microservices.
  3. Explain how ephemeral infrastructure changes monitoring design.
  4. Design labels, dimensions, traces, and dashboards without creating unmanageable cardinality.
  5. Apply service-level indicators, objectives, error budgets, and alert thresholds.
  6. Diagnose a distributed incident using correlated metrics, logs, traces, and events.
  7. Evaluate governance, privacy, reliability, and cost implications of telemetry.

1. Monitoring and observability as complementary disciplines

Monitoring asks whether known conditions are within acceptable limits. Examples include CPU utilization above 90%, queue depth increasing, or database storage reaching 85%. Observability is the broader property of a system that permits engineers to infer its internal state from externally recorded outputs. A system can have many dashboards but still be poorly observable if those dashboards do not explain unfamiliar failures.

The principal telemetry signals are:

  • Metrics: Numeric measurements sampled over time, such as request rate, latency, memory use, or error rate.
  • Logs: Timestamped records of events, normally containing a severity, message, and contextual fields.
  • Traces: Records of an operation as it propagates through services. A trace consists of spans, each representing work in a component.
  • Events: State transitions or administrative actions, such as a Kubernetes pod eviction or a database failover.
  • Profiles: Statistical evidence of resource consumption, particularly CPU and memory allocation within application processes.

Metrics are efficient for alerting and long-term trends. Logs provide detailed context but may be expensive and difficult to aggregate. Traces reveal causal paths and latency contribution, but sampling is often required. Profiles explain performance hotspots but may require careful privacy and overhead controls. Mature operations therefore use each signal for the question it answers best.

The four useful questions

A monitoring design should answer four operational questions:

  1. Is the service available? Can users complete valid operations?
  2. Is it performing adequately? Are latency, throughput, and freshness acceptable?
  3. Why is it behaving this way? Which dependency, resource, deployment, or configuration is involved?
  4. What is the consequence? How many users, transactions, and dollars are affected?

The fourth question prevents teams from optimizing isolated infrastructure metrics while overlooking customer impact.

2. A model for reliable cloud monitoring

A practical monitoring architecture has five layers:

  1. Workload instrumentation: Applications and platforms emit metrics, logs, traces, and events.
  2. Collection: Agents, exporters, cloud integrations, or OpenTelemetry collectors receive telemetry.
  3. Processing: Data is parsed, enriched, sampled, filtered, aggregated, and possibly redacted.
  4. Storage and analysis: Time-series databases, log stores, trace stores, dashboards, and analytical systems retain data.
  5. Action: Alerts, tickets, runbooks, autoscaling, deployment gates, and cost controls use the evidence.

Context must travel consistently through the layers. A useful correlation model includes service name, environment, version, region, cluster, namespace, workload identity, and trace identifier. However, context should not be added indiscriminately. Every additional metric label can multiply the number of time series.

Service-level indicators and objectives

A service-level indicator (SLI) is a measured representation of service performance. Examples are successful request proportion, request latency below a threshold, and percentage of messages processed within a target time. A service-level objective (SLO) is the target value for an SLI over a defined period.

For a request-based availability SLI:

Availability = (Number of successful valid requests ÷ Total valid requests) × 100%

Here, “successful” must be defined, such as HTTP status codes below 500; “valid” excludes health checks or deliberately rejected requests where appropriate. The formula applies to a clearly defined observation window and assumes that numerator and denominator use the same population.

If an SLO is 99.9% over a 30-day month, the permitted unavailability is approximately:

Error budget = (1 − SLO) × Window

For a 30-day window, this is (1 − 0.999) × 30 × 24 × 60 ≈ 43.2 minutes. The budget is not merely a reporting number: it informs release risk, testing, and incident priorities.

For a latency SLI, the percentage of requests meeting the target is usually more informative than an average:

Latency compliance = (Requests with latency ≤ T ÷ Total valid requests) × 100%

T is the agreed latency threshold, measured in a specified unit such as milliseconds. Percentiles, especially p95 and p99, expose tail behavior that an arithmetic mean can hide.

3. Monitoring the major workload types

3.1 Virtual machines

For virtual machines, monitor four dimensions:

DimensionExamplesInterpretation
CapacityvCPU, memory, disk, networkWhether resources are sufficient
SaturationCPU steal, memory pressure, I/O wait, connection limitsWhether demand is approaching a bottleneck
HealthAgent status, boot failures, filesystem errorsWhether the instance is functioning
Service outcomeRequest rate, latency, errorsWhether users are affected

CPU utilization alone is insufficient. A machine can have moderate CPU use and still fail because of exhausted memory, file descriptors, disk inodes, network bandwidth, or connection pools. Monitor both operating-system indicators and application outcomes. Cloud-provider “burst” instances require attention to credit balance or equivalent throttling indicators because average CPU may conceal imminent performance reduction.

3.2 Containers and Kubernetes

Container monitoring has at least three levels:

  • Node: CPU, memory, disk pressure, network, kubelet health, and allocatable capacity.
  • Pod and container: restarts, termination reasons, CPU and memory usage, resource requests and limits, readiness, and liveness.
  • Workload and service: deployment availability, replica count, request rate, latency, errors, and rollout status.

A container restart is an event, not necessarily a diagnosis. The reason may be an out-of-memory kill, failed health probe, application crash, node eviction, or deliberate rollout. Kubernetes events and container termination state should therefore be correlated with logs and deployment history.

Resource requests influence scheduling; limits constrain consumption. If requests are set too low, nodes may be overcommitted and workloads may be evicted. If limits are too low, legitimate workloads may be killed. If both are excessively high, capacity and cost are wasted. Monitoring should compare requested, allocatable, and actually consumed resources.

Kubernetes labels should describe stable ownership and topology, such as namespace, workload, cluster, region, and version. Avoid putting request IDs, user IDs, timestamps, or unrestricted URLs into metric labels. Those belong in logs or traces.

3.3 Serverless functions

Functions are ephemeral and may scale rapidly. Important metrics include invocation count, duration, error count, throttles, concurrent executions, cold-start indicators where available, retry count, and downstream latency. For event-driven functions, monitor age of the oldest unprocessed event and batch failure behavior.

A function that reports low CPU utilization may still be unhealthy because it is throttled by concurrency, waiting on a database connection, or generating retries. The invocation path should be traced across API gateways, functions, queues, and databases. Cost analysis should include invocations, execution duration, memory allocation, provisioned concurrency, and associated data transfer—not only function count.

3.4 Managed databases

Managed services reduce infrastructure administration but do not remove monitoring responsibility. Track connections, transaction rate, query latency, lock waits, replication lag, cache effectiveness, storage growth, IOPS or throughput, backup status, failover events, and rejected operations.

Database monitoring should distinguish workload demand from database capacity. For example, increased query latency may result from inefficient queries, lock contention, insufficient memory, storage throttling, or a downstream application retry storm. Query-level telemetry should be sampled or aggregated carefully because literal query text and user parameters may expose sensitive information.

Replication lag is particularly important for read replicas and asynchronous systems. Its operational meaning depends on the application’s consistency requirement. A lag of several seconds may be harmless for reporting but unacceptable for payment authorization.

3.5 Object and block storage

Storage monitoring includes capacity, request rate, latency, error codes, throttling, replication status, lifecycle transitions, and retrieval activity. Object storage often has no traditional “disk full” condition; nevertheless, uncontrolled object growth creates cost and governance risks. Monitor storage by account, bucket or container, class, region, age, and ownership—preferably through periodic inventory rather than extremely high-cardinality real-time metrics.

Block storage requires monitoring of provisioned and consumed capacity, IOPS, throughput, queue depth, burst balance where applicable, and filesystem utilization. A volume can have free filesystem space but still be limited by I/O performance.

3.6 Networks and service connectivity

Network monitoring should cover packet loss, latency, throughput, retransmissions, connection failures, DNS resolution, load-balancer health, NAT or gateway exhaustion, and firewall decisions. In distributed systems, “the network” is not a single object. A request may traverse a client, CDN, load balancer, ingress, service mesh, virtual network, firewall, NAT gateway, and external dependency.

Flow logs are valuable for reachability and security investigations, but they are not substitutes for application-level latency and error data. A permitted flow does not prove that an application accepted or processed the request.

3.7 Queues and event streams

For queues, the central indicators are depth, age, arrival rate, processing rate, retry count, dead-letter volume, visibility timeout expirations, and consumer health. Queue depth alone can be misleading. A large but stable backlog may be less urgent than a small backlog whose oldest message is rapidly aging.

A useful operational relationship is Little’s Law:

L = λW

L is the average number of items in the system, λ is the stable average arrival rate in items per unit time, and W is the average time an item spends in the system. The relationship assumes a stable system over the observation period and consistent definitions of arrivals, items, and residence time. For example, at 20 messages per second and an average residence time of 3 seconds, the average in-system population is 60 messages. This is an approximation for planning, not a guarantee during bursts or unstable backlog growth.

3.8 Microservices

Microservice dashboards should combine the “golden signals”: latency, traffic, errors, and saturation. Add dependency health, deployment version, retry rate, timeout rate, circuit-breaker state, and message processing delay. A service may be internally healthy but externally failing because a dependency is slow.

Distributed tracing represents one operation as a trace containing spans. Each span should identify the service, operation, start time, duration, outcome, and relevant attributes. Trace sampling must preserve unusual failures and slow requests rather than sampling only uniformly. Tail-based sampling can retain traces after their outcome is known, although it demands additional collector capacity.

4. Ephemeral resources and identity

Traditional monitoring assumes a stable host name. Cloud-native systems invalidate that assumption. Pods are rescheduled, functions disappear, spot instances are reclaimed, and autoscaling changes the population continuously.

Monitoring should therefore use two complementary identities:

  • Stable logical identity: service, workload, environment, region, tenant class, and version.
  • Ephemeral physical identity: pod ID, instance ID, container ID, or invocation ID.

Stable identity supports trends and alerting. Ephemeral identity supports forensic investigation. Retaining every ephemeral identity forever creates fragmented dashboards and expensive telemetry. Use short retention or aggregation for instance-level data, while retaining service-level summaries longer.

A robust design also records lifecycle events: creation, deployment, scaling, eviction, termination, failover, and configuration change. Without these events, engineers may mistake an intentional replacement for a failure.

5. High-cardinality telemetry

Cardinality is the number of distinct combinations of label values in a metric. If a metric has four dimensions with 5, 10, 3, and 20 possible values, the maximum combinations are:

5 × 10 × 3 × 20 = 3,000

Real systems may not use every combination, but the example shows why dimensions multiply. A request metric labelled by user ID, request ID, URL, and arbitrary error text can grow without bound. High cardinality increases memory, ingestion, query, and storage costs and may degrade the monitoring system itself.

Use bounded dimensions for metrics: service, route template, method, status class, region, and deployment version. Use logs and traces for unbounded values such as request IDs, account IDs, order IDs, and full URLs. Normalize routes so that /users/18492 becomes /users/{id}. Hashing is not automatically safe: a hash still creates many values and may remain linkable.

Cardinality control techniques include:

  • allowlists for metric labels;
  • aggregation at the collector;
  • route templating;
  • sampling traces and verbose logs;
  • separate low-cardinality operational metrics from analytical event data;
  • retention tiers for raw and aggregated telemetry;
  • quotas and admission controls;
  • periodic cardinality reports.

6. Alerting and diagnosis

An alert should represent an actionable condition, have a responsible owner, and link to a runbook. Prefer symptoms that indicate user impact, such as SLO burn, elevated error rate, or message age, over every low-level anomaly.

Static thresholds remain useful for hard limits, such as certificate expiry or storage exhaustion. For seasonal workloads, baselines and anomaly detection may help, but automated anomalies must be tested to avoid alert fatigue. A good alert includes scope, duration, severity, impact, likely causes, dashboard links, and immediate action.

A practical incident sequence is:

  1. Confirm the user-facing symptom.
  2. Establish start time, affected regions, versions, and workloads.
  3. Compare traffic, errors, latency, and saturation.
  4. Follow traces to the slowest or failing dependency.
  5. Check deployment, scaling, quota, and provider events.
  6. Mitigate safely, then preserve evidence for root-cause analysis.

7. Worked application: an illustrative online-order platform

Background

An illustrative retailer runs an API gateway, Kubernetes-based order and catalog services, a managed relational database, an event queue, object storage for invoices, and a serverless notification function.

Problem

During a promotion, customers report delayed order confirmation. The API error rate is only 1.5%, but the p99 latency rises from 900 ms to 8 seconds. Queue depth grows, and notification retries increase.

Analysis

The team first checks the SLO dashboard rather than individual pod CPU. Traces show that order requests wait on the database. Database connections are exhausted, while CPU remains moderate. Application logs reveal that a newly deployed order-service version performs an additional query per item. Queue telemetry shows that notification delay is a consequence, not the initial fault. Kubernetes events show no node failures.

Approach and solution

The team rolls back the deployment, increases observability around query duration, and temporarily limits promotion traffic. It then adds a bounded metric for query operation and version, retains sampled traces for slow orders, and introduces a database connection-pool saturation alert. A load test is added to the release process.

Outcome

p99 latency returns below the SLO threshold, queue age declines, and notification retries stop. The incident demonstrates why service outcome, traces, database saturation, deployment events, and queue age must be analyzed together.

Learning points

The highest CPU host was not the root cause. Moderate infrastructure utilization did not imply healthy service behavior. A small code change amplified database demand, and the queue exposed the downstream effect. Monitoring must connect technical signals to causal paths and customer impact.

8. Cost, governance, and responsible telemetry

Telemetry is itself a cloud workload. Costs arise from collection agents, ingestion, indexing, storage, queries, cross-region transfer, and retention. Cost optimization must not destroy evidence required for reliability or compliance. A sensible policy classifies data into hot, warm, and archive tiers; samples routine traces; retains all critical errors; and aggregates long-term trends.

Governance requirements include access control, encryption, retention schedules, audit trails, and data residency. Logs may contain passwords, tokens, payment data, health information, or personal identifiers. Redaction should occur before data leaves the workload where practical. Access to trace attributes and user-linked logs should follow least privilege.

Artificial intelligence can assist with anomaly grouping, incident summarization, and probable-cause suggestions. It should not silently change production configuration or suppress alerts without human-approved controls. AI-generated explanations must be checked against raw telemetry because correlation is not proof of causation.

9. Best-practice design checklist

  • Begin with user journeys and SLOs, not with the list of available metrics.
  • Instrument every important service boundary with consistent context.
  • Monitor golden signals plus workload-specific saturation indicators.
  • Treat deployments, scaling, failover, and eviction as first-class events.
  • Separate stable service identity from ephemeral resource identity.
  • Keep metric labels bounded; place high-cardinality data in logs or traces.
  • Alert on actionable symptoms and provide runbooks.
  • Test dashboards and alerts during load tests and failure simulations.
  • Apply sampling, retention tiers, and query controls to manage cost.
  • Protect telemetry as sensitive operational data.
  • Review monitoring coverage after incidents and architectural changes.

Chapter Summary

Cloud-native monitoring is an integrated discipline for understanding dynamic, distributed systems. Metrics provide efficient trends and alerting; logs provide event detail; traces connect latency and failures across service boundaries; events explain lifecycle and control-plane changes; and profiles reveal code-level resource consumption. Effective monitoring combines workload, platform, dependency, and user-outcome perspectives.

Virtual machines require more than CPU monitoring. Containers and Kubernetes require node, pod, workload, and event visibility. Serverless systems require invocation, duration, throttling, concurrency, and retry analysis. Databases, storage, networks, queues, and microservices each have distinctive saturation and reliability indicators. Ephemeral resources require stable logical identities alongside short-lived physical identities. High-cardinality dimensions must be controlled through bounded labels, aggregation, sampling, and appropriate signal selection.

SLIs and SLOs turn telemetry into service commitments, while error budgets connect reliability to release decisions. Cost, privacy, security, retention, and governance must be designed into telemetry rather than addressed after deployment. The central professional principle is to monitor what users experience, then use correlated technical evidence to explain and improve it.

Key Terms

Cardinality: Number of distinct values or label combinations in telemetry.

Container: An isolated process package containing application code and dependencies.

Distributed trace: A correlated record of an operation across multiple components.

Ephemeral resource: A resource whose identity or existence may change frequently.

Error budget: Permitted unreliability implied by an SLO over a specified window.

Event: A recorded state transition or operational action.

Golden signals: Latency, traffic, errors, and saturation.

High-cardinality data: Telemetry with a very large number of distinct values.

Instrumentation: Code or agents that produce telemetry.

Little’s Law: Relationship L = λW between population, arrival rate, and residence time under stable conditions.

Metric: A numeric measurement recorded over time.

Observability: Ability to infer internal system state from external outputs.

OpenTelemetry: A vendor-neutral framework and specification for generating and exporting telemetry.

Sampling: Selecting a subset of telemetry for collection or retention.

Service-level indicator: A quantitative measure of a service characteristic.

Service-level objective: A target value for an SLI over a defined period.

Span: A timed unit of work within a distributed trace.

Telemetry: Data emitted by systems for monitoring and analysis.

Throttling: Deliberate limitation of processing or resource consumption.

Workload identity: Stable logical identity assigned to an application workload.

Review Questions

Short Answer Questions

  1. Distinguish monitoring from observability.
  2. Name the four golden signals.
  3. Why is CPU utilization insufficient for monitoring a virtual machine?
  4. What is high-cardinality telemetry?
  5. State the purpose of a service-level objective.

Long Answer Questions

  1. Explain how metrics, logs, traces, events, and profiles complement one another in a distributed system.
  2. Describe a monitoring strategy for a Kubernetes application, including nodes, pods, workloads, and events.
  3. Explain how ephemeral resources affect identity, retention, and incident investigation.
  4. Discuss the operational and financial consequences of poorly designed metric labels.
  5. Design an observability approach for a serverless function connected to a queue and managed database.

Analytical / Application Questions

  1. A queue receives 30 messages per second and messages remain in the system for an average of 4 seconds. Using Little’s Law, estimate the average number of messages in the system and state the assumptions required.
  2. A service has an availability SLO of 99.5% over a 30-day month. Calculate the approximate error budget in minutes and explain how it could influence deployment decisions.
  3. During an incident, API latency increases, database CPU remains moderate, connection utilization reaches its limit, and queue age grows. Construct a causal hypothesis and identify the telemetry you would inspect next.

Multiple Choice Questions with Answers

Question 1

Which signal is most directly suited to following one request across several microservices?

A. A distributed trace

B. A host disk metric

C. A storage lifecycle event

D. A CPU profile

Correct Answer: A. A distributed trace

Question 2

Which label is generally most appropriate for a bounded operational metric?

A. User ID

B. Request ID

C. Service name

D. Full URL with query parameters

Correct Answer: C. Service name

Question 3

What does an SLO represent?

A. A target for a service-level indicator over a defined period

B. A list of all infrastructure resources

C. A database backup file

D. A trace sampling algorithm

Correct Answer: A. A target for a service-level indicator over a defined period

Question 4

Under the stable conditions of Little’s Law, if the arrival rate is 20 messages per second and average residence time is 3 seconds, what is the average population?

A. 6 messages

B. 17 messages

C. 23 messages

D. 60 messages

Correct Answer: D. 60 messages

Question 5

Which metric is especially important for detecting delayed queue processing?

A. Age of the oldest unprocessed message

B. Number of dashboard users

C. Virtual-machine boot image size

D. Object-storage filename length

Correct Answer: A. Age of the oldest unprocessed message

Question 6

Why should Kubernetes termination reasons be correlated with events and logs?

A. A restart alone does not identify its cause

B. Kubernetes pods never generate events

C. Logs cannot contain timestamps

D. Termination reasons measure customer satisfaction directly

Correct Answer: A. A restart alone does not identify its cause

Question 7

Which practice best controls metric cardinality?

A. Adding request IDs to every metric label

B. Using route templates and bounded dimensions

C. Creating a new label for every log message

D. Using unrestricted user-entered text as a label

Correct Answer: B. Using route templates and bounded dimensions

Question 8

For a 99.9% SLO over a 30-day month, the approximate error budget is:

A. 4.32 minutes

B. 43.2 minutes

C. 432 minutes

D. 4,320 minutes

Correct Answer: B. 43.2 minutes

Question 9

Which combination is most appropriate for monitoring a serverless function?

A. Invocation count, duration, errors, throttles, and concurrency

B. Only physical rack temperature

C. Only virtual-machine disk fragmentation

D. Only object names

Correct Answer: A. Invocation count, duration, errors, throttles, and concurrency

Question 10

What is a major governance concern when collecting application telemetry?

A. Telemetry may contain sensitive personal or security information

B. Metrics cannot be stored in cloud systems

C. Traces eliminate the need for access control

D. Sampling guarantees legal compliance

Correct Answer: A. Telemetry may contain sensitive personal or security information

Cloud Monitoring & Cost Optimization
Chapter 7 of 15