>_ IzzyLab

Hands-on task

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

Uptime as a Metric

easy~7 min

Write /usr/local/bin/uptimemetric that takes the uptime from /proc/uptime (the first number, in seconds) and prints the metric node_uptime_seconds <value>. Output goes to /root/uptime.prom.

What you'll practise:
  • monitoring
  • prometheus-metrics
  • /proc/uptime
  • field extraction
  • awk/cut

Topic breakdown

The kernel publishes counters in the /proc pseudo-files, and the exporter just has to move a ready-made value into a metric. In /proc/uptime there are two numbers: the first is the system's running time since boot in seconds (the one you need), the second is the total idle across all cores (not to be confused). The task boils down to pulling the line's first field with a tool like awk or cut and substituting it into the metric line name <value>.

What's checked

  1. Uptime metric is correct
  2. the script takes the uptime from /proc/uptime

What it looks like