Roy Ashbrook

let go or be dragged
posts - 198, comments - 29, trackbacks - 8

how to graph / chart multiple ping results using shell scripting and logparser

i probably should have called this post 'stupid batch file tricks' or 'how much time do you want to waste on batch files' as well. =P anyway, i needed to graph something else, and i was fiddling around with logparser. if you have ever fiddled, you have probably googled, and if you have ever googled for logparser, you probably have come across Ken Schaefer's blog post about graphing ping results. it's at http://www.adopenstatic.com/cs/blogs/ken/archive/2005/05/30/22.aspx if you haven't. go check it out. i will wait. it's quite short. wayyyy shorter than this. =P

anyway, i wanted to represent several test result series from servers, but i wanted to be able to basically just write whatever tests i wanted to do whatever and just use shell script so i could do whatever pretty easily. to do this i needed a simple execution harness and a way to output the data as a table with multiple series. you can get this data in one big table and then pivot it, but i wanted to just grab the data once and not massage it and this was pretty simple to do just using some cheating at the command line. the easiest test to do was a ping test so i just wrote a little poc script to do ping tests and dump the data to a tsv. then it outputs a logparser command that will show the chart. obviously, tweak everything to 'taste' lol

:setup
@echo off
set serverlistfile=serverlist
set outputtsvfile=output.tsv
set iteration=5
goto :main

:main
call :build_header
call :doteststimes %iteration%
call :echo_logparser_command
goto :end

:echo_logparser_command
call :startrow test#
for /f %%i in (%serverlistfile%) do call :appendcommarow %%i
@echo logparser "select %row% into output.gif from %outputtsvfile%" -i:TSV -charttype smoothline -view
goto :end

:build_header
call :startrow test#
for /f %%i in (%serverlistfile%) do call :appendrow %%i
@echo %row% > %outputtsvfile%
goto :end

:doteststimes
for /l %%i in (1,1,%1) do call :dotests %%i
goto :end

:dotests
call :startrow %1
for /f %%i in (%serverlistfile%) do call :dotest %%i
@echo %row% >> %outputtsvfile%
goto :end

:dotest
for /f "skip=2 tokens=1,8 delims=ms=, " %%i in ('ping -n 1 %1') do IF %%i==Reply call :appendrow %%j
goto :end

:startrow
set row=%1
goto :end

:appendrow
set row=%row% %1
goto :end

:appendcommarow
set row=%row%,%1
goto :end

:clearrow
set row=
goto :end

:end

before you ask:
  1. yes you can just dump this to a series in anything that can do pivots, and then just pivot it
  2. yes you can do this with excel by just copying and pasting
  3. yes.... you can automate excel and do it that way =P
  4. yes.... you could use xml or any of a million other ways to do it
  5. yes, you should be able to nest the commands using parens instead of calls/gotos, i just did that while i was troubleshooting and since it worked, i didn't see any great reason to undo it
  6. yes you can use goto :EOF, see #5 on why this isn't
  7. and finally... yes there are a million other ways. but this was pretty simple and it was more of a thought exercise and seemed worthy of a blog post due to the .... probably less than normal solution lol
the logparser command looks something like:

logparser "select test#,s1,s2,s3,s4 into output.gif from output.tsv" -i:TSV -charttype smoothline -view

and output.gif from that command looks something like:

sample ping results

anyway, next i will post a list of my fav logparser links. =) there's a ton to be said about logparser, but most of it is already in the links i will post next time.

Print | posted on Wednesday, May 26, 2010 1:00 AM | Filed Under [ SA ]

Comments have been closed on this topic.

Powered by: