terça-feira, 26 de julho de 2011

Monitorando Squid em Real-time

Crie um arquivo com o código abaixo e execute, ele mostrará o conteúdo do access.log de modo organizado e colorido, semelhante ao tail -f.

############################
# Inicio do Script
#!/bin/sh
tail -f $1 | awk '{
if (length($7)>76) {
   if ($4=="TCP_DENIED/403") {
      printf "\033[40;31;1m%15s %-27s %-7s %s/.../%s\033[mn\n\r", $3, $4, $6,substr($7,1,56),substr($7,length($7)-14,15)
      } else {
             printf "\033[40;36;1m%15s\033[m \033[40;36m%-27s\033[m\033[40;30;1m%-7s\033[m \033[40;37m%s/.../%s\033[mn\n\r", $3, $4, $6, substr($7,1,56),substr($7,length($7)-14,15)
      }
   } else {
          if ($4=="TCP_DENIED/403") {
             printf "\033[40;31;1m%15s %-27s %-7s %s\033[mn\n\r", $3, $4, $6, substr($7,1,76)
    } else {
           printf "\033[40;36;1m%15s\033[m \033[40;36m%-27s\033[m\033[40;30;1m%-7s\033[m \033[40;37m%s\033[mn\n\r", $3, $4, $6, substr($7,1,76)}}
}'
# Fim do Script
############################