Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm logging some data relative to clients NFS usage over a network. Now I want to plot it on a lines diagram, and I'm overwhelmed by the possibilities I'm finding out there. No one seems to be easy to understand for me.

Here's a simplified log:

1356112995  192.168.1.46    766
1356112995  192.168.1.12    14
1356112995  192.168.1.141   5
1356112995  192.168.1.11    38
1356114790  192.168.1.46    760
1356114790  192.168.1.12    10
1356114790  192.168.1.11    18
1356116586  192.168.1.46    758
1356116586  192.168.1.12    9
1356118387  192.168.1.46    783
1356120187  192.168.1.46    687
1356121987  192.168.1.46    699
1356123787  192.168.1.46    371
1356125587  192.168.1.46    717
1356127386  192.168.1.46    0

First column is a timestamp, it should be on the X axis. Second column is the client IP. Third column is the number of operations, it should be on the Y axis. The graph should be a line graph.

I want this to be automatic, so plotting from the command line is the way to go. No idea on how to do that, though.

It should generate a png file that will be subsequently uploaded to some webserver for visualization.

share|improve this question
    
do you want to see the plot in the command line or do you want to create an image and post in on the website or something? –  mnmnc Dec 23 '12 at 1:09
    
Create an image and upload it to a webserver. I'm going to clarify this on the original post. Thanks. –  Jorge Suárez de Lis Dec 23 '12 at 1:11
    
I like pCharts -> pchart.sourceforge.net. But this would generate a javascript chart not a picture like jpg or gif. If you want flexibility and nice look i would go with something like that. If you must have a jpg or some bitmap based picture - gnuplot will probably suit you best. –  mnmnc Dec 23 '12 at 1:25
    
Thank you. I've tried to understand gnuplot but it won't make it easy. I'll take a look into pCharts some day, looks interesting. –  Jorge Suárez de Lis Dec 23 '12 at 23:56

2 Answers 2

up vote 0 down vote accepted

There are probably some ways to do this without installing software (With NFS, I assume you're using a Linux box). But, my favorite solution involves R which is free and available for Linux/Windows/Mac, etc. and will present you with myriad opportunities to customize your plot or manipulate your data.

Step 1
Make a script with code that looks something like this:

logfile <- read.table(file="client.log") #Adjust the logfile name as needed.
#This assumes tab separated columns. 
#If needed, column delimiters can be adjusted.
names(logfile) <- c("time.stamp","client","operations") 
#Rename the columns of the input data (if they are named at all)
require(lattice) #This package is needed for the xyplot() function below.  
#The main benefit of this function for your purposes is the ability to color 
#your plot circles by client name.
png(filename="logfile.png") #Designate the plot file type and save location
xyplot(operations~time.stamp,group=client,data=logfile,jitter.x=T,jitter.y=T)
#I've added jitter here which helps prevent plotted points from overlapping.
dev.off() #Close and save the plot

I called my script log.to.png.R

Step 2
From a Unix or Mac command line you can call the script in this manner:
$R CMD BATCH log.to.png.R

share|improve this answer
1  
Thank you very much! I'm now looking into lattice documentation to personalize the plotting. Fortunately, I've used R some years ago, so I remember the basics. –  Jorge Suárez de Lis Dec 23 '12 at 23:30
    
@jorge-suarez-de-lis, great! Glad you found something that meets your needs. Using lattice might have been a bit of overkill here, but it was the quickest way I could think of to plot the entire log with one simple command while at the same time assigning different colors to different "clients." –  D. Woods Dec 24 '12 at 6:22

This is really late, but as I happened across this post, I'll put in my two pennies.

Without installing R, we can use call awk within gnuplot:

plot "<awk '{print $1, $3}' logfile" u 1:2

where the output of the awk command in the double quotes is used by gnuplot to plot your data. The awk command simply prints out the first and third column.

You can place the above command into a gnuplot file, such as plot_log.gp and then call it on the command line like so

gnuplot -e "logfile='your_actual_log_file.log'" plot_log.gp

which is a command that is easily placed into a cron job or some script you have. Note the single quotes around the text.

I just wanted to demonstrate that gnuplot is actually really flexible as it can take command line arguments and assign them as variables within a script. No heavy dependencies (looking at you, R) as awk is pretty pervasive.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.