source: palm/trunk/SCRIPTS/hlrn_watchdog @ 1448

Last change on this file since 1448 was 1448, checked in by maronga, 10 years ago

bugfix in hlrn_watchdog

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 7.5 KB
Line 
1#!/bin/ksh
2#--------------------------------------------------------------------------------#
3# This file is part of PALM.
4#
5# PALM is free software: you can redistribute it and/or modify it under the terms
6# of the GNU General Public License as published by the Free Software Foundation,
7# either version 3 of the License, or (at your option) any later version.
8#
9# PALM is distributed in the hope that it will be useful, but WITHOUT ANY
10# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License along with
14# PALM. If not, see <http://www.gnu.org/licenses/>.
15#
16# Copyright 1997-2014  Leibniz Universitaet Hannover
17#--------------------------------------------------------------------------------#
18#
19# Current revisions:
20# -----------------
21# Bugfix: removed debug mode
22#
23# Former revisions:
24# -----------------
25# $Id: hlrn_watchdog 1448 2014-08-07 10:47:05Z maronga $
26#
27# 1446 2014-08-07 10:08:56Z maronga
28# Adapted for HLRN III. Added windows if no runs are queued.
29#
30# 1046 2012-11-09 14:38:45Z maronga
31# code put under GPL (PALM 3.9)
32#
33# 1029 2012-10-17 15:33:56Z maronga
34# Initial revision
35#
36# Description:
37# ------------
38# The hlrn_watchdog works for jobs on HLRN in Hannover/Berlin and with KDE.
39# It can be used for monitoring currently submitted jobs and will display
40# Running, Idle and Blocked jobs in a separate window, which is updated every
41# 10 minutes.
42# Starting: "hlrn_watchdog start <your hlrn username>"
43# Stopping: "hlrn_watchdog stop"
44#------------------------------------------------------------------------------!
45
46    check_hannover=true
47    check_berlin=true
48    debug=false
49
50    cd $PALM_BIN
51
52    gate_h="hlogin.hlrn.de"
53    gate_b="blogin.hlrn.de"
54    update_frequency=600
55
56#   trap strg+c
57    trap 'kill -9 $infoPID > /dev/null; kill -9 $dialogPID > /dev/null; exit' 2
58
59
60#   start/stop routine
61    if [[ $1 == "stop" ]]
62    then
63       result=`ps aux|grep -c "./hlrn_watchdog"`
64       if (( $result > 2 ))
65       then
66          result=`ps aux|grep -m1 "./hlrn_watchdog"`
67          killid=`echo $result | tr -s " " | cut -d" " -s -f2`
68          kill -9 $killid > /dev/null
69          killall kdialog
70
71          if [[ -f .watchdog_report.x ]] then
72             rm .watchdog_report.x
73          fi
74          if [[ -f .watchdog_status.x ]] then
75             rm .watchdog_status.x
76          fi
77          echo "*** hlrn_watchdog stopped."
78       else
79          echo "+++ hlrn_watchdog is not running."
80       fi
81       exit
82    elif [[ $1 == "start" ]]
83    then
84        result=`ps aux|grep -c "hlrn_watchdog"`
85        if (( $result > 2 ))
86        then
87           echo "+++ hlrn_watchdog is already running."
88        else
89           if [[ $debug = true ]] then
90              ./hlrn_watchdog $2 &
91           else
92              nohup ./hlrn_watchdog $2 1> /dev/null 2> /dev/null &
93           fi
94           echo "\n*** hlrn_watchdog starting..."
95        fi
96        exit
97    else
98#      login via ssh and collect information in .watchdog_report.x
99       while true
100       do
101          touch .watchdog_report.x
102          if [[ $check_hannover == true ]] then
103             ssh  $gate_h -l $1 "showq | egrep \"($1)\"" > .watchdog_report.x
104          fi
105          if [[ $check_berlin == true ]] then
106          ssh  $gate_b -l $1 "showq | egrep \"($1)\"" >> .watchdog_report.x
107          fi
108
109          i=0
110          j=0
111          cat .watchdog_report.x|while read variable
112          do
113#            analyze output
114             comid[$i]=`echo $variable | tr -s " " | cut -d" " -s -f1`
115             jobid[$i]=`echo ${comid[$i]} | tr -s " " | cut -d"." -s -f2`
116             complex[$i]=`echo ${comid[$i]} | tr -s " " | cut -d"." -s -f1`
117             username[$i]=`echo $variable | tr -s " " | cut -d" " -s -f2`
118             status[$i]=`echo $variable | tr -s " " | cut -d" " -s -f3`
119             nodes[$i]=`echo $variable | tr -s " " | cut -d" " -s -f4`
120             walltime[$i]=`echo $variable | tr -s " " | cut -d" " -s -f5` 
121             day[$i]=`echo $variable | tr -s " " | cut -d" " -s -f6`   
122             month[$i]=`echo $variable | tr -s " " | cut -d" " -s -f7`   
123             date[$i]=`echo $variable | tr -s " " | cut -d" " -s -f8`
124             subtime[$i]=`echo $variable | tr -s " " | cut -d" " -s -f9`   
125             ((i = i + 1))
126          done
127          rm .watchdog_report.x
128          touch .watchdog_status.x
129
130#         check for terminated jobs and status changes
131          k=0
132          cat .watchdog_status.x|while read variable
133          do
134#            analyze output
135             old_comid[$k]=`echo $variable | tr -s " " | cut -d" " -s -f1`
136             old_status[$k]=`echo $variable | tr -s " " | cut -d" " -s -f2` 
137             ((k = k + 1))
138          done
139          rm .watchdog_status.x
140
141          info=""
142          for ((m=0;m<$k;m++))
143          do
144             found=0
145             for ((n=0;n<$i;n++))
146             do       
147                if [[ ${old_comid[$m]} == ${comid[$n]} ]]
148                then
149                   if [[ ${old_status[$m]} != ${status[$n]} ]]
150                   then
151                       info="$info ${old_comid[$m]} has changed status from ${old_status[$m]} to ${status[$n]}.\n"
152                   fi
153                   found=1
154                   break
155                fi
156             done
157             if (( $found == 0 ))
158             then
159                info="$info ${old_comid[$m]} has been terminated (Status was ${old_status[$m]}).\n"
160             fi
161          done
162
163#         check whether any jobs are queued
164          touch .watchdog_report.x
165          file_size=`ls -l .watchdog_report.x | tr -s " " | cut -d " " -f 5`
166          if [[ $file_size == 0 ]] then
167            printf "No jobs queued.\n" >> .watchdog_report.x
168          fi
169
170#         get estimated starting time for all idle jobs and write watchdog output in .watchdog_report.x
171          while (( $j < $i ))
172          do
173             if [[ ${status[$j]} == "Idle" ]]
174             then
175                if [[ ${complex[$j]} == "hannover" ]]
176                then
177                   eststart[$j]=`ssh $gate_h -l $1 "showstart ${comid[$j]}|grep \"based start in\""`
178                else
179                   eststart[$j]=`ssh $gate_b -l $1 "showstart ${comid[$j]}|grep \"based start in\""`
180                fi
181                eststart[$j]="Start in: "`echo ${eststart[$j]} | tr -s " " | cut -d" " -s -f6`   
182             else
183                eststart[$j]=""
184             fi
185
186#            write final output line
187             ((k = j + 1))
188             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
189             printf "${comid[$j]} ${status[$j]}\n" >> .watchdog_status.x
190             ((j = j + 1))
191          done
192
193#         kill all windows
194          if  [[ "$infoPID" -ne "" ]] then
195             kill -9 $infoPID > /dev/null
196             unset $infoPID
197          fi
198          if  [[ "$dialogPID" -ne "" ]] then
199             kill -9 $dialogPID > /dev/null
200             unset $dialogPID
201          fi
202
203          timestamp=`date`
204
205#         create window and show information
206          kdialog --textbox .watchdog_report.x 550 150 --title "HLRN watchdog  (last update: $timestamp)" & dialogPID=$!
207
208#         in case of status changes and terminated jobs, inform the user
209          if [[ $info != "" ]]
210          then
211             kdialog --msgbox "$info" --title "HLRN Job Information" & infoPID=$!
212          fi
213
214          sleep $update_frequency
215       done
216
217    fi
Note: See TracBrowser for help on using the repository browser.