Log analysis script in shell -


i'm newbie in scripting , need help. have log file, i'm cleaned out. looks (time, duration(in millisec), action):

2012-04-28 00:00:00;277.406;  2012-04-28 00:00:00;299.680;  2012-04-28 00:00:00;282.338;  2012-02-28 00:00:00;272.241; 

i need make script use duration data , count action.

first - need make easier parse different fields. simple way change semicolon space using

tr ";" " " <logfile|awkscript 

second, need create table of low , high values. i'm using associative array index name of column. in begin section.

you need count when value within low , high values. in middle section.

in end section, print out values. use 2 similar printf format strings make sure headers , values line nicely:

#!/usr/bin/awk -f begin {     low["<1ms"]=0;high["<1ms"]=1     low["1-10ms"]=1;high["1-10ms"]=10     low["10-100ms"]=10;high["10-100ms"]=100     low["100-500ms"]=100;high["100-500ms"]=500     low[">500ms"]=500;high[">500ms"]=1000000000 } { # middle section - each line duration=$3  (i in high) {     if ((duration > low[i]) && (duration <= high[i]) ) { #       printf("duration: %d, low: %s,high: %s\n", duration, low[i], high[i]);         total+=duration # total duration         bin[i]++ # store count different bins         count++ # total number of measurements     } } } end { average=total/count fmt="%-10s %10s %10s %10s %10s %10s\n" nfmt="%-10.3f %10s %10s %10s %10s %10s\n" printf(fmt,"avg", "<1ms", "1-10ms", "10-100ms", "100-500ms", "500+ms") printf(nfmt,average, bin["<1ms"], bin["1-10ms"], bin["10-100ms"], bin["100-500m\ s"], bin["500+ms"])  } 

when run data, get

avg              <1ms     1-10ms   10-100ms  100-500ms     500+ms  282.916                                              4 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -