Ignore:
Timestamp:
06/14/05 16:51:35 (19 years ago)
Author:
bastiaans
Message:

web/addons/toga/templates/search_results.tpl:

  • Setup for search results template

web/addons/toga/templates/overview.tpl:

  • Misc testing stuff for remembering filter order

web/addons/toga/templates/search.tpl:

  • Template for search

web/addons/toga/index.php:

  • Testing stuff from remembering filter order
  • Do not add filters in a search window

web/addons/toga/overview.php:

  • Extra test field for filterorder

web/addons/toga/search.php:

  • First good setup for search page

web/addons/toga/libtoga.php:

  • Added class TarchDbase? for searching SQL dbase for archived jobs
  • Added TarchRrd? for future generation of RRD Graphs for archived jobs
  • Cleaned up old RRD file generation code (we can graph on the fly!)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/web/addons/toga/libtoga.php

    r135 r138  
    8787global $metrics, $hosts_up;
    8888
    89 
    9089class TarchDbase {
    9190
    92         var $ip, $dbase;
     91        var $ip, $dbase, $conn;
    9392
    9493        function TarchDbase( $ip = null, $dbase = 'toga' ) {
    9594                $this->ip = $ip;
    9695                $this->dbase = $dbase;
     96                $this->conn = null;
    9797        }
    9898
     
    100100
    101101                if( $this->ip == null and $this->dbase == 'toga' )
    102                         $this->conn = pg_connect( "dbase=".$this->dbase );
     102                        $this->conn = pg_connect( "dbname=".$this->dbase );
    103103                else
    104104                        $this->conn = pg_connect( "host=".$this->ip." dbase=".$this->dbase );
    105105        }
     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        }
    106215}
    107216
    108 class TarchRrd {
     217class TarchRrdGraph {
    109218        var $rrdbin, $rrdvalues, $clustername, $hostname, $tempdir, $tarchdir, $metrics;
    110219
    111         function TarchRrd( $rrdbin = '/usr/bin/rrdtool', $tarchdir = '/data/toga/rrds' ) {
     220        function TarchRrd( $clustername, $rrdbin = '/usr/bin/rrdtool', $tarchdir = '/data/toga/rrds' ) {
    112221                $this->rrdbin = $rrdbin;
    113222                $this->rrdvalues = array();
    114223                $this->tarchdir = $tarchdir;
    115                 $this->tempdir = '/tmp/toga-web-temp';
    116                 $this->metrics = array();
    117224        }
    118225
     
    158265                $times = array();
    159266                $dirlist = $this->dirList( $this->tarchdir . '/' . $this->clustername . '/' . $this->hostname );
    160                 //print_r( $dirlist );
    161 
    162267                $first = 0;
    163268                $last = 9999999999999;
    164269
    165270                foreach( $dirlist as $dir ) {
    166 
    167                         //printf("dir = %s\n", $dir );
    168271
    169272                        if( $dir > $first and $dir <= $start )
     
    173276                }
    174277
    175                 //if( $first != 0 and !array_key_exists( $first, $times ) )
    176                 //      $times[] = $first;
    177 
    178278                foreach( $dirlist as $dir ) {
    179279
     
    182282                }
    183283
    184                 //if( $last != 9999999999 and !array_key_exists( $last, $times ) )
    185                 //      $times[] = $last;
    186 
    187284                sort( $times );
    188285
    189                 //print_r( $times );
    190 
    191286                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 130k
    286                                 //
    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                 } else
    300                         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                                         else
    332                                                 $keepval = 0;
    333                                 } else if( $end ) {
    334 
    335                                         if( intval($timestamp) <= intval($end) )
    336                                                 $keepval = 1;
    337                                         else
    338                                                 $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;
    358287        }
    359288
Note: See TracChangeset for help on using the changeset viewer.