Skip to content

Instantly share code, notes, and snippets.

@abhirup-dev
Last active January 23, 2020 10:04
Show Gist options
  • Save abhirup-dev/d0cda05a6566cf473d85581b177b2b3f to your computer and use it in GitHub Desktop.
Save abhirup-dev/d0cda05a6566cf473d85581b177b2b3f to your computer and use it in GitHub Desktop.
Gnuplot files/scripts to capture and plot linux system metrics in real-time
#!/bin/bash
gnuplot -e "fname='$1'" liveplot.gnu
#!/usr/bin/gnuplot
set multiplot layout 3,1
unset xtics
plot fname using 2:xticlabels(1) with lines t "Memory%"
plot fname using 3:xticlabels(1) with lines t "Disk%"
plot fname using 4:xticlabels(1) with lines t "CPU%"
pause 0.5
reread
set autoscale
#!/bin/bash
TSTAMP=$(date +"%T-%M-%H")
end=$((SECONDS+60))
while [ $SECONDS -lt $end ]; do
MEMORY=$(free -m | awk 'NR==2{printf "%.2f%%\t\t", $3*100/$2 }')
DISK=$(df -h | awk '$NF=="/"{printf "%s\t\t", $5}')
CPU=$(top -bn1 | grep load | awk '{printf "%.2f%%\t\t\n", $(NF-2)}')
# FREE=$(free| awk '/Mem/{print $3" "$4}')
echo $TSTAMP" "$MEMORY" "$DISK" "$CPU
sleep 1
done
@abhirup-dev
Copy link
Author

abhirup-dev commented Jan 23, 2020

Steps to execute:-

  1. Save all three files in same directory
  2. Run ./logger.sh > out.dat or ./logger.sh | tee -a out.dat to record metrics in out.dat (tee -a appends; only tee overwrites)
  3. Run ./getplot.sh out.dat
  4. Customize liveplot.gnu to support custom plots

Useful links:-

  1. https://medium.com/@chamilad/basic-process-metrics-collection-and-visualization-in-linux-3d0fce3eeb87
  2. https://raymii.org/s/tutorials/GNUplot_tips_for_nice_looking_charts_from_a_CSV_file.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment