2

I've got a dataset that I'd like to generate a set of plots from, and I'm having trouble getting gnuplot to do it.

I've got a dataset with the following columns:

  • time (timestamp in ISO-8601 format YYYY-MM-DDTHH:mm:ss.sssZ)
  • client (hostname of the client; two distinct clients in the dataset)
  • server (hostname of the server; eight distinct servers in the dataset)
  • Two related stats, A1 and A2
  • Two other related stats, B1 and B2

A given timestamp generally has a single sample in it. I have around 7000 rows in the dataset. Some example rows would look like:

time                | client   | server   | stat A1 | stat A2 | stat B1 | stat B2
--------------------+----------+----------+---------+---------+---------+--------
2015-04-01T03:47:12 | client-x | server-1 | 12.2    | 20.0    |  2.3    |  7.0
2015-04-01T03:49:09 | client-y | server-6 | 15.0    | 25.2    | 10.0    | 15.2

I'd like to generate four plots, as line charts, one for every combination of related stats and client.

  1. client-x and stats A1 and A2
  2. client-x and stats B1 and B2
  3. client-y and stats A1 and A2
  4. client-y and stats B1 and B2

At this point, at at a complete loss as to how to approach this with gnuplot. I'm open to other options for generating the plot, but it needs to be scriptable as I get new/updated datasets.

Community
  • 1
  • 1
leedm777
  • 23,444
  • 10
  • 58
  • 87

1 Answers1

1

In order to get line plots, you must do the data filtering outside of gnuplot, e.g. with awk:

First setup the time format with

set xdata time
set timefmt '%Y-%m-%dT%H:%M:%S'

Then extract all possible client name, unless you already know the possible client names:

clients = system("awk '!/^#/ { print $2 }' test.dat | sort | uniq")

and then plot the data using multiplot

set style data lines
set multiplot layout 2,2

do for [client in clients] {
    set title sprintf("client '%s'", client)
    plot sprintf('< grep ''\b%s\b'' test.dat', client) using 1:4 title "A1", '' using 1:5 title "A2"
    plot sprintf('< grep ''\b%s\b'' test.dat', client) using 1:6 title "B1", '' using 1:7 title "B2"
}
unset multiplot

The question is quite similar to How to use one of the column of data as legend in gnuplot?.

Community
  • 1
  • 1
Christoph
  • 47,569
  • 8
  • 87
  • 187