DevOps.Academy
CoursesCurriculumInterview prepPricing
◔My learningSign in
DevOps.Academy

Free, hands-on DevOps lessons. Made with care in India.

System status

Learn

All coursesLinux roadmapCurriculumInterview questionsCheat sheetsMy learning

Academy

PricingCertificates

Legal

PrivacyTermsContact

devops.rajeev.pro

Monitoring · revision

Monitoring cheat sheet

Recall first: read each stage's one-line summary and try to remember its commands. Then open the stage to check yourself.

9 stages51 commands

01Observability basicsMetrics tell you that something is wrong, traces tell you where, logs tell you why. Watch the four golden signals first: latency, traffic, errors and saturation.
  • uptime

    Load average over 1, 5 and 15 minutes

  • nproc

    Number of CPU cores, to compare with the load average

  • free -m

    Memory in MB; read the available column, not free

  • df -h

    Disk use per filesystem, saturation at a glance

  • journalctl -p err -b -n 20

    The last 20 error-level log entries since boot

  • curl -o /dev/null -s -w "%{http_code} %{time_total}\n" https://example.com

    Status code and total time for one request (errors and latency)

Remember

  • Counters only go up, gauges go up and down, histograms count values into buckets.
  • Use p95 or p99, not the average: averages hide the slow tail.
  • Put the same trace_id in logs and traces so you can jump between them.

Watch for A load average above nproc means work is queueing, even if CPU graphs look calm.

Open the lesson: Metrics, logs and traces →
02PrometheusPrometheus scrapes /metrics from every target it expects, stores samples for 15 days by default and answers PromQL. A failed scrape becomes up = 0, so a dead server is a number you can alert on.
  • docker exec prometheus promtool check config /etc/prometheus/prometheus.yml

    Validate the config and rule files before a restart

  • docker exec prometheus promtool query instant http://localhost:9090 'up'

    Run an instant query from the command line; 1 means the scrape worked

  • curl -s localhost:9100/metrics | grep -vc '^#'

    Count the series node_exporter serves

  • node_filesystem_avail_bytes{mountpoint="/", fstype!="tmpfs"}

    Select series with label matchers

  • 100 * (1 - avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])))

    CPU busy as a percentage per machine

  • histogram_quantile(0.95, sum by (le) (rate(prometheus_http_request_duration_seconds_bucket[5m])))

    p95 latency from a histogram; keep the le label

  • node_load1 / on (instance) count by (instance) (node_cpu_seconds_total{mode="idle"})

    Load per CPU core, matching both sides on instance only

  • predict_linear(node_filesystem_avail_bytes{mountpoint="/"}[1h], 4*3600) / 1e9

    Free disk in GB projected 4 hours ahead

Remember

  • Always wrap a counter in rate() or increase(); use a window at least 4x the scrape interval.
  • An empty division result is almost always a label mismatch: add on (label).
  • Name recording rules level:metric:operations, like instance:node_cpu_utilisation:rate5m.

Watch for Every unique label value is a new series. User IDs or full URLs as labels run Prometheus out of memory.

Open the lesson: Prometheus and PromQL →
03GrafanaGrafana stores dashboards, not metrics. Each panel sends its saved query to a data source for the chosen time range. Provision data sources and dashboards from Git so a lost Grafana is rebuilt in minutes.
  • docker run -d --name grafana --network mon -p 3000:3000 grafana/grafana

    Start Grafana on the same network as Prometheus

  • curl -s localhost:3000/api/health

    Check Grafana is up and see its version

  • curl -s -u admin:admin localhost:3000/api/datasources

    List data sources; provisioned ones show readOnly true

  • curl -s -u admin:admin "localhost:3000/api/search?query=node"

    Confirm a provisioned dashboard loaded, with its folder

  • label_values(node_uname_info, instance)

    Query for an instance variable listing every node_exporter host

  • 100 * (1 - avg by (instance) (rate(node_cpu_seconds_total{mode="idle", instance=~"$instance"}[5m])))

    CPU used panel filtered by the dashboard variable

Remember

  • The data source URL is resolved by the Grafana server: use http://prometheus:9090 in Docker, not localhost.
  • Filter with instance=~"$instance", because multi-value and All become a regex.
  • Set a unit and thresholds on every panel; prefer $__rate_interval over a fixed [5m].

Watch for A single panel saying "No data" is usually a bad query. Run it in Explore.

Open the lesson: Grafana dashboards →
04AlertingPrometheus evaluates alert rules and only says "firing". Alertmanager routes, groups, inhibits and silences alerts and decides who hears about them, how and how often.
  • docker exec prometheus promtool check rules /etc/prometheus/rules.yml

    Validate alert and recording rules

  • docker exec alertmanager amtool check-config /etc/alertmanager/alertmanager.yml

    Validate the Alertmanager config before a reload

  • amtool config routes --config.file=/etc/alertmanager/alertmanager.yml

    Print the routing tree

  • amtool config routes test --config.file=/etc/alertmanager/alertmanager.yml severity=page alertname=TargetDown

    Show which receiver a set of labels would reach

  • amtool silence add --alertmanager.url=http://localhost:9093 \ alertname=TargetDown instance=node-exporter:9100 \ --duration=2h --author=rajeev --comment="Planned reboot of node-exporter host"

    Silence an alert for planned work, with an author, comment and end time

  • amtool alert query -s --alertmanager.url=http://localhost:9093

    List alerts including silenced ones, shown as suppressed

  • curl -s localhost:9090/api/v1/alertmanagers

    Check that Prometheus found Alertmanager

Remember

  • Rule states: inactive, pending (true but not for the full for), firing.
  • group_wait batches the first message; group_interval paces updates and resolved messages.
  • Alert on symptoms users feel, predict_linear for things that fill up, and give every alert a runbook.
  • A Watchdog alert with vector(1) proves the pipeline itself works.

Watch for up == 0 can't fire for a target that vanished entirely. Add absent(up{job="..."}) for critical jobs.

Open the lesson: Alerting with Alertmanager →
05LogsAlloy reads and labels logs, Loki stores them as streams indexed by labels only, and Grafana searches them with LogQL. Every query starts with a stream selector, then a pipeline joined by |.
  • docker run -d --name loki --network mon -p 3100:3100 grafana/loki

    Start Loki next to Prometheus and Grafana

  • curl -s localhost:3100/ready

    Check Loki is ready to accept logs

  • curl -s localhost:3100/loki/api/v1/labels

    List the label names Loki knows

  • curl -s localhost:3100/loki/api/v1/label/container/values

    List the values of one label

  • {container="hotrod"} |= "ERROR"

    Keep only lines containing ERROR from one stream

  • sum by (container) (count_over_time({host="lab-1"}[5m]))

    Turn log lines into a count per container

  • alloy convert --source-format=promtail

    Translate an old Promtail config to Alloy

Remember

  • Keep labels few and low-cardinality; put user_id or trace_id in the line and filter for it.
  • | json needs the whole line to be JSON; use the pattern parser for mixed formats.
  • Failed parses keep the line and add an __error__ label instead of hiding it.

Watch for Centralised logs centralise leaked secrets too. Mask them before shipping and set a retention period.

Open the lesson: Centralised logs with Loki →
06TracingA trace is the tree of spans for one request, tied together by a trace ID passed in the traceparent header. Instrument with OpenTelemetry, send OTLP to a Collector, and read the waterfall in Jaeger.
  • docker run -d --name jaeger --network mon -p 16686:16686 -p 4317:4317 -p 4318:4318 jaegertracing/jaeger

    Run Jaeger with its UI and OTLP gRPC and HTTP ports

  • opentelemetry-instrument python app.py

    Zero-code instrumentation for a Python app

  • OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4318

    Tell the SDK where to send OTLP over HTTP

  • curl -s localhost:16686/api/traces/<trace-id> > ~/trace.json

    Fetch one trace from Jaeger's API

  • {container="hotrod"} |= "9881c56bd9002eeee8637029115c5b57"

    Every log line of one request, by its trace ID

Remember

  • OTLP uses port 4317 for gRPC and 4318 for HTTP.
  • A service that drops traceparent starts a new trace and splits the waterfall.
  • Head sampling is cheap but loses slow and failed requests; tail sampling keeps them at the cost of a Collector with memory.

Watch for Sequential spans of the same call, like fourteen GetDriver calls in a row, are an N+1 pattern. Batch them.

Open the lesson: Tracing with OpenTelemetry and Jaeger →
07Kubernetes monitoringkube-prometheus-stack installs the Prometheus Operator, Prometheus, Alertmanager, Grafana, node-exporter and kube-state-metrics. ServiceMonitors tell the Operator what to scrape.
  • helm repo add prometheus-community https://prometheus-community.github.io/helm-charts

    Add the chart repository

  • helm install monitoring prometheus-community/kube-prometheus-stack \ --namespace monitoring --create-namespace

    Install the stack with release name monitoring

  • kubectl get pods -n monitoring

    Check the operator, Prometheus, Grafana and exporters are running

  • kubectl port-forward -n monitoring svc/monitoring-kube-prometheus-prometheus 9090

    Reach the Prometheus UI from your machine

  • kubectl port-forward -n monitoring svc/monitoring-grafana 3000:80

    Reach Grafana from your machine

  • kubectl get servicemonitor -n shop

    List ServiceMonitors in a namespace

  • increase(kube_pod_container_status_restarts_total[1h]) > 0

    Containers that restarted in the last hour

  • kube_pod_container_status_last_terminated_reason{reason="OOMKilled"} == 1

    Containers whose last restart was an OOM kill

Remember

  • kube-state-metrics is what Kubernetes thinks; cAdvisor is what containers actually use.
  • The scheduler places pods by requests, so Pending pods can appear on idle-looking nodes.
  • CPU throttling above about 25% means the CPU limit is too low for bursts.

Watch for A missing target is almost always the release label, the selector, or a port number instead of the port name.

Open the lesson: Monitoring Kubernetes →
08SLOs & on-callAn SLI is good events over all events, an SLO is its target over a window, and 1 minus the SLO is the error budget. Alert on how fast the budget burns, and back every alert with a runbook.
  • sum(rate(hotrod_requests_total{endpoint="GET_/dispatch", error="false"}[30d])) / sum(rate(hotrod_requests_total{endpoint="GET_/dispatch"}[30d]))

    Availability SLI over 30 days

  • sum(rate(hotrod_request_latency_bucket{endpoint="GET_/dispatch", le="1"}[30d])) / sum(rate(hotrod_request_latency_count{endpoint="GET_/dispatch"}[30d]))

    Latency SLI, share of requests within 1 second

  • systemctl status node_exporter

    First runbook step for TargetDown on a server

Remember

  • 99.9% over 30 days is a 43.2-minute budget; each extra nine is about ten times harder.
  • Burn rate 14.4 over 1 hour uses 2% of the budget: page. Burn rate 1 over 3 days: ticket.
  • A latency SLI needs a histogram bucket exactly at the threshold.

Watch for Don't promise more than you depend on. A 99.99% SLO on a 99.95% database is a wish.

Open the lesson: SLOs, error budgets and on-call →
09Hosted toolsDatadog, New Relic and Dynatrace collect the same three signals and add APM, RUM, synthetics, correlation and AI. Self-hosted cost is mostly people; hosted cost is mostly data volume.
  • SELECT average(duration) FROM Transaction FACET name SINCE 1 hour ago

    An NRQL query in New Relic, average duration per transaction

Remember

  • Datadog charges per product, with custom metrics billed by distinct series.
  • New Relic charges by GB ingested plus users; Dynatrace by host memory per hour.
  • Instrument with OpenTelemetry so the vendor is a Collector exporter, not a code change.

Watch for Set an ingestion cap or usage alert on day one, or a runaway debug log shows up on the invoice.

Open the lesson: Hosted monitoring: Datadog, New Relic and Dynatrace →
← Back to the Monitoring course