1 | <?php
|
---|
2 |
|
---|
3 | $us3bin = exec( "ls -d ~us3/lims/bin" );
|
---|
4 | include "$us3bin/listen-config.php";
|
---|
5 |
|
---|
6 | $xml = get_data();
|
---|
7 |
|
---|
8 | if ( $xml != "" )
|
---|
9 | parse( $xml );
|
---|
10 |
|
---|
11 | $data = array();
|
---|
12 |
|
---|
13 | local_status();
|
---|
14 |
|
---|
15 | foreach ( $data as $item )
|
---|
16 | {
|
---|
17 | update( $item[ 'cluster' ], $item[ 'queued' ], $item[ 'status' ], $item[ 'running' ] );
|
---|
18 | }
|
---|
19 |
|
---|
20 | exit();
|
---|
21 |
|
---|
22 | // Get the cluster status
|
---|
23 |
|
---|
24 | function get_data()
|
---|
25 | {
|
---|
26 | global $self;
|
---|
27 | $url = "http://community.ucs.indiana.edu:19444/orps-service/XML/gateway/ultrascan";
|
---|
28 |
|
---|
29 | try
|
---|
30 | {
|
---|
31 | $post = new HttpRequest( $url, HttpRequest::METH_GET );
|
---|
32 | $http = $post->send();
|
---|
33 | $xml = $post->getResponseBody();
|
---|
34 | }
|
---|
35 | catch ( HttpException $e )
|
---|
36 | {
|
---|
37 | // write_log( "$self: Cluster Status not available" );
|
---|
38 | return "";
|
---|
39 | }
|
---|
40 |
|
---|
41 | return $xml;
|
---|
42 | }
|
---|
43 |
|
---|
44 | // Parse the xml
|
---|
45 |
|
---|
46 | function parse( $xml )
|
---|
47 | {
|
---|
48 | global $data;
|
---|
49 |
|
---|
50 | $data = array();
|
---|
51 |
|
---|
52 | $x = new XML_Array( $xml );
|
---|
53 | $d = $x->ReturnArray();
|
---|
54 |
|
---|
55 | if ( ! isset( $d[ 'summaries' ] ) ) exit(); // Bad input
|
---|
56 |
|
---|
57 | foreach ( $d[ 'summaries' ] as $item )
|
---|
58 | {
|
---|
59 | $a = Array();
|
---|
60 |
|
---|
61 |
|
---|
62 | $a[ 'queued' ] = $item[ 'waitingJobs' ];
|
---|
63 | $a[ 'running' ] = $item[ 'runningJobs' ];
|
---|
64 |
|
---|
65 | if ( $a[ 'queued' ] == "" || $a[ 'queued' ] < 0 ) $a[ 'queued' ] = 0;
|
---|
66 | if ( $a[ 'running' ] == "" || $a[ 'running' ] < 0 ) $a[ 'running' ] = 0;
|
---|
67 |
|
---|
68 | $clusterParts = explode( ".", $item[ 'resourceId' ] );
|
---|
69 | $cluster = preg_replace( '/\d+$/', "", $clusterParts[ 0 ] );
|
---|
70 |
|
---|
71 | if ( $cluster == 'uthscsa-bcf' ) $cluster = 'bcf';
|
---|
72 | if ( $cluster == 'uthscsa-alamo' ) $cluster = 'alamo';
|
---|
73 |
|
---|
74 | $a[ 'cluster' ] = $cluster;
|
---|
75 |
|
---|
76 | switch ( $item[ 'resourceStatus' ] )
|
---|
77 | {
|
---|
78 | case 'UP' :
|
---|
79 | $status = "up";
|
---|
80 | break;
|
---|
81 |
|
---|
82 | case 'DOWN' :
|
---|
83 | $status = "down";
|
---|
84 | break;
|
---|
85 |
|
---|
86 | case 'WARN' :
|
---|
87 | $status = "warn";
|
---|
88 | break;
|
---|
89 |
|
---|
90 | case 'FAILED' :
|
---|
91 | default :
|
---|
92 | $status = "unknown";
|
---|
93 | break;
|
---|
94 | }
|
---|
95 |
|
---|
96 | $a[ 'status' ] = $status;
|
---|
97 |
|
---|
98 | $data[] = $a;
|
---|
99 | }
|
---|
100 | }
|
---|
101 |
|
---|
102 | // Put it in the DB
|
---|
103 |
|
---|
104 | function update( $cluster, $queued, $status, $running )
|
---|
105 | {
|
---|
106 | global $dbhost;
|
---|
107 | global $guser;
|
---|
108 | global $gpasswd;
|
---|
109 | global $gDB;
|
---|
110 | global $self;
|
---|
111 | //echo " $cluster $queued, $status, $running\n";
|
---|
112 |
|
---|
113 | $gfac_link = mysql_connect( $dbhost, $guser, $gpasswd );
|
---|
114 | $result = mysql_select_db( $gDB, $gfac_link );
|
---|
115 |
|
---|
116 | if ( ! $result )
|
---|
117 | {
|
---|
118 | write_log( "$self: Could not connect to DB $gDB" );
|
---|
119 | echo "Could not connect to DB $gDB.\n";
|
---|
120 | exit();
|
---|
121 | }
|
---|
122 |
|
---|
123 | $query = "SELECT * FROM cluster_status WHERE cluster='$cluster'";
|
---|
124 | $result = mysql_query( $query, $gfac_link );
|
---|
125 |
|
---|
126 | if ( ! $result )
|
---|
127 | {
|
---|
128 | write_log( "$self: Query failed $query - " . mysql_error( $gfac_link ) );
|
---|
129 | echo "$self: Query failed $query - " . mysql_error( $gfac_link ) . "\n";
|
---|
130 | exit();
|
---|
131 | }
|
---|
132 |
|
---|
133 | $rows = mysql_num_rows( $result );
|
---|
134 |
|
---|
135 | if ( $rows == 0 ) // INSERT
|
---|
136 | {
|
---|
137 | $query = "INSERT INTO cluster_status SET " .
|
---|
138 | "cluster='$cluster', " .
|
---|
139 | "queued=$queued, " .
|
---|
140 | "running=$running, " .
|
---|
141 | "status='$status'";
|
---|
142 | }
|
---|
143 | else // UPDATE
|
---|
144 | {
|
---|
145 | $query = "UPDATE cluster_status SET " .
|
---|
146 | "queued=$queued, " .
|
---|
147 | "running=$running, " .
|
---|
148 | "status='$status' " .
|
---|
149 | "WHERE cluster='$cluster'";
|
---|
150 | }
|
---|
151 |
|
---|
152 | $result = mysql_query( $query, $gfac_link );
|
---|
153 |
|
---|
154 | if ( ! $result )
|
---|
155 | {
|
---|
156 | write_log( "$self: Query failed $query - " . mysql_error( $gfac_link ) );
|
---|
157 | echo "$self: Query failed $query - " . mysql_error( $gfac_link ) . "\n";
|
---|
158 | }
|
---|
159 | }
|
---|
160 |
|
---|
161 | // Get local cluster status
|
---|
162 |
|
---|
163 | function local_status()
|
---|
164 | {
|
---|
165 | global $self;
|
---|
166 | global $data;
|
---|
167 |
|
---|
168 | $clusters = array( "alamo", "lonestar5", "stampede",
|
---|
169 | "comet", "gordon", "jureca", "jacinto" );
|
---|
170 | // $clusters = array( "alamo", "lonestar5", "stampede",
|
---|
171 | // "comet", "gordon", "jureca" );
|
---|
172 | foreach ( $clusters as $clname )
|
---|
173 | {
|
---|
174 | $a = Array();
|
---|
175 | switch( $clname )
|
---|
176 | {
|
---|
177 | case 'alamo':
|
---|
178 | {
|
---|
179 | $host = "us3@alamo.uthscsa.edu";
|
---|
180 | $qstat = `ssh $host '/usr/bin/qstat -B 2>&1|tail -1'`;
|
---|
181 | $sparts = preg_split( '/\s+/', $qstat );
|
---|
182 | $que = $sparts[ 3 ];
|
---|
183 | $run = $sparts[ 4 ];
|
---|
184 | $sta = $sparts[ 10 ];
|
---|
185 | if ( $sta == "Active" )
|
---|
186 | $sta = "up";
|
---|
187 | else
|
---|
188 | $sta = "down";
|
---|
189 | break;
|
---|
190 | }
|
---|
191 | case 'jacinto':
|
---|
192 | {
|
---|
193 | $host = "us3@jacinto.uthscsa.edu";
|
---|
194 | $qstat = `ssh $host '/opt/torque/bin/qstat -B 2>&1|tail -1'`;
|
---|
195 | $sparts = preg_split( '/\s+/', $qstat );
|
---|
196 | $que = $sparts[ 3 ];
|
---|
197 | $run = $sparts[ 4 ];
|
---|
198 | $sta = $sparts[ 9 ];
|
---|
199 | if ( $sta == "Active" )
|
---|
200 | $sta = "up";
|
---|
201 | else
|
---|
202 | $sta = "down";
|
---|
203 | break;
|
---|
204 | }
|
---|
205 | case 'stampede':
|
---|
206 | {
|
---|
207 | $host = "us3@stampede.tacc.utexas.edu";
|
---|
208 | $qstat = `ssh $host '/usr/local/bin/showq 2>&1|grep "Total Jobs"'`;
|
---|
209 | $sparts = preg_split( '/\s+/', $qstat );
|
---|
210 | $tot = $sparts[ 2 ];
|
---|
211 | $run = $sparts[ 5 ];
|
---|
212 | $que = $sparts[ 8 ];
|
---|
213 | $sta = "up";
|
---|
214 | if ( $tot == '' || $tot == '0' )
|
---|
215 | $sta = "down";
|
---|
216 | break;
|
---|
217 | }
|
---|
218 | case 'lonestar5':
|
---|
219 | {
|
---|
220 | $host = "us3@ls5.tacc.utexas.edu";
|
---|
221 | $qstat = `ssh $host '/usr/local/bin/showq 2>&1|grep "Total Jobs"'`;
|
---|
222 | $sparts = preg_split( '/\s+/', $qstat );
|
---|
223 | $tot = $sparts[ 2 ];
|
---|
224 | $run = '0';
|
---|
225 | $que = '0';
|
---|
226 | $sta = "up";
|
---|
227 | if ( $tot == '' || $tot == '0' )
|
---|
228 | {
|
---|
229 | $sta = "down";
|
---|
230 | }
|
---|
231 | else
|
---|
232 | {
|
---|
233 | $run = $sparts[ 5 ];
|
---|
234 | $que = $sparts[ 8 ];
|
---|
235 | }
|
---|
236 | break;
|
---|
237 | }
|
---|
238 | case 'comet':
|
---|
239 | {
|
---|
240 | $host = "us3@comet.sdsc.edu";
|
---|
241 | $qstat = `ssh $host '/usr/bin/sinfo -s -p compute -o "%a %F" |tail -1'`;
|
---|
242 | $sparts = preg_split( '/\s+/', $qstat );
|
---|
243 | $sta = $sparts[ 0 ];
|
---|
244 | $knts = $sparts[ 1 ];
|
---|
245 | $sparts = preg_split( '/\//', $knts );
|
---|
246 | $run = $sparts[ 0 ];
|
---|
247 | $que = $sparts[ 1 ];
|
---|
248 | if ( $sta == "" )
|
---|
249 | $sta = "down";
|
---|
250 | break;
|
---|
251 | }
|
---|
252 | case 'gordon':
|
---|
253 | {
|
---|
254 | $host = "us3@gordon.sdsc.edu";
|
---|
255 | $qstat = `ssh $host '/opt/torque/bin/qstat -B 2>&1|tail -1'`;
|
---|
256 | $sparts = preg_split( '/\s+/', $qstat );
|
---|
257 | $que = $sparts[ 3 ];
|
---|
258 | $run = $sparts[ 4 ];
|
---|
259 | $sta = $sparts[ 10 ];
|
---|
260 | if ( $sta == "Active" )
|
---|
261 | $sta = "up";
|
---|
262 | else
|
---|
263 | $sta = "down";
|
---|
264 | break;
|
---|
265 | }
|
---|
266 | case 'jureca':
|
---|
267 | {
|
---|
268 | $host = "swus1@jureca.fz-juelich.de";
|
---|
269 | $qstat = `ssh $host '~swus1/scripts/qstat-jureca 2>&1'`;
|
---|
270 | $sparts = preg_split( '/\s+/', $qstat );
|
---|
271 | $sta = $sparts[ 0 ];
|
---|
272 | $run = $sparts[ 1 ];
|
---|
273 | $que = $sparts[ 2 ];
|
---|
274 | break;
|
---|
275 | }
|
---|
276 | }
|
---|
277 |
|
---|
278 | if ( $sta == "" )
|
---|
279 | $sta = "down";
|
---|
280 |
|
---|
281 | if ( $sta == "down" )
|
---|
282 | {
|
---|
283 | $que = "0";
|
---|
284 | $run = "0";
|
---|
285 | }
|
---|
286 |
|
---|
287 | $a[ 'cluster' ] = $clname;
|
---|
288 | $a[ 'queued' ] = $que;
|
---|
289 | $a[ 'running' ] = $run;
|
---|
290 | $a[ 'status' ] = $sta;
|
---|
291 |
|
---|
292 | $data[] = $a;
|
---|
293 |
|
---|
294 | if ( $clname == 'alamo' || $clname == 'jacinto' )
|
---|
295 | {
|
---|
296 | $a[ 'cluster' ] = $clname . "-local";
|
---|
297 | $data[] = $a;
|
---|
298 | }
|
---|
299 | }
|
---|
300 | }
|
---|
301 |
|
---|
302 | class XML_Array
|
---|
303 | {
|
---|
304 | var $_data = Array();
|
---|
305 | var $_name = Array();
|
---|
306 | var $_rep = Array();
|
---|
307 | var $_parser = 0;
|
---|
308 | var $_level = 0;
|
---|
309 | var $_index = 0;
|
---|
310 |
|
---|
311 | function XML_Array( &$data )
|
---|
312 | {
|
---|
313 | $this->_parser = xml_parser_create();
|
---|
314 |
|
---|
315 | xml_set_object ( $this->_parser, $this );
|
---|
316 | xml_parser_set_option ( $this->_parser, XML_OPTION_CASE_FOLDING, false );
|
---|
317 | xml_set_element_handler ( $this->_parser, "_startElement", "_endElement" );
|
---|
318 | xml_set_character_data_handler( $this->_parser, "_cdata" );
|
---|
319 |
|
---|
320 | $this->_data = array();
|
---|
321 | $this->_level = 0;
|
---|
322 |
|
---|
323 | if ( ! xml_parse( $this->_parser, $data, true ) )
|
---|
324 | return false;
|
---|
325 |
|
---|
326 | xml_parser_free( $this->_parser );
|
---|
327 | }
|
---|
328 |
|
---|
329 | function & ReturnArray()
|
---|
330 | {
|
---|
331 | return $this->_data[ 0 ];
|
---|
332 | }
|
---|
333 |
|
---|
334 | function _startElement( $parser, $name, $attrs )
|
---|
335 | {
|
---|
336 | if ( $name == "resourceHealth" )
|
---|
337 | {
|
---|
338 | ## $name .= $this->_index;
|
---|
339 | $this->_index++;
|
---|
340 | }
|
---|
341 |
|
---|
342 | if ( ! isset( $this->_rep[ $name ] ) ) $this->_rep[ $name ] = 0;
|
---|
343 |
|
---|
344 | $this->_addElement( $name, $this->_data[ $this->_level ], $attrs );
|
---|
345 | $this->_name[ $this->_level ] = $name;
|
---|
346 | $this->_level++;
|
---|
347 | }
|
---|
348 |
|
---|
349 | function _endElement( $parser, $name )
|
---|
350 | {
|
---|
351 | if ( isset( $this->_data[ $this->_level ] ) )
|
---|
352 | {
|
---|
353 | $this->_addElement( $this->_name[ $this->_level - 1 ],
|
---|
354 | $this->_data[ $this->_level - 1 ],
|
---|
355 | $this->_data[ $this->_level ]
|
---|
356 | );
|
---|
357 | }
|
---|
358 |
|
---|
359 | unset( $this->_data[ $this->_level ] );
|
---|
360 | $this->_level--;
|
---|
361 | $this->_rep[ $name ]++;
|
---|
362 | }
|
---|
363 |
|
---|
364 | function _cdata( $parser, $data )
|
---|
365 | {
|
---|
366 | if ( $this->_name[ $this->_level - 1 ] )
|
---|
367 | {
|
---|
368 | $this->_addElement( $this->_name[ $this->_level - 1 ],
|
---|
369 | $this->_data[ $this->_level - 1 ],
|
---|
370 | str_replace( array( ">", "<",""", "&" ),
|
---|
371 | array( ">" , "<" , '"' , "&" ),
|
---|
372 | $data
|
---|
373 | )
|
---|
374 | );
|
---|
375 | }
|
---|
376 | }
|
---|
377 |
|
---|
378 | function _addElement( &$name, &$start, $add = array() )
|
---|
379 | {
|
---|
380 | if ( ( sizeof( $add ) == 0 && is_array( $add ) ) || ! $add )
|
---|
381 | {
|
---|
382 | if ( ! isset( $start[ $name ] ) ) $start[ $name ] = '';
|
---|
383 | $add = '';
|
---|
384 | }
|
---|
385 |
|
---|
386 | $update = &$start[ $name ];
|
---|
387 |
|
---|
388 | if ( is_array( $add) &&
|
---|
389 | is_array( $update ) ) $update += $add;
|
---|
390 | elseif ( is_array( $update ) ) return;
|
---|
391 | elseif ( is_array( $add ) ) $update = $add;
|
---|
392 | elseif ( $add ) $update .= $add;
|
---|
393 | }
|
---|
394 | }
|
---|
395 | ?>
|
---|