GNU Plot Basics with XEN metrics

Grabbing the Metrics

Say that you want to get a plot against XEN guests activity, from a XEN host.

cd /data/guests/
xl create load1/load1
xl create load2/load2
xl create load3/load3

Three seconds is the default delay for xentop to deliver the metrics. And we usually get rid of the first metric, either because the percentage is zero or because we need to substract the overall count from the previous iteration. So during one minute,

mkdir -p /var/tmp/xentop/
cd /var/tmp/xentop/
rm -f xentop*
(( time = 0 )); until (( time >= 60 )); do (( time++ )); echo -n "$time "; sleep 1; done &
xentop -f -b -i$(( 60 / 3 + 1 )) > xentop
unset time

to help your stress the guest in due time,

stress --help
nice stress --cpu 16

Grab each guest’s metrics in a separate file,

for guest in load1 load2 load3; do
    egrep "^[[:space:]]*$guest " xentop > xentop.$guest
    wc -l xentop.$guest
done; unset guest

Taking CPU(sec), not CPU(%), we need to substract the values from the previous iteration,

vi convertcpu

[[ -z $1 ]] && print what guest? && exit 1
(( sec = 0 ))
for time in `awk '{print $3}' xentop.$guest`; do
        (( diff = time - timeold ))
        print "$sec\t$diff"
        (( sec = sec +3 ))
done; unset cputime

chmod +x convertcpu

As a result you get the time on the first col, and CPU(sec) on the second col.

for guest in load1 load2 load3; do
    ./convertcpu $guest | sed 1d > table.$guest
done; unset guest

Note. we are removing the first line from those tables, as its diff would not make any sense.

Delivering the Plot

#apt install gnome-themes-standard


set term png
set output "output.png"

set title "load1,2,3 vcpu usage"
set xlabel "60 seconds"
set ylabel "vcpu times"
set xrange [0:60]
set yrange [0:35]

set multiplot

set key at 60,35
plot "table.load1" title "load1" smooth csplines lt 1

set key at 60,34
plot "table.load2" title "load2" smooth csplines lt 2

set key at 60,33
plot "table.load3" title "load3" smooth csplines lt 3

gnuplot -c

Interactive use

Other useful commands,


Other nice terminals,

#set term pdf mono
#set output "output.pdf"

Check for avaiable terminals,

set term


Plotting Data with gnuplot

GNUPLOT 4.2 - A Brief Manual and Tutorial

output formats

Output terminals

multiple graphs

gnuplot plotting multiple line graphs

smooth lines

How to output smooth cspline curve as a data file


Library – Gnuplot Examples

gnuplot Frequency Plot


Gnuplot line types

gnuplot demo script: lines_arrows.dem

Linetypes, colors, and styles,-colors,-and-styles.html

Gnuplot Line Styles for Display and Printing

15 Linetype, colors, and styles


Multiple lines with different colors



Library – Gnuplot Examples

1.17.2 linestyles vs linetypes

How to plot a bar graph on Gnuplot

Copyright © 2024 Pierre-Philipp Braun