Changeset 717 for branches/0.4/web


Ignore:
Timestamp:
03/21/13 21:43:10 (11 years ago)
Author:
ramonb
Message:
  • cleanup
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/0.4/web/addons/job_monarch/graph.php

    r714 r717  
    2828include "./libtoga.php";
    2929
    30 if ( !empty( $_GET ) ) {
     30if ( !empty( $_GET ) )
     31{
    3132        extract( $_GET );
    3233}
     
    5051
    5152# Assumes we have a $start variable (set in get_context.php).
    52 if ($size == "small") {
    53         $height = 40;
    54         $width = 130;
    55 } else if ($size == "medium") {
    56         $height = 75;
    57         $width = 300;
    58 } else {
    59         $height = 100;
    60         $width = 400;
    61 }
    62 
    63 if($command) {
     53if ($size == "small")
     54{
     55    $height = 40;
     56    $width = 130;
     57}
     58else if ($size == "medium")
     59{
     60    $height = 75;
     61    $width = 300;
     62}
     63else
     64{
     65    $height = 100;
     66    $width = 400;
     67}
     68
     69if($command)
     70{
    6471      $command = '';
    6572}
     
    6976$graph = $metricname;
    7077
    71 if (isset($graph)) {
    72         $series = '';
    73         if( isset( $period_start ) && isset( $period_stop ) )
    74         {
    75                 $rrd_dirs = $trd->getRrdDirs( $period_start, $period_stop );
    76         }
    77 
    78         if($graph == "cpu_report") {
    79 
    80                 $style = "CPU";
    81 
    82                 $upper_limit = "--upper-limit 100 --rigid";
    83                 $lower_limit = "--lower-limit 0";
    84 
    85                 $vertical_label = "--vertical-label Percent ";
    86 
    87                 $def_nr = 0;
    88 
    89                 foreach( $rrd_dirs as $rrd_dir ) {
    90 
    91                         if( $def_nr == 0 ) {
    92 
    93                                 $user_str = ":'User CPU'";
    94                                 $nice_str = ":'Nice CPU'";
    95                                 $system_str = ":'System CPU'";
    96                                 $wio_str = ":'WAIT CPU'";
    97                                 $idle_str = ":'Idle CPU'";
    98                         } else {
    99 
    100                                 $user_str = "";
    101                                 $nice_str = "";
    102                                 $system_str = "";
    103                                 $wio_str = "";
    104                                 $idle_str = "";
    105                         }
    106 
    107                         $series .= "DEF:'cpu_user${def_nr}'='${rrd_dir}/cpu_user.rrd':'sum':AVERAGE "
    108                                 ."DEF:'cpu_nice${def_nr}'='${rrd_dir}/cpu_nice.rrd':'sum':AVERAGE "
    109                                 ."DEF:'cpu_system${def_nr}'='${rrd_dir}/cpu_system.rrd':'sum':AVERAGE "
    110                                 ."DEF:'cpu_idle${def_nr}'='${rrd_dir}/cpu_idle.rrd':'sum':AVERAGE "
    111                                 ."AREA:'cpu_user${def_nr}'#${cpu_user_color}${user_str} "
    112                                 ."STACK:'cpu_nice${def_nr}'#${cpu_nice_color}${nice_str} "
    113                                 ."STACK:'cpu_system${def_nr}'#${cpu_system_color}${system_str} ";
    114 
    115                         if (file_exists("$rrd_dir/cpu_wio.rrd")) {
    116                                 $series .= "DEF:'cpu_wio${def_nr}'='${rrd_dir}/cpu_wio.rrd':'sum':AVERAGE "
    117                                         ."STACK:'cpu_wio${def_nr}'#${cpu_wio_color}${wio_str} ";
    118                         }
    119 
    120                         $series .= "STACK:'cpu_idle${def_nr}'#${cpu_idle_color}${idle_str} ";
    121 
    122                         $def_nr++;
    123                 }
    124 
    125         } else if ($graph == "job_report") {
    126                 $style = "Jobs";
    127 
    128                 $lower_limit = "--lower-limit 0 --rigid";
    129                 $vertical_label = "--vertical-label Jobs";
    130 
    131                 $def_nr = 0;
    132 
    133                 foreach( $metrics as $bhost => $bmetric )
    134                 {
    135                         foreach( $bmetric as $mname => $mval )
    136                         {
    137                                 if( ( $mname == 'MONARCH-RJ' ) || ($mname == 'MONARCH-QJ') )
    138                                 {
    139                                         $rjqj_host      = $bhost;
    140                                 }
    141                         }
    142                 }
    143 
    144                 $rrd_dir = "$rrds/$clustername/$rjqj_host/";
    145 
    146                 $rj_rrd = $rrd_dir . "MONARCH-RJ.rrd";
    147                 $qj_rrd = $rrd_dir . "MONARCH-QJ.rrd";
    148 
    149                 $sorted_hosts   = array();
    150                 $sorted_hosts[] = $rjqj_host;
    151 
    152                 $rj_str = ":'Running Jobs'";
    153                 $qj_str = ":'Queued Jobs'";
    154 
    155                 $series .= "DEF:'running_jobs'='${rj_rrd}':'sum':AVERAGE "
    156                         ."DEF:'queued_jobs'='${qj_rrd}':'sum':AVERAGE "
    157 
    158                
    159                         ."LINE3:'running_jobs'#ff0000${rj_str} "
    160                         ."LINE3:'queued_jobs'#999999${qj_str} ";
    161 
    162         } else if ($graph == "mem_report") {
    163                 $style = "Memory";
    164 
    165                 $lower_limit = "--lower-limit 0 --rigid";
    166                 $extras = "--base 1024";
    167                 $vertical_label = "--vertical-label Bytes";
    168 
    169                 $def_nr = 0;
    170 
    171                 foreach( $rrd_dirs as $rrd_dir ) {
    172 
    173                         if( $def_nr == 0 ) {
    174 
    175                                 $memuse_str = ":'Memory Used'";
    176                                 $memshared_str = ":'Memory Shared'";
    177                                 $memcached_str = ":'Memory Cached'";
    178                                 $membuff_str = ":'Memory Buffered'";
    179                                 $memswap_str = ":'Memory Swapped'";
    180                                 $total_str = ":'Total In-Core Memory'";
    181                         } else {
    182 
    183                                 $memuse_str = "";
    184                                 $memshared_str = "";
    185                                 $memcached_str = "";
    186                                 $membuff_str = "";
    187                                 $memswap_str = "";
    188                                 $total_str = "";
    189                         }
    190 
    191                         $series .= "DEF:'mem_total${def_nr}'='${rrd_dir}/mem_total.rrd':'sum':AVERAGE "
    192                                 ."CDEF:'bmem_total${def_nr}'=mem_total${def_nr},1024,* "
    193                                 ."DEF:'mem_shared${def_nr}'='${rrd_dir}/mem_shared.rrd':'sum':AVERAGE "
    194                                 ."CDEF:'bmem_shared${def_nr}'=mem_shared${def_nr},1024,* "
    195                                 ."DEF:'mem_free${def_nr}'='${rrd_dir}/mem_free.rrd':'sum':AVERAGE "
    196                                 ."CDEF:'bmem_free${def_nr}'=mem_free${def_nr},1024,* "
    197                                 ."DEF:'mem_cached${def_nr}'='${rrd_dir}/mem_cached.rrd':'sum':AVERAGE "
    198                                 ."CDEF:'bmem_cached${def_nr}'=mem_cached${def_nr},1024,* "
    199                                 ."DEF:'mem_buffers${def_nr}'='${rrd_dir}/mem_buffers.rrd':'sum':AVERAGE "
    200                                 ."CDEF:'bmem_buffers${def_nr}'=mem_buffers${def_nr},1024,* "
    201                                 ."CDEF:'bmem_used${def_nr}'='bmem_total${def_nr}','bmem_shared${def_nr}',-,'bmem_free${def_nr}',-,'bmem_cached${def_nr}',-,'bmem_buffers${def_nr}',- "
    202                                 ."AREA:'bmem_used${def_nr}'#${mem_used_color}${memuse_str} "
    203                                 ."STACK:'bmem_shared${def_nr}'#${mem_shared_color}${memshared_str} "
    204                                 ."STACK:'bmem_cached${def_nr}'#${mem_cached_color}${memcached_str} "
    205                                 ."STACK:'bmem_buffers${def_nr}'#${mem_buffered_color}${membuff_str} ";
    206 
    207                         if (file_exists("$rrd_dir/swap_total.rrd")) {
    208                                 $series .= "DEF:'swap_total${def_nr}'='${rrd_dir}/swap_total.rrd':'sum':AVERAGE "
    209                                         ."DEF:'swap_free${def_nr}'='${rrd_dir}/swap_free.rrd':'sum':AVERAGE "
    210                                         ."CDEF:'bmem_swapped${def_nr}'='swap_total${def_nr}','swap_free${def_nr}',-,1024,* "
    211                                         ."STACK:'bmem_swapped${def_nr}'#${mem_swapped_color}${memswap_str} ";
    212                         }
    213 
    214                         $series .= "LINE2:'bmem_total${def_nr}'#${cpu_num_color}${total_str} ";
    215 
    216                         $def_nr++;
    217                 }
    218 
    219         } else if ($graph == "load_report") {
    220                 $style = "Load";
    221 
    222                 $lower_limit = "--lower-limit 0 --rigid";
    223                 $vertical_label = "--vertical-label 'Load/Procs'";
    224 
    225                 $def_nr = 0;
    226 
    227                 foreach( $rrd_dirs as $rrd_dir ) {
    228 
    229                         if( $def_nr == 0 ) {
    230 
    231                                 $load_str = ":'1-min Load'";
    232                                 $cpu_str = ":'CPUs'";
    233                                 $run_str = ":'Running Processes'";
    234                         } else {
    235                                 $load_str = "";
    236                                 $cpu_str = "";
    237                                 $run_str = "";
    238                         }
    239 
    240                         $series .= "DEF:'load_one${def_nr}'='${rrd_dir}/load_one.rrd':'sum':AVERAGE "
    241                                 ."DEF:'proc_run${def_nr}'='${rrd_dir}/proc_run.rrd':'sum':AVERAGE "
    242                                 ."DEF:'cpu_num${def_nr}'='${rrd_dir}/cpu_num.rrd':'sum':AVERAGE ";
    243                         $series .="AREA:'load_one${def_nr}'#${load_one_color}${load_str} ";
    244                         $series .="LINE2:'cpu_num${def_nr}'#${cpu_num_color}${cpu_str} ";
    245                         $series .="LINE2:'proc_run${def_nr}'#${proc_run_color}${run_str} ";
    246 
    247                         $def_nr++;
    248                 }
    249 
    250         } else if ($graph == "network_report") {
    251                 $style = "Network";
    252 
    253                 $lower_limit = "--lower-limit 0 --rigid";
    254                 $extras = "--base 1024";
    255                 $vertical_label = "--vertical-label 'Bytes/sec'";
    256 
    257                 $def_nr = 0;
    258 
    259                 foreach( $rrd_dirs as $rrd_dir ) {
    260 
    261                         if( $def_nr == 0 ) {
    262 
    263                                 $in_str = ":'In'";
    264                                 $out_str = ":'Out'";
    265                         } else {
    266 
    267                                 $in_str = "";
    268                                 $out_str = "";
    269                         }
    270 
    271                         $series .= "DEF:'bytes_in${def_nr}'='${rrd_dir}/bytes_in.rrd':'sum':AVERAGE "
    272                                 ."DEF:'bytes_out${def_nr}'='${rrd_dir}/bytes_out.rrd':'sum':AVERAGE "
    273                                 ."LINE2:'bytes_in${def_nr}'#${mem_cached_color}${in_str} "
    274                                 ."LINE2:'bytes_out${def_nr}'#${mem_used_color}${out_str} ";
    275 
    276                         $def_nr++;
    277                 }
    278 
    279         } else if ($graph == "packet_report") {
    280                 $style = "Packets";
    281 
    282                 $lower_limit = "--lower-limit 0 --rigid";
    283                 $extras = "--base 1024";
    284                 $vertical_label = "--vertical-label 'Packets/sec'";
    285 
    286                 $def_nr = 0;
    287 
    288                 foreach( $rrd_dirs as $rrd_dir ) {
    289 
    290                         if( $def_nr == 0 ) {
    291 
    292                                 $in_str = ":'In'";
    293                                 $out_str = ":'Out'";
    294                         } else {
    295 
    296                                 $in_str = "";
    297                                 $out_str = "";
    298                         }
    299 
    300                         $series .= "DEF:'bytes_in${def_nr}'='${rrd_dir}/pkts_in.rrd':'sum':AVERAGE "
    301                                 ."DEF:'bytes_out${def_nr}'='${rrd_dir}/pkts_out.rrd':'sum':AVERAGE "
    302                                 ."LINE2:'bytes_in${def_nr}'#${mem_cached_color}${in_str} "
    303                                 ."LINE2:'bytes_out${def_nr}'#${mem_used_color}${out_str} ";
    304 
    305                         $def_nr++;
    306                 }
    307 
    308         } else {
    309                 /* Custom graph */
    310                 $style = "";
    311 
    312                 $subtitle = $metricname;
    313                 if ($context == "host") {
    314                         if ($size == "small")
    315                                 $prefix = $metricname;
    316                         else
    317                                 $prefix = $hostname;
    318 
    319                         $value = $value>1000 ? number_format($value) : number_format($value, 2);
    320                 }
    321 
    322                 if (is_numeric($max))
    323                         $upper_limit = "--upper-limit '$max' ";
    324                 if (is_numeric($min))
    325                         $lower_limit ="--lower-limit '$min' ";
    326 
    327                 if ($vlabel)
    328                         $vertical_label = "--vertical-label '$vlabel'";
    329                 else {
    330                         if ($upper_limit or $lower_limit) {
    331                                 $max = $max>1000 ? number_format($max) : number_format($max, 2);
    332                                 $min = $min>0 ? number_format($min,2) : $min;
    333 
    334                                 $vertical_label ="--vertical-label '$min - $max' ";
    335                         }
    336                 }
    337 
    338                 $def_nr = 0;
    339 
    340                 foreach( $rrd_dirs as $rrd_dir ) {
    341 
    342                         if( $def_nr == 0 ) {
    343                                 $title_str = ":'${subtitle}'";
    344                         } else {
    345                                 $title_str = "";
    346                         }
    347 
    348                         $rrd_file = "$rrd_dir/$metricname.rrd";
    349                         $series .= "DEF:'sum${def_nr}'='$rrd_file':'sum':AVERAGE "
    350                                 ."AREA:'sum${def_nr}'#${default_metric_color}${title_str} ";
    351 
    352                         $def_nr++;
    353                 }
    354 
    355         }
    356         if( $series != '' ) {
    357                 if ($job_start)
    358                         $series .= "VRULE:${job_start}#${jobstart_color} ";
    359                 if ($job_stop)
    360                         $series .= "VRULE:${job_stop}#${jobstart_color} ";
    361         }
     78if (isset($graph))
     79{
     80    $series = '';
     81    if( isset( $period_start ) && isset( $period_stop ) )
     82    {
     83        $rrd_dirs = $trd->getRrdDirs( $period_start, $period_stop );
     84    }
     85
     86    if($graph == "cpu_report")
     87    {
     88
     89        $style = "CPU";
     90
     91        $upper_limit = "--upper-limit 100 --rigid";
     92        $lower_limit = "--lower-limit 0";
     93
     94        $vertical_label = "--vertical-label Percent ";
     95
     96        $def_nr = 0;
     97
     98        foreach( $rrd_dirs as $rrd_dir )
     99        {
     100
     101            if( $def_nr == 0 )
     102            {
     103
     104                $user_str = ":'User CPU'";
     105                $nice_str = ":'Nice CPU'";
     106                $system_str = ":'System CPU'";
     107                $wio_str = ":'WAIT CPU'";
     108                $idle_str = ":'Idle CPU'";
     109            }
     110            else
     111            {
     112
     113                $user_str = "";
     114                $nice_str = "";
     115                $system_str = "";
     116                $wio_str = "";
     117                $idle_str = "";
     118            }
     119
     120            $series .= "DEF:'cpu_user${def_nr}'='${rrd_dir}/cpu_user.rrd':'sum':AVERAGE "
     121                ."DEF:'cpu_nice${def_nr}'='${rrd_dir}/cpu_nice.rrd':'sum':AVERAGE "
     122                ."DEF:'cpu_system${def_nr}'='${rrd_dir}/cpu_system.rrd':'sum':AVERAGE "
     123                ."DEF:'cpu_idle${def_nr}'='${rrd_dir}/cpu_idle.rrd':'sum':AVERAGE "
     124                ."AREA:'cpu_user${def_nr}'#${cpu_user_color}${user_str} "
     125                ."STACK:'cpu_nice${def_nr}'#${cpu_nice_color}${nice_str} "
     126                ."STACK:'cpu_system${def_nr}'#${cpu_system_color}${system_str} ";
     127
     128            if (file_exists("$rrd_dir/cpu_wio.rrd"))
     129            {
     130                $series .= "DEF:'cpu_wio${def_nr}'='${rrd_dir}/cpu_wio.rrd':'sum':AVERAGE "
     131                    ."STACK:'cpu_wio${def_nr}'#${cpu_wio_color}${wio_str} ";
     132            }
     133
     134            $series .= "STACK:'cpu_idle${def_nr}'#${cpu_idle_color}${idle_str} ";
     135
     136            $def_nr++;
     137        }
     138
     139    }
     140    else if ($graph == "job_report")
     141    {
     142        $style = "Jobs";
     143
     144        $lower_limit = "--lower-limit 0 --rigid";
     145        $vertical_label = "--vertical-label Jobs";
     146
     147        $def_nr = 0;
     148
     149        foreach( $metrics as $bhost => $bmetric )
     150        {
     151            foreach( $bmetric as $mname => $mval )
     152            {
     153                if( ( $mname == 'MONARCH-RJ' ) || ($mname == 'MONARCH-QJ') )
     154                {
     155                    $rjqj_host      = $bhost;
     156                }
     157            }
     158        }
     159
     160        $rrd_dir = "$rrds/$clustername/$rjqj_host/";
     161
     162        $rj_rrd    = $rrd_dir . "MONARCH-RJ.rrd";
     163        $qj_rrd    = $rrd_dir . "MONARCH-QJ.rrd";
     164
     165        $sorted_hosts    = array();
     166        $sorted_hosts[]    = $rjqj_host;
     167
     168        $rj_str = ":'Running Jobs'";
     169        $qj_str = ":'Queued Jobs'";
     170
     171        $series .= "DEF:'running_jobs'='${rj_rrd}':'sum':AVERAGE "
     172            ."DEF:'queued_jobs'='${qj_rrd}':'sum':AVERAGE "
     173
     174       
     175            ."LINE3:'running_jobs'#ff0000${rj_str} "
     176            ."LINE3:'queued_jobs'#999999${qj_str} ";
     177
     178    }
     179    else if ($graph == "mem_report")
     180    {
     181        $style = "Memory";
     182
     183        $lower_limit = "--lower-limit 0 --rigid";
     184        $extras = "--base 1024";
     185        $vertical_label = "--vertical-label Bytes";
     186
     187        $def_nr = 0;
     188
     189        foreach( $rrd_dirs as $rrd_dir )
     190        {
     191
     192            if( $def_nr == 0 )
     193            {
     194
     195                $memuse_str = ":'Memory Used'";
     196                $memshared_str = ":'Memory Shared'";
     197                $memcached_str = ":'Memory Cached'";
     198                $membuff_str = ":'Memory Buffered'";
     199                $memswap_str = ":'Memory Swapped'";
     200                $total_str = ":'Total In-Core Memory'";
     201            }
     202            else
     203            {
     204
     205                $memuse_str = "";
     206                $memshared_str = "";
     207                $memcached_str = "";
     208                $membuff_str = "";
     209                $memswap_str = "";
     210                $total_str = "";
     211            }
     212
     213            $series .= "DEF:'mem_total${def_nr}'='${rrd_dir}/mem_total.rrd':'sum':AVERAGE "
     214                ."CDEF:'bmem_total${def_nr}'=mem_total${def_nr},1024,* "
     215                ."DEF:'mem_shared${def_nr}'='${rrd_dir}/mem_shared.rrd':'sum':AVERAGE "
     216                ."CDEF:'bmem_shared${def_nr}'=mem_shared${def_nr},1024,* "
     217                ."DEF:'mem_free${def_nr}'='${rrd_dir}/mem_free.rrd':'sum':AVERAGE "
     218                ."CDEF:'bmem_free${def_nr}'=mem_free${def_nr},1024,* "
     219                ."DEF:'mem_cached${def_nr}'='${rrd_dir}/mem_cached.rrd':'sum':AVERAGE "
     220                ."CDEF:'bmem_cached${def_nr}'=mem_cached${def_nr},1024,* "
     221                ."DEF:'mem_buffers${def_nr}'='${rrd_dir}/mem_buffers.rrd':'sum':AVERAGE "
     222                ."CDEF:'bmem_buffers${def_nr}'=mem_buffers${def_nr},1024,* "
     223                ."CDEF:'bmem_used${def_nr}'='bmem_total${def_nr}','bmem_shared${def_nr}',-,'bmem_free${def_nr}',-,'bmem_cached${def_nr}',-,'bmem_buffers${def_nr}',- "
     224                ."AREA:'bmem_used${def_nr}'#${mem_used_color}${memuse_str} "
     225                ."STACK:'bmem_shared${def_nr}'#${mem_shared_color}${memshared_str} "
     226                ."STACK:'bmem_cached${def_nr}'#${mem_cached_color}${memcached_str} "
     227                ."STACK:'bmem_buffers${def_nr}'#${mem_buffered_color}${membuff_str} ";
     228
     229            if (file_exists("$rrd_dir/swap_total.rrd"))
     230            {
     231                $series .= "DEF:'swap_total${def_nr}'='${rrd_dir}/swap_total.rrd':'sum':AVERAGE "
     232                    ."DEF:'swap_free${def_nr}'='${rrd_dir}/swap_free.rrd':'sum':AVERAGE "
     233                    ."CDEF:'bmem_swapped${def_nr}'='swap_total${def_nr}','swap_free${def_nr}',-,1024,* "
     234                    ."STACK:'bmem_swapped${def_nr}'#${mem_swapped_color}${memswap_str} ";
     235            }
     236
     237            $series .= "LINE2:'bmem_total${def_nr}'#${cpu_num_color}${total_str} ";
     238
     239            $def_nr++;
     240        }
     241
     242    }
     243    else if ($graph == "load_report")
     244    {
     245        $style = "Load";
     246
     247        $lower_limit = "--lower-limit 0 --rigid";
     248        $vertical_label = "--vertical-label 'Load/Procs'";
     249
     250        $def_nr = 0;
     251
     252        foreach( $rrd_dirs as $rrd_dir )
     253        {
     254
     255            if( $def_nr == 0 )
     256            {
     257
     258                $load_str = ":'1-min Load'";
     259                $cpu_str = ":'CPUs'";
     260                $run_str = ":'Running Processes'";
     261            }
     262            else
     263            {
     264                $load_str = "";
     265                $cpu_str = "";
     266                $run_str = "";
     267            }
     268
     269            $series .= "DEF:'load_one${def_nr}'='${rrd_dir}/load_one.rrd':'sum':AVERAGE "
     270                ."DEF:'proc_run${def_nr}'='${rrd_dir}/proc_run.rrd':'sum':AVERAGE "
     271                ."DEF:'cpu_num${def_nr}'='${rrd_dir}/cpu_num.rrd':'sum':AVERAGE ";
     272            $series .="AREA:'load_one${def_nr}'#${load_one_color}${load_str} ";
     273            $series .="LINE2:'cpu_num${def_nr}'#${cpu_num_color}${cpu_str} ";
     274            $series .="LINE2:'proc_run${def_nr}'#${proc_run_color}${run_str} ";
     275
     276            $def_nr++;
     277        }
     278
     279    }
     280    else if ($graph == "network_report")
     281    {
     282        $style = "Network";
     283
     284        $lower_limit = "--lower-limit 0 --rigid";
     285        $extras = "--base 1024";
     286        $vertical_label = "--vertical-label 'Bytes/sec'";
     287
     288        $def_nr = 0;
     289
     290        foreach( $rrd_dirs as $rrd_dir )
     291        {
     292
     293            if( $def_nr == 0 )
     294            {
     295
     296                $in_str = ":'In'";
     297                $out_str = ":'Out'";
     298            }
     299            else
     300            {
     301
     302                $in_str = "";
     303                $out_str = "";
     304            }
     305
     306            $series .= "DEF:'bytes_in${def_nr}'='${rrd_dir}/bytes_in.rrd':'sum':AVERAGE "
     307                ."DEF:'bytes_out${def_nr}'='${rrd_dir}/bytes_out.rrd':'sum':AVERAGE "
     308                ."LINE2:'bytes_in${def_nr}'#${mem_cached_color}${in_str} "
     309                ."LINE2:'bytes_out${def_nr}'#${mem_used_color}${out_str} ";
     310
     311            $def_nr++;
     312        }
     313
     314    }
     315    else if ($graph == "packet_report")
     316    {
     317        $style = "Packets";
     318
     319        $lower_limit = "--lower-limit 0 --rigid";
     320        $extras = "--base 1024";
     321        $vertical_label = "--vertical-label 'Packets/sec'";
     322
     323        $def_nr = 0;
     324
     325        foreach( $rrd_dirs as $rrd_dir )
     326        {
     327
     328            if( $def_nr == 0 )
     329            {
     330
     331                $in_str = ":'In'";
     332                $out_str = ":'Out'";
     333            }
     334            else
     335            {
     336
     337                $in_str = "";
     338                $out_str = "";
     339            }
     340
     341            $series .= "DEF:'bytes_in${def_nr}'='${rrd_dir}/pkts_in.rrd':'sum':AVERAGE "
     342                ."DEF:'bytes_out${def_nr}'='${rrd_dir}/pkts_out.rrd':'sum':AVERAGE "
     343                ."LINE2:'bytes_in${def_nr}'#${mem_cached_color}${in_str} "
     344                ."LINE2:'bytes_out${def_nr}'#${mem_used_color}${out_str} ";
     345
     346            $def_nr++;
     347        }
     348
     349    }
     350    else
     351    {
     352        /* Custom graph */
     353        $style = "";
     354
     355        $subtitle = $metricname;
     356        if ($context == "host")
     357        {
     358            if ($size == "small")
     359                $prefix = $metricname;
     360            else
     361                $prefix = $hostname;
     362
     363            $value = $value>1000 ? number_format($value) : number_format($value, 2);
     364        }
     365
     366        if (is_numeric($max))
     367            $upper_limit = "--upper-limit '$max' ";
     368        if (is_numeric($min))
     369            $lower_limit ="--lower-limit '$min' ";
     370
     371        if ($vlabel)
     372        {
     373            $vertical_label = "--vertical-label '$vlabel'";
     374        }
     375        else
     376        {
     377            if ($upper_limit or $lower_limit)
     378            {
     379                $max = $max>1000 ? number_format($max) : number_format($max, 2);
     380                $min = $min>0 ? number_format($min,2) : $min;
     381
     382                $vertical_label ="--vertical-label '$min - $max' ";
     383            }
     384        }
     385
     386        $def_nr = 0;
     387
     388        foreach( $rrd_dirs as $rrd_dir )
     389        {
     390
     391            if( $def_nr == 0 )
     392            {
     393                $title_str = ":'${subtitle}'";
     394            }
     395            else
     396            {
     397                $title_str = "";
     398            }
     399
     400            $rrd_file = "$rrd_dir/$metricname.rrd";
     401            $series .= "DEF:'sum${def_nr}'='$rrd_file':'sum':AVERAGE "
     402                ."AREA:'sum${def_nr}'#${default_metric_color}${title_str} ";
     403
     404            $def_nr++;
     405        }
     406
     407    }
     408    if( $series != '' )
     409    {
     410        if ($job_start)
     411            $series .= "VRULE:${job_start}#${jobstart_color} ";
     412        if ($job_stop)
     413            $series .= "VRULE:${job_stop}#${jobstart_color} ";
     414    }
    362415}
    363416
    364417$title = "$hostname";
    365418
    366 function determineXGrid( $p_start, $p_stop ) {
    367 
    368         $period = intval( $p_stop - $p_start );
    369 
    370         // Syntax: <minor_grid_lines_time_declr>:<major_grid_lines_time_declr>:<labels_time_declr>:<offset>:<format>
    371         //
    372         // Where each <*time_declr*> = <time_type>:<time_interval>
    373 
    374         //$my_lines1 = intval( $period / 3.0 );
    375         //$my_lines2 = intval( $period / 6.0 );
    376 
    377         //$my_grid = "SECOND:$my_lines2:SECOND:$my_lines1:SECOND:$my_lines1:0:%R";
    378 
    379         //return "--x-grid $my_grid";
    380 
    381         // Less than 1 minute
    382         if( $period < 60 ) {
    383 
    384                 $tm_formt = "%X";
    385                 $my_grid = "SECOND:15:SECOND:30:SECOND:30:0:$tm_formt";
    386 
    387         // Less than 10 minutes
    388         } else if( $period < 600 ) {
    389 
    390                 $tm_formt = "%R";
    391                 $my_grid = "MINUTE:1:MINUTE:3:MINUTE:3:0:$tm_formt";
    392 
    393         // Less than 1 hour
    394         } else if( $period < 3600 ) {
    395 
    396                 $tm_formt = "%R";
    397                 $my_grid = "MINUTE:5:MINUTE:15:MINUTE:15:0:$tm_formt";
    398 
    399         // Less than 15 hour
    400         } else if( $period < 3600 ) {
    401 
    402                 $tm_formt = "%R";
    403                 $my_grid = "HOUR:1:HOUR:2:HOUR:2:0:$tm_formt";
    404 
    405         // Less than 1 day
    406         //
    407         } else if( $period < 86400 ) {
    408 
    409                 $tm_formt = "%R";
    410                 $my_grid = "HOUR:2:HOUR:5:HOUR:5:0:$tm_formt";
    411 
    412         // Less than 15 days
    413         //
    414         } else if( $period < 1296000 ) {
    415 
    416                 $tm_formt = "%e-%m";
    417                 $my_grid = "HOUR:1:DAY:3:DAY:3:0:'$tm_formt'";
    418                
    419         // Less than 30 days (a month)
    420         //
    421         } else if( $period < 2592000 ) {
    422 
    423                 $tm_formt = "%e-%m";
    424                 $my_grid = "DAY:5:DAY:10:DAY:10:0:'$tm_formt'";
    425         }
    426 
    427         if( isset( $my_grid ) ) {
    428 
    429                 $ret_str = "--x-grid $my_grid";
    430                 return array($ret_str,$tm_formt);
    431 
    432         } else {
    433                 return array( "", "" );
    434         }
    435 }
    436 
    437 #list( $xgrid, $t_format ) = determineXGrid( $period_start, $period_stop );
    438 
    439 #if( $t_format != "" ) {
    440 #       $prnt_start = strftime( $t_format, $period_start );
    441 #       $prnt_stop = strftime( $t_format, $period_stop );
    442 #       $series .= " COMMENT:'     Timescale $prnt_start - $prnt_stop' ";
    443 #}
     419function determineXGrid( $p_start, $p_stop )
     420{
     421
     422    $period = intval( $p_stop - $p_start );
     423
     424    // Syntax: <minor_grid_lines_time_declr>:<major_grid_lines_time_declr>:<labels_time_declr>:<offset>:<format>
     425    //
     426    // Where each <*time_declr*> = <time_type>:<time_interval>
     427
     428    //$my_lines1 = intval( $period / 3.0 );
     429    //$my_lines2 = intval( $period / 6.0 );
     430
     431    //$my_grid = "SECOND:$my_lines2:SECOND:$my_lines1:SECOND:$my_lines1:0:%R";
     432
     433    //return "--x-grid $my_grid";
     434
     435    // Less than 1 minute
     436    if( $period < 60 )
     437    {
     438
     439        $tm_formt = "%X";
     440        $my_grid = "SECOND:15:SECOND:30:SECOND:30:0:$tm_formt";
     441
     442    // Less than 10 minutes
     443    }
     444    else if( $period < 600 )
     445    {
     446
     447        $tm_formt = "%R";
     448        $my_grid = "MINUTE:1:MINUTE:3:MINUTE:3:0:$tm_formt";
     449
     450    // Less than 1 hour
     451    }
     452    else if( $period < 3600 )
     453    {
     454
     455        $tm_formt = "%R";
     456        $my_grid = "MINUTE:5:MINUTE:15:MINUTE:15:0:$tm_formt";
     457
     458    // Less than 15 hour
     459    }
     460    else if( $period < 3600 )
     461    {
     462
     463        $tm_formt = "%R";
     464        $my_grid = "HOUR:1:HOUR:2:HOUR:2:0:$tm_formt";
     465
     466    // Less than 1 day
     467    //
     468    }
     469    else if( $period < 86400 )
     470    {
     471
     472        $tm_formt = "%R";
     473        $my_grid = "HOUR:2:HOUR:5:HOUR:5:0:$tm_formt";
     474
     475    // Less than 15 days
     476    //
     477    }
     478    else if( $period < 1296000 )
     479    {
     480
     481        $tm_formt = "%e-%m";
     482        $my_grid = "HOUR:1:DAY:3:DAY:3:0:'$tm_formt'";
     483       
     484    // Less than 30 days (a month)
     485    //
     486    }
     487    else if( $period < 2592000 )
     488    {
     489
     490        $tm_formt = "%e-%m";
     491        $my_grid = "DAY:5:DAY:10:DAY:10:0:'$tm_formt'";
     492    }
     493
     494    if( isset( $my_grid ) )
     495    {
     496
     497        $ret_str = "--x-grid $my_grid";
     498        return array($ret_str,$tm_formt);
     499
     500    }
     501    else
     502    {
     503        return array( "", "" );
     504    }
     505}
    444506
    445507$lower_limit = "--lower-limit 0";
     
    448510if( isset($sourcetime) )
    449511{
    450         $end = $sourcetime;
    451         # Get_context makes start negative.
    452         $start = $sourcetime + $start;
    453 
    454         # Fix from Phil Radden, but step is not always 15 anymore.
    455         if ($range=="month")
    456                 $end = floor($end / 672) * 672;
    457 
    458         $command = $conf['rrdtool']. " graph - --start $start --end $end ".
    459                 "--width $width --height $height $lower_limit ".
    460                 "--title '$title' $extras $background ".
    461                 $series;
    462 }
    463 
    464 #
    465 # Generate the rrdtool graph command.
    466 #
    467 #$command = RRDTOOL . " graph - --start $period_start --end $period_stop ".
    468 #       "--width $width --height $height $upper_limit $lower_limit ".
    469 #       "--title '$title' $vertical_label $extras $background $xgrid ".
    470 #       $series;
    471 
    472 else {
    473         $command = $conf['rrdtool'] . " graph - --start $period_start --end $period_stop ".
    474                 "--width $width --height $height $lower_limit ".
    475                 "--title '$title' $extras $background ".
    476                 $series;
     512    $end = $sourcetime;
     513    # Get_context makes start negative.
     514    $start = $sourcetime + $start;
     515
     516    # Fix from Phil Radden, but step is not always 15 anymore.
     517    if ($range=="month")
     518        $end = floor($end / 672) * 672;
     519
     520    $command = $conf['rrdtool']. " graph - --start $start --end $end ".
     521        "--width $width --height $height $lower_limit ".
     522        "--title '$title' $extras $background ".
     523        $series;
     524}
     525else
     526{
     527    $command = $conf['rrdtool'] . " graph - --start $period_start --end $period_stop ".
     528        "--width $width --height $height $lower_limit ".
     529        "--title '$title' $extras $background ".
     530        $series;
    477531}
    478532
     
    480534
    481535# Did we generate a command?   Run it.
    482 if($command) {
    483         /*Make sure the image is not cached*/
    484         header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");   // Date in the past
    485         header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
    486         header ("Cache-Control: no-cache, must-revalidate");   // HTTP/1.1
    487         header ("Pragma: no-cache");                     // HTTP/1.0
    488         if ($debug) {
    489                 header ("Content-type: text/html");
    490                 print "$command\n\n\n\n\n";
    491         } else {
    492                 header ("Content-type: image/gif");
    493                 passthru($command);
    494         }
     536if($command)
     537{
     538    /*Make sure the image is not cached*/
     539    header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");   // Date in the past
     540    header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
     541    header ("Cache-Control: no-cache, must-revalidate");   // HTTP/1.1
     542    header ("Pragma: no-cache");                     // HTTP/1.0
     543    if ($debug)
     544    {
     545        header ("Content-type: text/html");
     546        print "$command\n\n\n\n\n";
     547    }
     548    else
     549    {
     550        header ("Content-type: image/gif");
     551        passthru($command);
     552    }
    495553}
    496554?>
Note: See TracChangeset for help on using the changeset viewer.