Sub topic 1
Why Monitor with Metrics
Prerequisites
This chapter assumes that you can use a Linux command line, understand basic system resources such as CPU, memory, and disk, and recognize that a monitoring system collects data from running services. You should also know that an application can produce logs and that servers communicate over networks.
What Metrics Tell You
A metric is a measured value recorded over time. Examples include CPU utilization, available memory, request count, request latency, and filesystem space. Each value has a timestamp, so you can compare the current state with earlier states.
Metrics help answer operational questions quickly:
- Is the server healthy now?
- Did performance change after a deployment?
- Which server is using the most CPU?
- Is disk space decreasing steadily?
- Did an outage affect one service or the whole system?
A metric usually represents a narrow, repeatable observation. This makes it useful for charts, comparisons, thresholds, and automated alerts.
Metrics Compared with Logs and Traces
Monitoring usually combines three kinds of operational data:
| Data type | Main question | Example |
|---|---|---|
| Metric | How much, how often, or how long? | CPU usage is 82% |
| Log | What event occurred? | The application rejected a configuration file |
| Trace | Where did a request spend time? | A database call took 900 ms |
Metrics provide a compact view of system behavior. Logs contain detailed event information but can be difficult to aggregate at scale. Traces follow individual requests through multiple services and are especially useful for distributed applications.
A metric might show that latency increased. A trace can identify the slow dependency, while a log may explain the error that dependency returned. These data types complement one another rather than replacing one another.
The Monitoring Feedback Loop
A useful monitoring system follows a loop:
Prometheus collects numeric measurements and stores them as time series. PromQL queries turn those series into useful views. Grafana displays the views in dashboards. Alert rules detect conditions that require attention, such as a server becoming unreachable. A response may involve restarting a service, adding capacity, or correcting a deployment.
Monitoring is effective only when someone can act on its results. A dashboard with hundreds of unused panels creates noise. An alert without a clear owner and response procedure creates interruptions without improving reliability.
Choosing Useful Metrics
Start with the basic resources and service signals:
- CPU usage and load
- Memory available and swap activity
- Disk space and I/O wait
- Network traffic and errors
- Request rate, errors, and latency
Record enough history to identify trends and compare normal behavior with unusual behavior. Also define what “healthy” means. For example, high CPU may be normal during a batch job but concerning when request latency rises at the same time.
Exercise
A server has 95% CPU usage for two minutes, but request latency, error rate, and queue length remain normal. Should this alone trigger a critical alert?
Show answer
Usually no. Investigate the cause, but alert severity should reflect user impact or a sustained resource risk. CPU usage alone may be normal for a batch workload.