>_ IzzyLab

Hands-on task

This task is step 14 of the course “Monitoring and metrics”

TTFB as a metric

medium~6 min

The service at http://localhost:9300/health takes suspiciously long to think before answering. Use curl to measure the time to first byte (TTFB) and write it as a Prometheus-format metric to /root/ttfb.prom — exactly one line probe_ttfb_seconds <seconds>, for example probe_ttfb_seconds 0.412.

What you'll practise:
  • curl -w
  • time_starttransfer
  • TTFB
  • Prometheus format
  • request metrics

Topic breakdown

curl -w (write-out) prints a line from a template after the request, filling in connection metrics: time_namelookup, time_connect, time_starttransfer, time_total and others. The time to first byte (time_starttransfer) shows how long the server "thought" before it started answering — the key indicator of a slow backend, unlike the total time, which also includes transferring the body. The template can contain arbitrary text, so curl outputs a ready Prometheus metric line right away: name, space, value. The body and progress are silenced so that only the metric ends up in the file.

What's checked

  1. ttfb.prom has a single metric line
  2. the value looks like a real TTFB

What it looks like