0

I have a problem with a gnuplot script.

my data file, have the following format, (values are as example)

# timestamp        |- user1 -|       |-user2-|          |-user3-|
# ms            procs cpu% mem%   procs cpu% mem%    procs cpu% mem%
1234            10    12   13       20   22   23      30    32   33
1235            19    15   16       29   25   26      39    35   36

my gnuplot code is

reset

USERS="user1 user2 user3"

VAL(g,c)= (3*(g-1)) + c  

plot for [i=1:words(USERS)] "__GCRONDIR__/.data/usrstat.log" \
   u 1:VAL(i,3) t word(USERS,i)." cpu:".i  __STYLE0__, \
"" u 1:VAL(i,4) t word(USERS,i)." mem:".i  __STYLE0__

my problem is that the loop, happens only for the last user, so if a have 10 users, lets say, this script, will plot 9 cpu's values, for the first 9 users, and both values for the last one. ... for me make no sense, any one?

here a screen shot ;)

enter image description here

2 Answers 2

1

It seems that gnuplot plots in loop only one line at once, and the second part of your loop is treated as a separate plot. Gnuplot first plots all "cpu" lines in a loop:

plot for [i=1:words(USERS)] "__GCRONDIR__/.data/usrstat.log" \
   u 1:VAL(i,3) t word(USERS,i)." cpu:".i  __STYLE0__, \

and then the last "mem" line:

"" u 1:VAL(i,4) t word(USERS,i)." mem:".i  __STYLE0__

You can use nested loops instead:

kind(k)=(k==1? "cpu: " : "mem: ")
plot for [i=1:5] for [j=1:2] (i-1)*2+j t sprintf("%s %d", kind(j), i)

enter image description here

For your case it would be something like this:

reset
USERS="user1 user2 user3"
VAL(g,c)= (3*(g-1)) + c  
kind(k)=(k==3? "cpu:" : "mem:")
plot for [i=1:words(USERS)] \
for [j=3:4] \
"__GCRONDIR__/.data/usrstat.log" \
   u 1:VAL(i,j) t word(USERS,i).kind(j).i  __STYLE0__
Sign up to request clarification or add additional context in comments.

2 Comments

this format dont work, inside the script, i get exactly the straight lines, like your image, and this is wrong. I use the follow, using your code: plot for [i=1:words(USERS)] for [j=2:4] (i-1)*3+j t sprintf("%s %d", USR(j), i) - ( USR(i)=word(USERS,i) ) - But my 1st question still, is "why my script dont work, in theory is wright yes ?"
@prompt32 That was just example. See edited answer. Not having your data, I can't guarantee that it works.
0

https://stackoverflow.com/users/6401403/michael-o base on Michael O's answer, it works, and this is my whole script.

#!/usr/bin/gnuplot

reset
set term __TERM__ transparent truecolor enhanced font "__PLOTFONT__" size __PLOTGEOMETRY__
set key noreverse outside top right Right tc rgb"#ffffff"
set grid ytics xtics back lw __PLOTGRID__ lc rgb"#ffffff"
set autoscale

set title "Users %" tc rgb"#ffffff"
set xtics ("0" 0,"." 60,"." 120,"3" 180,"." 240,"." 300,"6" 360,"." 420,"." 480,"9" 540,"." 600,"." 660,"0" 720,"." 780,"." 840,"3" 900,"." 960,"." 1020,"6" 1080,"." 1140,"." 1200,"9" 1260,"." 1320,"." 1380,"0" 1440,) tc rgb"#ffffff"
set ylabel "%" tc rgb"#ffffff"
set ytics  tc rgb"#ffffff"

DATA="__GCRONDIR__/.data/usrstat.log"
USERS=system("__GCRONDIR__/bin/getEnv 'USERS'")

VAL(g,c)=(3*(g-1)) + c  
USR(i)=word(USERS,i)

STATLABELS="pad1 procs cpu mem"

kind(k)=word(STATLABELS,k)


plot for [i=1:words(USERS)] for [j=3:4] \
"__GCRONDIR__/.data/usrstat.log" u 1:VAL(i,j) t USR(i)." ".kind(j).i  __STYLE0__

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.