forked from HPCNow/PHPQstat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqhost.php
182 lines (151 loc) · 4.58 KB
/
qhost.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?php require_once( 'navigation.php' ); ?>
<html>
<head>
<title>PHPQstat</title>
<meta name="AUTHOR" content="Jordi Blasco Pallares ">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="KEYWORDS" content="gridengine sge sun hpc supercomputing batch queue linux xml qstat qhost jordi blasco solnu">
<meta http-equiv="refresh" content="30"/>
<link rel="stylesheet" href="phpqstat.css" type="text/css" />
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" type="text/css" />
<script type="text/javascript" language="javascript" src="/media/js/jquery.js"></script>
<script type="text/javascript" language="javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript" language="javascript" src="/media/js/jquery.dataTables.js"></script>
<script>
$(document).ready(function() {
$('.qstat').dataTable( {
"bPaginate": false,
"bLengthChange": false,
"bFilter": true,
"bJQueryUI": true,
"bAutoWidth": true,
"aoColumnDefs": [
{
"aTargets": [ 3 ],
"fnCreatedCell": function(nTd, sData, oData, iRow, iCol)
{
if ( oData[3] == '-' ) {
$(nTd).parent().addClass( 'down' );
}
},
},
],
} );
} );
</script>
</head>
<body>
<table align=center width=95% border="1" cellpadding="0" cellspacing="0"><tbody>
<tr><td><h1>PHPQstat</h1></td></tr>
<tr><td CLASS=\"bottom\" align=center>
<?php displayNav( $_GET['owner'] ); ?>
</td>
</tr>
<tr>
<td>
<br>
<table class="qstat" align=center width=95% border="1" cellpadding="0" cellspacing="0">
<thead>
<tr CLASS="header">
<th>Hostname</th>
<th>Architecture</th>
<th>NCPU</th>
<th>Load avg</th>
<th>mem_total</th>
<th>mem_used</th>
<th>swap_total</th>
<th>swap_used</th>
<th>Queues</th>
</tr>
</thead>
<tbody>
<?php
$password_length = 20;
function make_seed() {
list($usec, $sec) = explode(' ', microtime());
return (float) $sec + ((float) $usec * 100000);
}
function rstrstr($haystack,$needle)
{
return substr($haystack, 0,strpos($haystack, $needle));
}
srand(make_seed());
$alfa = "1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
$token = "";
for($i = 0; $i < $password_length; $i ++) {
$token .= $alfa[rand(0, strlen($alfa))];
}
// array to store status of all queue instances (queue@host)
$queueinstances = array();
$out = exec("./qquinst /tmp/$token.queueinstances");
foreach ( file ( "/tmp/$token.queueinstances" ) as $qi ) {
// $hostarr = explode ( "@", $host );
// Bug in qhost: sometimes the fqdn gets truncated...
// $queuehosts[ rstrstr( trim( $hostarr[1] ), '.ethz' ) . '.ethz.ch' ][] = trim ( $hostarr[0] );
if ( strstr($qi, '@') ) {
$d = explode ( " ", $qi );
$queueinstances[ $d[0] ] = array ( "name" => trim ( $d[0] ),
"qtype" => trim ( $d[1] ),
"rut" => trim ( $d[2] ),
"lavg" => trim ( $d[3] ),
"arch" => trim ( $d[4] ),
"states" => trim ( $d[5] )
);
}
}
//echo "<pre>";
//print_r ( $queueinstances );
//echo "</pre>";
// array to store the queue hosts
$queuehosts = array();
// Get a list of all hosts with associated queues
$out = exec("./qqueuehosts /tmp/$token.hostlist");
foreach ( file ( "/tmp/$token.hostlist" ) as $host ) {
$hostarr = explode ( "@", $host );
// Bug in qhost: sometimes the fqdn gets truncated...
$queuehosts[ rstrstr( trim( $hostarr[1] ), '.ethz' ) . '.ethz.ch' ][] = trim ( $hostarr[0] );
}
$out = exec("./qhostout /tmp/$token.xml");
//printf("System Output: $out\n");
$qhost = simplexml_load_file("/tmp/$token.xml");
$i=0;
foreach ($qhost->host as $host) {
echo "<tr>";
$hostname=$host['name'];
echo " <td>$hostname</td>";
foreach ($qhost->host[$i] as $hostvalue) {
echo " <td>$hostvalue</td>";
}
echo "<td>";
if ( count ( $queuehosts[ trim ( $hostname ) ] ) != 0 ) {
foreach ( $queuehosts[ trim ( $hostname ) ] as $queue ) {
$states = trim ( $queueinstances[ "$queue@" . trim ( $hostname ) ][ 'states' ] );
if ( $states != '' ) {
echo $queue . " [$states], ";
}
else {
echo $queue . ", ";
}
}
}
else {
echo " ";
}
echo "</td>";
echo "</tr>";
$i++;
}
exec("rm /tmp/$token.xml");
?>
</tbody>
</table>
<br>
</td>
</tr>
<?php
include("bottom.php");
?>
</tbody>
</table>
</body>
</html>