Skip to content

Instantly share code, notes, and snippets.

@drmalex07
Last active December 11, 2018 00:45
Show Gist options
  • Select an option

  • Save drmalex07/5fc9685a4d815f68b3614a23c43e012d to your computer and use it in GitHub Desktop.

Select an option

Save drmalex07/5fc9685a4d815f68b3614a23c43e012d to your computer and use it in GitHub Desktop.
A quick-n-dirty memory measurement. #proc-meminfo #memory

Take a measurement via /proc/meminfo and pipe it to a parser AWK script to turn it into a data row:

cat /proc/meminfo | parse-meminfo.awk

Maybe append it to a series of measurements (removing the extra header line from each measurement):

cat /proc/meminfo | parse-meminfo.awk | tail -n +2 | tee --append memory-measurements.csv

Plot measurements as time series:

gnuplot -c plot-memory-measurements.gnuplot memory-measurements.csv | display -
#!/usr/bin/awk -f
BEGIN {
FS=":"
total = 0;
free = 0;
cached = 0;
buffers = 0;
timestamp = systime(); # epoch seconds (as in `data +%s`)
printf ("timestamp;total;free;cached;buffers\n");
}
/^MemTotal:/ { total = int($2); }
/^MemFree:/ { free = int($2); }
/^Cached:/ { cached = int($2); }
/^Buffers:/ { buffers = int($2); }
END {
printf("%d;%d;%d;%d;%d\n", timestamp, total, free, cached, buffers);
}
DATAFILE = ARG1
set grid
set datafile separator ";"
set terminal png font "sans-serif,10"
set style fill solid 0.33
# the format to read x datapoints from input
set timefmt "%s"
# the format to write datapoints at x axis
set xdata time
#set format x "%b %d\n%H:%M"
set format x "%R"
# place a X tick every 2h
set xtic 7200
TITLE_1 = "Memory Used (%)"
plot DATAFILE using ($1):(100 * ($2 - $3 - $4)/($2)) with lines title TITLE_1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment