sexta-feira, 29 de agosto de 2014

Bash Script to parse access log - keywords: parse, awk, bash, statistics, time taken

1. Introduction

Guilherme Junqueira's script to parse access.log

2. Script


#!/bin/bash

#######################################################################################################
# Description: this parse calculates the time taken stats to serve each page                          #
#              It removes the parameters provided after '?' ou ';'                                    #
#              Aggregation options: second, minute, hour, day                                         #
#                                                                                                     #
# Parameters (in order):                                                                              #
#    SEP             - the separator between fields inside each file (usually ' ')                    #
#    DATE_FIELD      - Index of the field that contains the date (usually 5)                          #
#    AGG_OPTION      - Either second, minute, hour, day                                               #
#    TIMETAKEN_FIELD - Index of the field of the time taken                                           #
#    ID              - label to identify the output of the log (usually the server name)              #
#######################################################################################################

DATE_FIELD=$1
AGG_OPTION=$2
TIMETAKEN_FIELD=$3
ID='unspecified'
if [[ ! -z $4 ]];
then
   ID=$4
fi

SEP=' '
if [[ ! -z $5 ]];
then
   SEP=$5
fi

######################################################################################################
############################ Non configurable section below this line ################################

if [[ -z "$DATE_FIELD" || -z "$AGG_OPTION" || -z "$TIMETAKEN_FIELD" ]]
then
  echo
  echo "Not all parameters have been provided or set properly."
  echo "Usage: $(basename $0) DATE_FIELD AGG_OPTION TIMETAKEN_FIELD [ID] [SEP]"
  echo "Alternate usage: $(basename $0) (with parameters set internally)"
  echo
  exit 1
fi

awk -F "$SEP" -v dateField=$DATE_FIELD -v aggOpt=$AGG_OPTION -v ttField=$TIMETAKEN_FIELD -v vID=$ID '
function getDate(df, agg) {
   if( agg == "second" ) {
      split($df, a, ":");
      data=substr(a[1], 2) " " a[2] ":" a[3] ":" a[4];

   } else if ( agg == "minute" ) {
      split($df, a, ":");
      data=substr(a[1], 2) " " a[2] ":" a[3];

   } else if ( agg == "hour" ) {
      split($df, a, ":");
      data=substr(a[1], 2) " " a[2];

   } else {
      split($df, a, ":");
      data=substr(a[1], 2)
   }
   return(data)
}

{
   data=getDate(dateField, aggOpt)
   req[data]++
   time[data]+=$ttField

   if($ttField > max[data]){
      max[data]=$ttField
   }

   if( min[data] == "" ){
      min[data]=$ttField
   } else if ($ttField < min[data]){
      min[data]=$ttField
   }
}

END {
    printf("%15s;%25s;%20s;%15s;%15s;%15s;\n", "ID", "DATA", "SUM TIME TAKEN", "REQS", "MAX", "MIN");

    for(i in req){
       printf("%15s;%25s;%20d;%15d;%15d;%15d;\n", vID, i, time[i], req[i], max[i], min[i]);
    }
}'


3. References


  • Special thanks for Guilherme Junqueira

terça-feira, 19 de agosto de 2014

Installing and Configuring Spring-Tool-Suite-3.5.1 with GRAILS Grails 1.3.7

1. Introduction

This post gathers information about install and configure Spring-Tool-Suite-3.5.1 with Grails 1.3.7.

2. Step-by-Step

Step #1. Install binary

+ spring-tool-suite-3.5.1.RELEASE-e3.8.2-win32-x86_64-installer.exe
- Installation path: C:\springsource
PS: Do not use "C:\Program Files\..."
- Select the JDK path: C:\Program Files\Java\jdk1.7.0_60

Step #2. Configure automatic update

+ Spring Tool Suite :: Help >> Check for update
- [X] Spring Tool Suite
- [X] Spring UAA Integration (optional)

Step #3. Configure automatic update

+ Spring Tool Suite :: Help >> Dashboard
+ Extension
- Find "Groovy"
- [X] Groovy-Eclipse: Groovy-Eclipse plugin
- Find "Grails"
- [X] Grails Support: Support for creating Grails project

Step #4. Install Groovy software version 1.8 compatible

+ Spring Tool Suite :: Help >> Install New Software
+ add: http://dist.springsource.org/release/GRECLIPSE/e4.2
- name: Groovy-Eclipse update site 
+ Extra Groovy Compiler
- [X] Groovy Compiler 1.8 Feature
- [X] Groovy Eclipse (Required)

Step #5. Configure Grails for Spring Tool Suite

+ Spring Tool Suite :: Windows >> Preference
- Groovy >> Grails
- [Add...] [Browse] Enter Grails 1.3.7 Installation Path 
                      Name="Grails 1.3.7" 
                      Location="C:\Program Files(x86)\grails-1.3.7"

Step #6. Configure SVN Plugin Extension

+ Spring Tool Suite :: Help >> Dashboard
+ Extension
 - Find "SVN"
   - [X] Subversive: Subversive plugin

Step #7. Configure SVN Repository and Checking out In-Manager project

+ Spring Tool Suite :: Help >> Dashboard
+ Perspective: Others >> SVN Repository Exploring
- New Repository Location: http://aplic.inmetrics.com.br/com.inmetrics.manager
- Select: trunc >> com.inmetrics.inm-manager
- Checkout

Step #8. Switch Groovy Compiler

+ Spring Tool Suite :: Windows >> Preference
- Groovy >> Compiler
- [Switch to 1.8.6] 

Step #9. Install Grails Plugin

+ Spring Tool Suite :: ^ ALT G
grails> install-plugin plugins/grails-acegi-0.5.3.2.zip 

Step #10. Remove conflict JasperReports

+ Windows Command Prompt


C:\> 
  C:\> rm %HOMEPATH%\.grails\1.3.7\projects\com.inmetrics.inm-manager\plugins\jasper-0.9.7\lib\jasperreports-2.0.5.jar

Step #11. Configure Spring-Tool-Suite to avoid war generation conflict

+ Spring Tool Suite :: Windows >> Preference
- Groovy >> Grails >> Grails Launch
- [New...]
     variable=stringchararrayaccessor.disabled
     value=true


3. References


  • n/a