>_ IzzyLab

Hands-on task

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

Load average as a metric

medium~10 min

Write /usr/local/bin/loadmetric — a mini load average exporter. It reads /proc/loadavg and prints three metrics, one line each: node_load1, node_load5 and node_load15 — the values over 1, 5 and 15 minutes. Like the real node_exporter (the --path.procfs flag), the procfs directory can be substituted: if the PROCFS environment variable is set, the script reads $PROCFS/loadavg, otherwise /proc/loadavg. Save the output to /root/load.prom.

What you'll practise:
  • prometheus
  • /proc/loadavg
  • metrics
  • awk
  • parsing

Topic breakdown

Load average is the averaged task queue length over 1, 5 and 15 minutes; the kernel exposes it via /proc/loadavg, where these three numbers come first, followed by the runnable/total processes ratio and the last PID. The task teaches turning a system source into a Prometheus metric of the form name value, cutting out the right field with text utilities (cut/awk). It's important to preserve the fractional part of the value: a number cut out as a field stays fractional on its own, but integer arithmetic like $(( )) would truncate the tail after the dot — which you must not do.

What's checked

  1. Script is executable
  2. load.prom has three load average metrics
  3. the script reads loadavg from $PROCFS
  4. without PROCFS the script reads /proc/loadavg

What it looks like