- Timestamp:
- 06/14/05 16:51:35 (18 years ago)
- Location:
- trunk/web/addons/toga
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/web/addons/toga/index.php
r129 r138 37 37 global $self, $filter, $cluster_url, $get_metric_string; 38 38 global $metrics, $reports, $m, $default_metric; 39 global $default_refresh ;39 global $default_refresh, $filterorder, $view; 40 40 41 41 if( isset($default_metric) and !isset($m) ) … … 150 150 $node_menu .= "<B><A HREF=\"./?c=".rawurlencode($clustername)."\">Joblist</A></B> "; 151 151 152 if( count( $filter ) > 0 ) { 153 154 foreach( $filter as $filtername => $filterval ) { 155 156 $node_menu .= "<B>></B>\n"; 157 $node_menu .= "<B>$filtername- $filterval</B> "; 152 if( count( $filter ) > 0 && $view != "search" ) { 153 154 $filter_fields = explode( ",", $filterorder ); 155 $onclick_href = array(); 156 157 if( count( $filter_fields ) > 1 ) { 158 //for( $i = (count( $filter_fields )-2); $i >= 0; $i-- ) { 159 160 // for( $l = intval($i+1); $l <=(count($filter_fields)-1); $l++ ) { 161 //$onclick_href[$filter_fields[$i]] = $onclick_href[$filter_fields[$i]] . "removeFilter( '" . $filter_fields[$l] . "' );"; 162 // if( !isset( $onclick_href[$filter_fields[$i]] ) ) 163 // $onclick_href[$filter_fields[$i]] = "removeFilters( '".$filter_fields[$l]; 164 // else 165 // $onclick_href[$filter_fields[$i]] = $onclick_href[$filter_fields[$i]] . " ". $filter_fields[$l]; 166 167 // } 168 // $onclick_href[$filter_fields[$i]] = $onclick_href[$filter_fields[$i]] . "' )"; 169 //} 170 foreach( $filter_fields as $filtername ) { 171 172 $node_menu .= "<B>></B>\n"; 173 if( isset( $onclick_href[$filtername] ) ) 174 $node_menu .= "<B><A HREF =\"#\" onClick=\"".$onclick_href[$filtername]."\">$filtername: $filter[$filtername]</A></B> "; 175 else 176 $node_menu .= "<B>$filtername: $filter[$filtername]</B> "; 177 } 178 } else { 179 180 foreach( $filter as $filtername=>$filterval ) { 181 $node_menu .= "<B>></B>\n"; 182 $node_menu .= "<B>$filtername: $filterval</B> "; 183 } 158 184 } 185 159 186 } 160 187 -
trunk/web/addons/toga/libtoga.php
r135 r138 87 87 global $metrics, $hosts_up; 88 88 89 90 89 class TarchDbase { 91 90 92 var $ip, $dbase ;91 var $ip, $dbase, $conn; 93 92 94 93 function TarchDbase( $ip = null, $dbase = 'toga' ) { 95 94 $this->ip = $ip; 96 95 $this->dbase = $dbase; 96 $this->conn = null; 97 97 } 98 98 … … 100 100 101 101 if( $this->ip == null and $this->dbase == 'toga' ) 102 $this->conn = pg_connect( "db ase=".$this->dbase );102 $this->conn = pg_connect( "dbname=".$this->dbase ); 103 103 else 104 104 $this->conn = pg_connect( "host=".$this->ip." dbase=".$this->dbase ); 105 105 } 106 107 function searchDbase( $id = null, $queue = null, $user = null, $name = null, $start_from_time = null, $start_to_time = null, $end_from_time = null, $end_to_time = null ) { 108 109 if( $id ) 110 $query = "SELECT job_id FROM jobs WHERE job_id = '$id'"; 111 else { 112 $query_args = array(); 113 114 if( $queue ) 115 $query_args[] = "job_queue ='$queue'"; 116 if( $user ) 117 $query_args[] = "job_owner ='$user'"; 118 if( $name ) 119 $query_args[] = "job_name = '$name'"; 120 if( $start_from_time ) 121 $query_args[] = "job_start_timestamp >= $start_from_time"; 122 if( $start_end_time ) 123 $query_args[] = "job_start_timestamp <= $start_to_time"; 124 if( $end_from_time ) 125 $query_args[] = "job_stop_timestamp >= $end_from_time"; 126 if( $end_to_time ) 127 $query_args[] = "job_stop_timestamp <= $end_to_time"; 128 129 $query = "SELECT job_id FROM jobs WHERE "; 130 $extra_query_args = ''; 131 132 foreach( $query_args as $myquery ) { 133 134 if( $extra_query_args == '' ) 135 $extra_query_args = $myquery; 136 else 137 $extra_query_args .= " AND ".$myquery; 138 } 139 $query .= $extra_query_args; 140 } 141 142 $ids = $this->queryDbase( $query ); 143 print_r($ids); 144 } 145 146 function getNodesForJob( $jobid ) { 147 148 $result = $this->queryDbase( "SELECT node_id FROM job_nodes WHERE job_id = '$jobid'" ); 149 150 $nodes = array(); 151 152 foreach( $result as $result_row ) 153 154 $nodes[] = $this->getNodeArray( $result_row['id'] ); 155 156 return $nodes; 157 } 158 159 function getJobsForNode( $nodeid ) { 160 161 $result = $this->queryDbase( "SELECT job_id FROM job_nodes WHERE node_id = '$nodeid'" ); 162 163 $jobs = array(); 164 165 foreach( $result as $result_row ) 166 167 $jobs[] = $this->getJobArray( $result_row['id'] ); 168 169 return $jobs; 170 } 171 172 function getJobArray( $id ) { 173 $result = $this->queryDbase( "SELECT * FROM jobs WHERE job_id = '$id'" ); 174 175 return ( $this->makeArray( $result[0] ) ); 176 } 177 178 function getNodeArray( $id ) { 179 180 $result = $this->queryDbase( "SELECT * FROM nodes WHERE node_id = '$id'" ); 181 182 return ( $this->makeArray( $result[0] ) ); 183 } 184 185 function makeArray( $result_row ) { 186 187 $myar = array(); 188 189 foreach( $result_row as $mykey => $myval ) { 190 191 $map_key = explode( '_', $mykey ); 192 193 $newkey = $map_key[1]; 194 195 $myar[$newkey] = $result_row[$mykey]; 196 } 197 198 return $myar; 199 } 200 201 function queryDbase( $query ) { 202 203 $result_rows = array(); 204 205 if( !$this->conn ) 206 $this->connect(); 207 208 $result = pg_query( $this->conn, $query ); 209 210 while ($row = pg_fetch_assoc($result)) 211 $result_rows[] = $row; 212 213 return $result_rows; 214 } 106 215 } 107 216 108 class TarchRrd {217 class TarchRrdGraph { 109 218 var $rrdbin, $rrdvalues, $clustername, $hostname, $tempdir, $tarchdir, $metrics; 110 219 111 function TarchRrd( $ rrdbin = '/usr/bin/rrdtool', $tarchdir = '/data/toga/rrds' ) {220 function TarchRrd( $clustername, $rrdbin = '/usr/bin/rrdtool', $tarchdir = '/data/toga/rrds' ) { 112 221 $this->rrdbin = $rrdbin; 113 222 $this->rrdvalues = array(); 114 223 $this->tarchdir = $tarchdir; 115 $this->tempdir = '/tmp/toga-web-temp';116 $this->metrics = array();117 224 } 118 225 … … 158 265 $times = array(); 159 266 $dirlist = $this->dirList( $this->tarchdir . '/' . $this->clustername . '/' . $this->hostname ); 160 //print_r( $dirlist );161 162 267 $first = 0; 163 268 $last = 9999999999999; 164 269 165 270 foreach( $dirlist as $dir ) { 166 167 //printf("dir = %s\n", $dir );168 271 169 272 if( $dir > $first and $dir <= $start ) … … 173 276 } 174 277 175 //if( $first != 0 and !array_key_exists( $first, $times ) )176 // $times[] = $first;177 178 278 foreach( $dirlist as $dir ) { 179 279 … … 182 282 } 183 283 184 //if( $last != 9999999999 and !array_key_exists( $last, $times ) )185 // $times[] = $last;186 187 284 sort( $times ); 188 285 189 //print_r( $times );190 191 286 return $times; 192 }193 194 function getIntervalStep( $file ) {195 196 $ret = $this->doCmd( $this->rrdbin .' info '. $file );197 198 foreach( $ret as $r ) {199 200 $fields = explode( ' = ', $r );201 202 if( $fields[0] == 'step' )203 return $fields[1];204 }205 206 return null;207 }208 209 function makeJobRrd( $clustername, $hostname, $metric, $descr, $start, $end) {210 $this->clustername = $clustername;211 $this->hostname = $hostname;212 213 $myvalues = array();214 215 $times = $this->getTimePeriods( $start, $end );216 217 if( count( $times ) > 0 ) {218 219 $time_size = count( $times );220 $curtime = 1;221 //print_r( $this->metrics );222 223 $firstold = $this->tarchdir . '/' . $this->clustername . '/' . $this->hostname .'/'. $times[0]. '/'.$metric;224 225 if( !file_exists( $firstold ) )226 return 0;227 228 $hostdir = $this->tempdir .'/'. $hostname;229 $newdir = $hostdir .'/'.$descr;230 $newfile = $newdir .'/'.$metric;231 232 //if( file_exists( $newfile ) )233 // return 0;234 235 if( !file_exists( $hostdir ) )236 mkdir( $hostdir );237 238 if( !file_exists( $newdir ) )239 mkdir( $newdir );240 241 //$this->metrics = $this->dirList( $this->tarchdir . '/' . $this->clustername . '/' . $this->hostname .'/'. $times[0] );242 $intv = $this->getIntervalStep( '"'.$firstold.'"' );243 244 foreach( $times as $timep ) {245 246 $r_start = null;247 $r_end = null;248 249 if( $curtime == 1 )250 $r_start = $start;251 252 if( $curtime == $time_size )253 $r_end = $end;254 255 $file = $this->tarchdir . '/' . $this->clustername . '/' . $this->hostname .'/'. $timep .'/'. $metric;256 257 $r_values = $this->getValues( $file, $r_start, $r_end );258 //print_r($r_values);259 260 $myvalues = $myvalues + $r_values;261 262 $curtime++;263 }264 //printf( "----myvalues----\n" );265 //print_r($myvalues);266 //printf( "----myvalues----\n" );267 268 $heartbeat = intval( 8 * $intv );269 $ret = $this->doCmd( $this->rrdbin .' create "'.$newfile.'" --step '. $intv .' --start '. $start .' DS:sum:GAUGE:'.$heartbeat.':U:U RRA:AVERAGE:0.5:1:'. count( $myvalues ) );270 271 $update_args = array();272 $arglist_nr = 0;273 274 ksort( $myvalues );275 reset( $myvalues );276 $myvalues = array_unique( $myvalues );277 reset( $myvalues );278 279 foreach( $myvalues as $mytime=>$myvalue ) {280 $myupdateval = ' '.trim($mytime).':'.trim($myvalue);281 282 if( !isset($update_args[$arglist_nr]) )283 $update_args[$arglist_nr] = '';284 285 // Max_Args for Linux kernel is normally about 130k286 //287 if( intval( strlen($update_args[$arglist_nr]) + strlen($myupdateval) ) > 100000 )288 $arglist_nr++;289 290 $update_args[$arglist_nr] .= $myupdateval;291 }292 293 //printf( "grootte args = %s\n", strlen( $update_args ) );294 295 foreach( $update_args as $update_arg )296 $ret = $this->doCmd( $this->rrdbin .' update "'. $newfile . '"'.$update_arg );297 298 printf( "generated %s\n", $newfile );299 } else300 return 0;301 }302 303 function getValues( $file, $start = null, $end = null ) {304 305 $rrdargs = 'AVERAGE -r 15';306 307 if( $start )308 $rrdargs .= ' -s '. $start;309 if( $end )310 $rrdargs .= ' -e '. $end;311 312 $values = $this->doCmd( $this->rrdbin .' fetch "'.$file.'" '. $rrdargs );313 314 //print_r( $values );315 $arvalues = array();316 317 foreach( $values as $value ) {318 //printf( "value = %s\n", $value );319 320 $fields = explode( ':', $value );321 322 if( count( $fields ) == 2 ) {323 324 $timestamp = trim($fields[0]);325 $keepval = 1;326 327 if( $start ) {328 329 if( intval($timestamp) >= intval($start) )330 $keepval = 1;331 else332 $keepval = 0;333 } else if( $end ) {334 335 if( intval($timestamp) <= intval($end) )336 $keepval = 1;337 else338 $keepval = 0;339 }340 341 $value = $fields[1];342 //printf("timestamp = %s, value = %s\n", $timestamp, $value );343 344 if( $keepval and !isset($arvalues[$timestamp] ) )345 $arvalues[$timestamp] = $value;346 }347 }348 //printf( "----arvalues----\n" );349 //print_r( $arvalues);350 //printf( "----arvalues----\n" );351 352 //ksort( $arvalues );353 //printf( "----arsortvalues----\n" );354 //print_r( $arvalues);355 //printf( "----arsortvalues----\n" );356 357 return $arvalues;358 287 } 359 288 -
trunk/web/addons/toga/overview.php
r135 r138 1 1 <?php 2 2 global $GANGLIA_PATH, $clustername, $tpl, $filter, $cluster, $get_metric_string, $cluster_url, $sh; 3 global $hosts_up, $m, $start, $end ;3 global $hosts_up, $m, $start, $end, $filterorder; 4 4 5 5 $data_gatherer = new DataGatherer(); … … 26 26 27 27 $tpl->assign( "clusterimage", "./image.php?c=".rawurlencode($clustername)."&view=big-clusterimage".$filter_image_url ); 28 $tpl->assign( "f_order", $filterorder ); 28 29 29 30 if( array_key_exists( "id", $filter ) ) -
trunk/web/addons/toga/search.php
r130 r138 3 3 global $clustername, $tpl; 4 4 5 function makeSearchPage() { 6 global $clustername; 5 function validateFormInput() { 6 global $clustername, $tpl, $id, $user, $name, $start_from_time, $start_to_time, $queue; 7 global $end_from_time, $end_to_time; 7 8 8 $tr = new TarchRrd(); 9 $tr->makeJobRrds( $clustername, 'gb-r1n1.irc.sara.nl', 'testje', 1114936341, 1115015563 ); 10 // bla! 9 $error = 0; 10 11 $none_set = 0; 12 13 //if( $id == '' or $user == '' or $name == '' or $start_from_time == '' or $start_to_time == '' or $queue == '' or $end_from_time == '' or $end_to_time == '') $none_set = 1; 14 15 //if (!isset($id) and !isset($user) and !isset($start_from_time) and !isset($start_to_time) and !isset($end_from_time) and !isset($end_to_time) and !isset($queue) ) $none_set = 0; 16 17 if( $none_set ) { 18 $error = 1; 19 $error_msg = "<FONT COLOR=\"red\"><B>No search criteria set!</B></FONT>"; 20 } 21 22 // doe checks en set error en error_msg in case shit 23 24 if( $error) { 25 $tpl->assign( "form_error_msg", $error_msg ); 26 return 0; 27 } else { 28 return 1; 29 } 11 30 } 12 31 32 function makeSearchPage() { 33 global $clustername, $tpl, $id, $user, $name, $start_from_time, $start_to_time, $queue; 34 global $end_from_time, $end_to_time; 35 36 $tpl->assign( "cluster", $clustername ); 37 $tpl->assign( "id_value", $id ); 38 $tpl->assign( "user_value", $user ); 39 $tpl->assign( "queue_value", $queue ); 40 $tpl->assign( "name_value", $name ); 41 $tpl->assign( "start_from_value", rawurldecode( $start_from_time ) ); 42 $tpl->assign( "start_to_value", rawurldecode( $start_to_time ) ); 43 $tpl->assign( "end_from_value", rawurldecode( $end_from_time ) ); 44 $tpl->assign( "end_to_value", rawurldecode( $end_to_time ) ); 45 46 if( validateFormInput() ) { 47 48 $tdb = new TarchDbase(); 49 $tdb->searchDbase( $id, $queue, $user, $name, $start_from_time, $start_to_time, $end_from_time, $end_to_time ); 50 $tpl->assign( "search_results", "templates/search_results.tpl" ); 51 52 // show search results 53 54 } 55 } 13 56 ?> -
trunk/web/addons/toga/templates/overview.tpl
r135 r138 55 55 //document.toga_form.state.value = ''; 56 56 //document.toga_form.user.value = ''; 57 var myfilterorder = document.toga_form.elements['filterorder'].value; 57 58 58 59 if( document.toga_form.elements[filtername] ) { 59 60 document.toga_form.elements[filtername].value = filterval; 61 if( myfilterorder != '') 62 myfilterorder = myfilterorder + "," + filtername; 63 else 64 myfilterorder = filtername; 65 60 66 } 67 document.toga_form.elements['filterorder'].value = myfilterorder; 68 69 //setTimeout( "document.forms['toga_form'].submit();", 1000 ); 61 70 62 71 document.forms['toga_form'].submit(); 63 72 } 73 74 //function removeFilters( filters ) { 75 76 //var myfilter_fields = filters.split( " " ); 77 //for( var i=0; i<myfilter_fields.length; i++ ) { 78 //removeFilter( myfilter_fields[i] ); 79 //setTimeout( "removeFilter( "+myfilter_fields[i]+" );", 50 ); 80 //} 81 // delay 100 ms before submit or fields might not be set 82 //document.forms['toga_form'].submit();", 100 ); 83 84 //setTimeout( "document.forms['toga_form'].submit();", 1000 ); 85 //} 86 87 //function removeFilter( filtername ) { 88 89 // var filterorder_fields = document.toga_form.elements['filterorder'].value.split( "," ); 90 // var myfilterorder = ''; 91 92 // for( var i=0; i<filterorder_fields.length; i++ ) { 93 // if( filterorder_fields[i] != filtername ) { 94 // if( myfilterorder != '') { 95 // myfilterorder = myfilterorder + "," + filterorder_fields[i]; 96 // //alert('myfilterorder = '+myfilterorder); 97 // } else { 98 // myfilterorder = filterorder_fields[i]; 99 // //alert('emyfilterorder = '+myfilterorder); 100 // } 101 // } 102 // } 103 // document.toga_form.elements[filtername].value = ''; 104 // document.toga_form.elements['filterorder'].value = myfilterorder; 105 //} 106 64 107 </SCRIPT> 65 108 … … 71 114 <INPUT TYPE="HIDDEN" NAME="user" VALUE="{f_user}"> 72 115 <INPUT TYPE="HIDDEN" NAME="id" VALUE="{f_id}"> 116 <INPUT TYPE="HIDDEN" NAME="filterorder" VALUE="{f_order}"> 73 117 74 118 <TABLE WIDTH="90%" CELLPADDING="8" CELLSPACING="3" BORDER=0>
Note: See TracChangeset
for help on using the changeset viewer.