source: palm/trunk/SCRIPTS/hlrn_watchdog @ 1029

Last change on this file since 1029 was 1029, checked in by maronga, 12 years ago

HLRN watchdog added

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 5.4 KB
Line 
1#!/bin/ksh
2#------------------------------------------------------------------------------!
3# Current revisions:
4# -----------------
5# Initial revision
6#
7# Former revisions:
8# -----------------
9# $Id: hlrn_watchdog 1029 2012-10-17 15:33:56Z maronga $
10#
11#
12# Description:
13# ------------
14# The hlrn_watchdog works for jobs on HLRN in Hannover/Berlin and with KDE.
15# It can be used for monitoring currently submitted jobs and will display
16# Running, Idle and Blocked jobs in a separate window, which is updated every
17# 10 minutes.
18# Starting: "hlrn_watchdog start <your hlrn username>"
19# Stopping: "hlrn_watchdog stop"
20#------------------------------------------------------------------------------!
21
22    cd $PALM_BIN
23
24    gate_h="hicegate.hlrn.de"
25    gate_b="bicegate.hlrn.de"
26    update_frequency=600
27
28#   trap strg+c
29    trap 'killall kdialog; exit' 2
30
31
32#   start/stop routine
33    if [[ $1 == "stop" ]]
34    then
35       result=`ps aux|grep -c "./hlrn_watchdog"`
36       if (( $result > 2 ))
37       then
38          result=`ps aux|grep -m1 "./hlrn_watchdog"`
39          killid=`echo $result | tr -s " " | cut -d" " -s -f2`
40          kill -9 $killid > /dev/null
41          killall kdialog
42          echo "*** hlrn_watchdog stopped."
43       else
44          echo "+++ hlrn_watchdog is not running."
45       fi
46       exit
47    elif [[ $1 == "start" ]]
48    then
49        result=`ps aux|grep -c "hlrn_watchdog"`
50        if (( $result > 2 ))
51        then
52           echo "+++ hlrn_watchdog is already running."
53        else
54           nohup ./hlrn_watchdog $2 1> /dev/null 2> /dev/null &
55           echo "\n*** hlrn_watchdog starting..."
56        fi
57        exit
58    else
59
60#      login via ssh and collect information in .watchdog_report.x
61       while true
62       do
63          ssh  $gate_h -l $1 "showq | egrep \"($1)\"" > .watchdog_report.x
64          ssh  $gate_b -l $1 "showq | egrep \"($1)\"" >> .watchdog_report.x
65
66          i=0
67          j=0
68          cat .watchdog_report.x|while read variable
69          do
70#            analyze output
71             comid[$i]=`echo $variable | tr -s " " | cut -d" " -s -f1`
72             jobid[$i]=`echo ${comid[$i]} | tr -s " " | cut -d"." -s -f2`
73             complex[$i]=`echo ${comid[$i]} | tr -s " " | cut -d"." -s -f1`
74             username[$i]=`echo $variable | tr -s " " | cut -d" " -s -f2`
75             status[$i]=`echo $variable | tr -s " " | cut -d" " -s -f3`
76             nodes[$i]=`echo $variable | tr -s " " | cut -d" " -s -f4`
77             walltime[$i]=`echo $variable | tr -s " " | cut -d" " -s -f5` 
78             day[$i]=`echo $variable | tr -s " " | cut -d" " -s -f6`   
79             month[$i]=`echo $variable | tr -s " " | cut -d" " -s -f7`   
80             date[$i]=`echo $variable | tr -s " " | cut -d" " -s -f8`
81             subtime[$i]=`echo $variable | tr -s " " | cut -d" " -s -f9`   
82             ((i = i + 1))
83          done
84          rm .watchdog_report.x
85
86#         check for terminated jobs and status changes
87          k=0
88          cat .watchdog_status.x|while read variable
89          do
90#            analyze output
91             old_comid[$k]=`echo $variable | tr -s " " | cut -d" " -s -f1`
92             old_status[$k]=`echo $variable | tr -s " " | cut -d" " -s -f2` 
93             ((k = k + 1))
94          done
95          rm .watchdog_status.x
96
97          info=""
98          for ((m=0;m<$k;m++))
99          do
100             found=0
101             for ((n=0;n<$i;n++))
102             do       
103                if [[ ${old_comid[$m]} == ${comid[$n]} ]]
104                then
105                   if [[ ${old_status[$m]} != ${status[$n]} ]]
106                   then
107                       info="$info ${old_comid[$m]} has changed status from ${old_status[$m]} to ${status[$n]}.\n"
108                   fi
109                   found=1
110                   break
111                fi
112             done
113             if (( $found == 0 ))
114             then
115                info="$info ${old_comid[$m]} has been terminated (Status was ${old_status[$m]}).\n"
116             fi
117          done
118
119#         get estimated starting time for all idle jobs and write watchdog output in .watchdog_report.x
120          while (( $j < $i ))
121          do
122             if [[ ${status[$j]} == "Idle" ]]
123             then
124                if [[ ${complex[$j]} == "hannover" ]]
125                then
126                   eststart[$j]=`ssh $gate_h -l $1 "showstart ${comid[$j]}|grep \"based start in\""`
127                else
128                   eststart[$j]=`ssh $gate_b -l $1 "showstart ${comid[$j]}|grep \"based start in\""`
129                fi
130                eststart[$j]="Start in: "`echo ${eststart[$j]} | tr -s " " | cut -d" " -s -f6`   
131             else
132                eststart[$j]=""
133             fi
134
135#            write final output line
136             ((k = j + 1))
137             printf "%-9s%8s%3s%04i%13s%11s%2s%-s%3s%-20s\n" "Job: $k:" "${status[$j]}" " @ " "${nodes[$j]}" " nodes, time:" "${walltime[$j]}" " (" "${comid[$j]}" "). " "${eststart[$j]}" >> .watchdog_report.x
138             printf "${comid[$j]} ${status[$j]}\n" >> .watchdog_status.x
139             ((j = j + 1))
140          done
141
142#         kill all windows
143          killall kdialog
144
145          timestamp=`date`
146
147#         create window and show information
148          kdialog --textbox .watchdog_report.x 550 150 --title "HLRN watchdog  (last update: $timestamp)" &
149
150#         in case of status changes and terminated jobs, inform the user
151          if [[ $info != "" ]]
152          then
153             kdialog --msgbox "$info" --title "HLRN Job Information" &
154          fi
155
156          sleep $update_frequency
157       done
158
159    fi
Note: See TracBrowser for help on using the repository browser.