0
votes

I have a bash script to log sar output for cpu load and memory usage and it outputs logged stats in csv format. But how would I go about creating a gnuplot chart from the csv output and do so solely from command line without an interactive commands/input ?

Basically, I want to extend my bash script to log sar output, output to csv and create the gnuplot charts all by running the bash script.

The current

sar cpu load csv output

Time,runq-sz,plist-sz,ldavg-1,ldavg-5,ldavg-15
02:04:36AM,0,171,0.00,0.00,0.00
02:04:37AM,0,171,0.00,0.00,0.00
02:04:38AM,0,171,0.00,0.00,0.00

sar mem csv output

Time,kbmemfree,kbmemused,%memused,kbbuffers,kbcached,kbcommit,%commit
02:11:38AM,1501736,811188,35.07,38852,101808,2628024,49.03
02:11:39AM,1501488,811436,35.08,38852,101808,2628024,49.03
02:11:40AM,1501364,811560,35.09,38852,101808,2628024,49.03

Any advice is greatly appreciated :)

1

1 Answers

2
votes

One way (perhaps the easiest) to do it is to use this syntax:

#!/bin/bash
outputname="output"
gnuplot << eor
 set terminal png
 set output '$outputname.png'
 set datafile separator ","
 plot 'datafile' u 1:2, '' u 1:3 ...
 <other gnuplot commands here>
eor

As I have shown, bash variable names can be escaped inside the gnuplot command lines.