>_ IzzyLab

Hands-on task

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

Memory from /proc/meminfo

medium~10 min

Write /usr/local/bin/memfree that takes MemAvailable from /proc/meminfo (in kilobytes) and prints the metric node_memory_available_kb <value>. Output goes to /root/mem.prom.

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

Topic breakdown

/proc/meminfo is a text snapshot of memory as pairs Key: value kB, and the task teaches you to carefully pull one specific field out of it for a Prometheus metric of the form name value. The main trap is pattern precision: the line about available memory sits next to keys with similar prefixes (total, free), so the match must be anchored to the start of the line, otherwise you'll catch extra ones. The metric value is only the number (the line's second field); the kB unit suffix at the end is not part of the metric and must not be captured.

What's checked

  1. memory metric is correct
  2. the script takes MemAvailable from /proc/meminfo

What it looks like