source: trunk/cluster_status.php@ 15

Last change on this file since 15 was 15, checked in by gegorbet, 9 years ago

fixes, mainly for Jureca

File size: 9.8 KB
Line 
1<?php
2
3$us3bin = exec( "ls -d ~us3/bin" );
4include "$us3bin/listen-config.php";
5
6$xml = get_data();
7
8if ( $xml != "" )
9 parse( $xml );
10
11$data = array();
12
13local_status();
14
15foreach ( $data as $item )
16{
17 update( $item[ 'cluster' ], $item[ 'queued' ], $item[ 'status' ], $item[ 'running' ] );
18}
19
20exit();
21
22// Get the cluster status
23
24function 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
46function 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
104function update( $cluster, $queued, $status, $running )
105{
106 global $dbhost;
107 global $guser;
108 global $gpasswd;
109 global $gDB;
110 global $self;
111
112 $gfac_link = mysql_connect( $dbhost, $guser, $gpasswd );
113 $result = mysql_select_db( $gDB, $gfac_link );
114
115 if ( ! $result )
116 {
117 write_log( "$self: Could not connect to DB $gDB" );
118 echo "Could not connect to DB $gDB.\n";
119 exit();
120 }
121
122 $query = "SELECT * FROM cluster_status WHERE cluster='$cluster'";
123 $result = mysql_query( $query, $gfac_link );
124
125 if ( ! $result )
126 {
127 write_log( "$self: Query failed $query - " . mysql_error( $gfac_link ) );
128 echo "$self: Query failed $query - " . mysql_error( $gfac_link ) . "\n";
129 exit();
130 }
131
132 $rows = mysql_num_rows( $result );
133
134 if ( $rows == 0 ) // INSERT
135 {
136 $query = "INSERT INTO cluster_status SET " .
137 "cluster='$cluster', " .
138 "queued=$queued, " .
139 "running=$running, " .
140 "status='$status'";
141 }
142 else // UPDATE
143 {
144 $query = "UPDATE cluster_status SET " .
145 "queued=$queued, " .
146 "running=$running, " .
147 "status='$status' " .
148 "WHERE cluster='$cluster'";
149 }
150
151 $result = mysql_query( $query, $gfac_link );
152
153 if ( ! $result )
154 {
155 write_log( "$self: Query failed $query - " . mysql_error( $gfac_link ) );
156 echo "$self: Query failed $query - " . mysql_error( $gfac_link ) . "\n";
157 }
158}
159
160// Get local cluster status
161
162function local_status()
163{
164 global $self;
165 global $data;
166
167 //$clusters = array( "alamo", "lonestar", "stampede", "comet", "gordon" );
168 $clusters = array( "alamo", "lonestar", "stampede", "comet", "gordon", "jureca" );
169 foreach ( $clusters as $clname )
170 {
171 $a = Array();
172 switch( $clname )
173 {
174 case 'alamo':
175 {
176 $host = "us3@alamo.uthscsa.edu";
177 $qstat = `ssh $host '/usr/bin/qstat -B 2>&1|tail -1'`;
178 $sparts = preg_split( '/\s+/', $qstat );
179 $que = $sparts[ 3 ];
180 $run = $sparts[ 4 ];
181 $sta = $sparts[ 10 ];
182 if ( $sta == "Active" )
183 $sta = "up";
184 else
185 $sta = "down";
186 break;
187 }
188 case 'stampede':
189 {
190 $host = "us3@stampede.tacc.utexas.edu";
191 $qstat = `ssh $host '/usr/local/bin/showq 2>&1|tail -1'`;
192 $sparts = preg_split( '/\s+/', $qstat );
193 $tot = $sparts[ 2 ];
194 $run = $sparts[ 5 ];
195 $que = $sparts[ 8 ];
196 $sta = "up";
197 if ( $tot == '' || $tot == '0' )
198 $sta = "down";
199 break;
200 }
201 case 'lonestar':
202 {
203 $host = "us3@lonestar.tacc.utexas.edu";
204 $qstat = `ssh $host 'showq 2>&1|tail -1'`;
205 $sparts = preg_split( '/\s+/', $qstat );
206 $tot = $sparts[ 2 ];
207 $run = '0';
208 $que = '0';
209 $sta = "up";
210 if ( $tot == '' || $tot == '0' )
211 {
212 $sta = "down";
213 }
214 else
215 {
216 $run = $sparts[ 5 ];
217 $que = $sparts[ 8 ];
218 }
219 break;
220 }
221 case 'comet':
222 {
223 $host = "us3@comet.sdsc.edu";
224 $qstat = `ssh $host '/usr/bin/sinfo -s -p compute -o "%a %F" |tail -1'`;
225 $sparts = preg_split( '/\s+/', $qstat );
226 $sta = $sparts[ 0 ];
227 $knts = $sparts[ 1 ];
228 $sparts = preg_split( '/\//', $knts );
229 $run = $sparts[ 0 ];
230 $que = $sparts[ 1 ];
231 if ( $sta == "" )
232 $sta = "down";
233 break;
234 }
235 case 'gordon':
236 {
237 $host = "us3@gordon.sdsc.edu";
238 $qstat = `ssh $host '/opt/torque/bin/qstat -B 2>&1|tail -1'`;
239 $sparts = preg_split( '/\s+/', $qstat );
240 $que = $sparts[ 3 ];
241 $run = $sparts[ 4 ];
242 $sta = $sparts[ 10 ];
243 if ( $sta == "Active" )
244 $sta = "up";
245 else
246 $sta = "down";
247 break;
248 }
249 case 'jureca':
250 {
251 $host = "swus1@jureca.fz-juelich.de";
252 $qstat = `ssh $host '/usr/bin/sinfo -s -p batch -o "%a %F" 2>&1|tail -1'`;
253 $sparts = preg_split( '/\s+/', $qstat );
254 $sta = $sparts[ 0 ];
255 $knts = $sparts[ 1 ];
256 $sparts = preg_split( '/\//', $knts );
257 $run = $sparts[ 0 ];
258 $que = $sparts[ 1 ];
259 break;
260 }
261 }
262
263 if ( $sta == "down" )
264 {
265 $que = "0";
266 $run = "0";
267 }
268
269 $a[ 'cluster' ] = $clname;
270 $a[ 'queued' ] = $que;
271 $a[ 'running' ] = $run;
272 $a[ 'status' ] = $sta;
273
274 $data[] = $a;
275
276 if ( $clname == 'alamo' )
277 {
278 $a[ 'cluster' ] = $clname . "-local";
279 $data[] = $a;
280 }
281 }
282}
283
284class XML_Array
285{
286 var $_data = Array();
287 var $_name = Array();
288 var $_rep = Array();
289 var $_parser = 0;
290 var $_level = 0;
291 var $_index = 0;
292
293 function XML_Array( &$data )
294 {
295 $this->_parser = xml_parser_create();
296
297 xml_set_object ( $this->_parser, $this );
298 xml_parser_set_option ( $this->_parser, XML_OPTION_CASE_FOLDING, false );
299 xml_set_element_handler ( $this->_parser, "_startElement", "_endElement" );
300 xml_set_character_data_handler( $this->_parser, "_cdata" );
301
302 $this->_data = array();
303 $this->_level = 0;
304
305 if ( ! xml_parse( $this->_parser, $data, true ) )
306 return false;
307
308 xml_parser_free( $this->_parser );
309 }
310
311 function & ReturnArray()
312 {
313 return $this->_data[ 0 ];
314 }
315
316 function _startElement( $parser, $name, $attrs )
317 {
318 if ( $name == "resourceHealth" )
319 {
320## $name .= $this->_index;
321 $this->_index++;
322 }
323
324 if ( ! isset( $this->_rep[ $name ] ) ) $this->_rep[ $name ] = 0;
325
326 $this->_addElement( $name, $this->_data[ $this->_level ], $attrs );
327 $this->_name[ $this->_level ] = $name;
328 $this->_level++;
329 }
330
331 function _endElement( $parser, $name )
332 {
333 if ( isset( $this->_data[ $this->_level ] ) )
334 {
335 $this->_addElement( $this->_name[ $this->_level - 1 ],
336 $this->_data[ $this->_level - 1 ],
337 $this->_data[ $this->_level ]
338 );
339 }
340
341 unset( $this->_data[ $this->_level ] );
342 $this->_level--;
343 $this->_rep[ $name ]++;
344 }
345
346 function _cdata( $parser, $data )
347 {
348 if ( $this->_name[ $this->_level - 1 ] )
349 {
350 $this->_addElement( $this->_name[ $this->_level - 1 ],
351 $this->_data[ $this->_level - 1 ],
352 str_replace( array( "&gt;", "&lt;","&quot;", "&amp;" ),
353 array( ">" , "<" , '"' , "&" ),
354 $data
355 )
356 );
357 }
358 }
359
360 function _addElement( &$name, &$start, $add = array() )
361 {
362 if ( ( sizeof( $add ) == 0 && is_array( $add ) ) || ! $add )
363 {
364 if ( ! isset( $start[ $name ] ) ) $start[ $name ] = '';
365 $add = '';
366 }
367
368 $update = &$start[ $name ];
369
370 if ( is_array( $add) &&
371 is_array( $update ) ) $update += $add;
372 elseif ( is_array( $update ) ) return;
373 elseif ( is_array( $add ) ) $update = $add;
374 elseif ( $add ) $update .= $add;
375 }
376}
377?>
Note: See TracBrowser for help on using the repository browser.