Add scripts to create myops-getqueryview:
[myops.git] / web / collect / server / summarize_logs.sh
1 #!/bin/bash
2
3 PREFIX=/var/www/html/uploadlogs/raw/old
4
5 # get keys
6 key_list="bootcd_version
7 fs_status
8 iptables_status
9 kernel_version
10 netflow
11 netflow_live
12 nm_running
13 nodemanager_running
14 plc_config
15 real_bootcd_kernel_version
16 real_bootcd_version
17 "
18
19 DATE=$( date --date "1 hour ago" +%Y-%m-%dT%H )
20 #DATE=$1
21
22 # get count of unique values from keys
23 echo $START Hours ago == $DATE
24 c=`ls $PREFIX/$DATE/*--upload | wc -l`
25 if [[ $c -gt 2 ]] ; then
26     for key in $key_list ; do 
27         echo $key
28         c=`grep -E -h "^$key " $PREFIX/$DATE/*--upload | wc -l`
29                 if [[ $c -gt 2 ]] ; then
30                         grep -E -h "^$key " $PREFIX/$DATE/*--upload | \
31                                 awk '{if ( NF == 2 ) { print $0, "unknown" } else { print $0 } }' | \
32                                 awk '{if ( $3 == "Linux" ) { print $1, $2, $5 } else { print $0 } }'  | \
33                                 sed -e 's/^.* : //g' -e 's/ /_/g' -e 's/.*running_:/no/' -e 's/.*status_:/none/g' | \
34                                 awk -F. '{ if ( $2 == "" ) { print $1 } else if ( $3 == "" ) { printf("%s.%s\n", $1, $2) } else { printf("%s.%s.%s\n", $1, $2, $3)} }' | \
35                                 sed -e 's/Multiple_IO_errors.*/error/' \
36                                         -e 's/\/home\/pl_monitor.*/error/' \
37                                         -e 's/Unable_to_find.*/error/'  \
38                                         -e 's/.*cannot_touch.*/error/'  \
39                                         -e 's/No_kernel_at_.*/error/' | \
40                                 sort | uniq -c | \
41                                 sed -e 's/\./_/g' -e 's/\//_/g' | awk 'BEGIN{total=0} { total += $1 ; print $0 } END { print total, "total"}' | \
42                                 while read value value_name ; do 
43                                         #echo -e "\tmyops.$key.$value_name $value $DATE" 
44                                         #echo -e "\t"/root/load-graphite.py --target "myops.$key.$value_name" --date $DATE  --value $value
45                                         /usr/share/myops/web/collect/server/load-graphite.py --target "myops.$key.$value_name" --date $DATE  --value $value
46                                         sleep .2
47                                 done
48                 fi
49     done
50 fi
51