>_ IzzyLab

Hands-on task

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

Process Count as a Metric

medium~10 min

Write /usr/local/bin/procmetric that counts the total number of processes in the system and prints the metric node_processes_total <value>. Output goes to /root/proc.prom.

What you'll practise:
  • monitoring
  • prometheus-metrics
  • process counting
  • /proc
  • ps

Topic breakdown

A metric in Prometheus format is a line of the form metric_name <number>, which an exporter drops into a .prom file and the scraper reads later. The task is to generate one such line with the process count. That number can be found two independent ways: enumerate the directories in /proc with purely numeric names (each corresponds to a PID), or count the lines in ps output, not forgetting the header line. In a container the PID namespace isolates the processes, so the counter reflects only this container.

What's checked

  1. Process metric is correct
  2. the script counts the real number of processes
  3. the script notices new processes

What it looks like