source: trunk/web/addons/toga/graph.php @ 143

Last change on this file since 143 was 143, checked in by bastiaans, 19 years ago

web/addons/toga/libtoga.php:

  • Removed debug print

web/addons/toga/redcross.jpg:

  • Image for clearing date/time fields (tnx walter ;))

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

  • Header form name configurable

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

  • Moved javascript back in for modification
  • Misc. cosmetic changes
  • Added clear buttons for date/time fields

web/addons/toga/index.php:

  • Header will now label "Jobsearch" in header

web/addons/toga/search.php:

  • Misc. cleanup
  • Initial graphing code setup

web/addons/toga/graph.php:

  • Modified / modifyable graphing script for archive jobs

web/addons/toga/next.gif:

  • Next month button of datepicker

web/addons/toga/prev.gif:

  • Previous month button of datepicker

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

  • Configurable form
File size: 10.8 KB
RevLine 
[143]1<?php
2/* $Id: graph.php,v 1.8 2005/02/18 14:20:35 knobi1 Exp $ */
3include_once "./conf.php";
4include_once "./get_context.php";
5
6if ( !empty( $_GET ) ) {
7        extract( $_GET );
8}
9
10# Graph specific variables
11$size = escapeshellcmd( rawurldecode( $HTTP_GET_VARS["z"] ));
12$graph = escapeshellcmd( rawurldecode( $HTTP_GET_VARS["g"] ));
13$grid = escapeshellcmd( rawurldecode( $HTTP_GET_VARS["G"] ));
14$self = escapeshellcmd( rawurldecode( $HTTP_GET_VARS["me"] ));
15$max = escapeshellcmd( rawurldecode( $HTTP_GET_VARS["x"] ));
16$min = escapeshellcmd( rawurldecode( $HTTP_GET_VARS["n"] ));
17$value = escapeshellcmd( rawurldecode( $HTTP_GET_VARS["v"] ));
18$load_color = escapeshellcmd( rawurldecode( $HTTP_GET_VARS["l"] ));
19$vlabel = escapeshellcmd( rawurldecode( $HTTP_GET_VARS["vl"] ));
20$sourcetime = escapeshellcmd($HTTP_GET_VARS["st"]);
21
22# Assumes we have a $start variable (set in get_context.php).
23if ($size == "small")
24    {
25      $height = 40;
26      $width = 130;
27    }
28else if ($size == "medium")
29    {
30      $height = 75;
31      $width = 300;
32    }
33else
34    {
35      $height = 100;
36      $width = 400;
37    }
38
39
40# This security fix was brought to my attention by Peter Vreugdenhil <petervre@sci.kun.nl>
41# Dont want users specifying their own malicious command via GET variables e.g.
42# http://ganglia.mrcluster.org/graph.php?graph=blob&command=whoami;cat%20/etc/passwd
43#
44if($command)
45    {
46      exit();
47    }
48
49switch ($context)
50{
51    case "meta":
52      $rrd_dir = "$rrds/__SummaryInfo__";
53      break;
54    case "grid":
55      $rrd_dir = "$rrds/$grid/__SummaryInfo__";
56      break;
57    case "cluster":
58      $rrd_dir = "$rrds/$clustername/__SummaryInfo__";
59      break;
60    case "host":
61      $rrd_dir = "$rrds/$clustername/$hostname";
62      break;
63    default:
64      exit;
65}
66
67if ($graph)   /* Canned graph request */
68    {
69      if($graph == "cpu_report")
70         {
71            $style = "CPU";
72
73            $upper_limit = "--upper-limit 100 --rigid";
74            $lower_limit = "--lower-limit 0";
75
76            $vertical_label = "--vertical-label Percent ";
77
78            if($context != "host" )
79               {
80                  /* If we are not in a host context, then we need to calculate the average */
81                  $series =
82                  "DEF:'num_nodes'='${rrd_dir}/cpu_user.rrd':'num':AVERAGE "
83                  ."DEF:'cpu_user'='${rrd_dir}/cpu_user.rrd':'sum':AVERAGE "
84                  ."CDEF:'ccpu_user'=cpu_user,num_nodes,/ "
85                  ."DEF:'cpu_nice'='${rrd_dir}/cpu_nice.rrd':'sum':AVERAGE "
86                  ."CDEF:'ccpu_nice'=cpu_nice,num_nodes,/ "
87                  ."DEF:'cpu_system'='${rrd_dir}/cpu_system.rrd':'sum':AVERAGE "
88                  ."CDEF:'ccpu_system'=cpu_system,num_nodes,/ "
89                  ."DEF:'cpu_idle'='${rrd_dir}/cpu_idle.rrd':'sum':AVERAGE "
90                  ."CDEF:'ccpu_idle'=cpu_idle,num_nodes,/ "
91                  ."AREA:'ccpu_user'#$cpu_user_color:'User CPU' "
92                  ."STACK:'ccpu_nice'#$cpu_nice_color:'Nice CPU' "
93                  ."STACK:'ccpu_system'#$cpu_system_color:'System CPU' ";
94                  if (file_exists("$rrd_dir/cpu_wio.rrd")) {
95                     $series .= "DEF:'cpu_wio'='${rrd_dir}/cpu_wio.rrd':'sum':AVERAGE "
96                     ."CDEF:'ccpu_wio'=cpu_wio,num_nodes,/ "
97                     ."STACK:'ccpu_wio'#$cpu_wio_color:'WAIT CPU' ";
98                  }
99                  $series .= "STACK:'ccpu_idle'#$cpu_idle_color:'Idle CPU' ";
100               }
101            else
102               {
103                  $series ="DEF:'cpu_user'='${rrd_dir}/cpu_user.rrd':'sum':AVERAGE "
104                  ."DEF:'cpu_nice'='${rrd_dir}/cpu_nice.rrd':'sum':AVERAGE "
105                  ."DEF:'cpu_system'='${rrd_dir}/cpu_system.rrd':'sum':AVERAGE "
106                  ."DEF:'cpu_idle'='${rrd_dir}/cpu_idle.rrd':'sum':AVERAGE "
107                  ."AREA:'cpu_user'#$cpu_user_color:'User CPU' "
108                  ."STACK:'cpu_nice'#$cpu_nice_color:'Nice CPU' "
109                  ."STACK:'cpu_system'#$cpu_system_color:'System CPU' ";
110                  if (file_exists("$rrd_dir/cpu_wio.rrd")) {
111                     $series .= "DEF:'cpu_wio'='${rrd_dir}/cpu_wio.rrd':'sum':AVERAGE "
112                     ."STACK:'cpu_wio'#$cpu_wio_color:'WAIT CPU' ";
113                  }
114                  $series .= "STACK:'cpu_idle'#$cpu_idle_color:'Idle CPU' ";
115               }
116         }
117      else if ($graph == "mem_report")
118         {
119            $style = "Memory";
120
121            $lower_limit = "--lower-limit 0 --rigid";
122            $extras = "--base 1024";
123            $vertical_label = "--vertical-label Bytes";
124
125            $series = "DEF:'mem_total'='${rrd_dir}/mem_total.rrd':'sum':AVERAGE "
126               ."CDEF:'bmem_total'=mem_total,1024,* "
127               ."DEF:'mem_shared'='${rrd_dir}/mem_shared.rrd':'sum':AVERAGE "
128               ."CDEF:'bmem_shared'=mem_shared,1024,* "
129               ."DEF:'mem_free'='${rrd_dir}/mem_free.rrd':'sum':AVERAGE "
130               ."CDEF:'bmem_free'=mem_free,1024,* "
131               ."DEF:'mem_cached'='${rrd_dir}/mem_cached.rrd':'sum':AVERAGE "
132               ."CDEF:'bmem_cached'=mem_cached,1024,* "
133               ."DEF:'mem_buffers'='${rrd_dir}/mem_buffers.rrd':'sum':AVERAGE "
134               ."CDEF:'bmem_buffers'=mem_buffers,1024,* "
135               ."CDEF:'bmem_used'='bmem_total','bmem_shared',-,'bmem_free',-,'bmem_cached',-,'bmem_buffers',- "
136               ."AREA:'bmem_used'#$mem_used_color:'Memory Used' "
137               ."STACK:'bmem_shared'#$mem_shared_color:'Memory Shared' "
138               ."STACK:'bmem_cached'#$mem_cached_color:'Memory Cached' "
139               ."STACK:'bmem_buffers'#$mem_buffered_color:'Memory Buffered' ";
140            if (file_exists("$rrd_dir/swap_total.rrd")) {
141               $series .= "DEF:'swap_total'='${rrd_dir}/swap_total.rrd':'sum':AVERAGE "
142               ."DEF:'swap_free'='${rrd_dir}/swap_free.rrd':'sum':AVERAGE "
143               ."CDEF:'bmem_swapped'='swap_total','swap_free',-,1024,* "
144               ."STACK:'bmem_swapped'#$mem_swapped_color:'Memory Swapped' ";
145            }
146            $series .= "LINE2:'bmem_total'#$cpu_num_color:'Total In-Core Memory' ";
147         }
148      else if ($graph == "load_report")
149         {
150            $style = "Load";
151
152            $lower_limit = "--lower-limit 0 --rigid";
153            $vertical_label = "--vertical-label 'Load/Procs'";
154
155            $series = "DEF:'load_one'='${rrd_dir}/load_one.rrd':'sum':AVERAGE "
156               ."DEF:'proc_run'='${rrd_dir}/proc_run.rrd':'sum':AVERAGE "
157               ."DEF:'cpu_num'='${rrd_dir}/cpu_num.rrd':'sum':AVERAGE ";
158            if( $context != "host" )
159               {
160                  $series .="DEF:'num_nodes'='${rrd_dir}/cpu_num.rrd':'num':AVERAGE ";
161               }
162            $series .="AREA:'load_one'#$load_one_color:'1-min Load' ";
163            if( $context != "host" )
164               {
165                  $series .= "LINE2:'num_nodes'#$num_nodes_color:'Nodes' ";
166               }
167            $series .="LINE2:'cpu_num'#$cpu_num_color:'CPUs' ";
168            $series .="LINE2:'proc_run'#$proc_run_color:'Running Processes' ";
169         }
170      else if ($graph == "network_report")
171         {
172            $style = "Network";
173
174            $lower_limit = "--lower-limit 0 --rigid";
175            $extras = "--base 1024";
176            $vertical_label = "--vertical-label 'Bytes/sec'";
177
178            $series = "DEF:'bytes_in'='${rrd_dir}/bytes_in.rrd':'sum':AVERAGE "
179               ."DEF:'bytes_out'='${rrd_dir}/bytes_out.rrd':'sum':AVERAGE "
180               ."LINE2:'bytes_in'#$mem_cached_color:'In' "
181               ."LINE2:'bytes_out'#$mem_used_color:'Out' ";
182         }
183      else if ($graph == "packet_report")
184         {
185            $style = "Packets";
186
187            $lower_limit = "--lower-limit 0 --rigid";
188            $extras = "--base 1024";
189            $vertical_label = "--vertical-label 'Packets/sec'";
190
191            $series = "DEF:'bytes_in'='${rrd_dir}/pkts_in.rrd':'sum':AVERAGE "
192               ."DEF:'bytes_out'='${rrd_dir}/pkts_out.rrd':'sum':AVERAGE "
193               ."LINE2:'bytes_in'#$mem_cached_color:'In' "
194               ."LINE2:'bytes_out'#$mem_used_color:'Out' ";
195         }
196      else
197         {
198      /* Custom graph */
199      $style = "";
200
201      $subtitle = $metricname;
202      if ($context == "host") 
203      {
204          if ($size == "small")
205              $prefix = $metricname;
206          else
207              $prefix = $hostname;
208
209          $value = $value>1000 ? number_format($value) : number_format($value, 2);
210
211          if ($range=="job") {
212               $hrs = intval( -$jobrange / 3600 );
213               $subtitle = "$prefix last ${hrs}h (now $value)";
214          }
215          else
216              $subtitle = "$prefix last $range (now $value)";
217      }
218
219      if (is_numeric($max))
220         $upper_limit = "--upper-limit '$max' ";
221      if (is_numeric($min))
222         $lower_limit ="--lower-limit '$min' ";
223
224      if ($vlabel)
225         $vertical_label = "--vertical-label '$vlabel'";
226      else if ($upper_limit or $lower_limit)
227         {
228            $max = $max>1000 ? number_format($max) : number_format($max, 2);
229            $min = $min>0 ? number_format($min,2) : $min;
230
231            $vertical_label ="--vertical-label '$min - $max' ";
232         }
233
234      $rrd_file = "$rrd_dir/$metricname.rrd";
235      $series = "DEF:'sum'='$rrd_file':'sum':AVERAGE "
236         ."AREA:'sum'#$default_metric_color:'$subtitle' ";
237      if ($jobstart)
238         $series .= "VRULE:$jobstart#$jobstart_color ";
239    }
240
241# Set the graph title.
242if($context == "meta")
243   {
244     $title = "$self $meta_designator $style last $range";
245   }
246else if ($context == "grid")
247  {
248     $title = "$grid $meta_designator $style last $range";
249  }
250else if ($context == "cluster")
251   {
252      $title = "$clustername $style last $range";
253   }
254else
255   {
256    if ($size == "small")
257      {
258        # Value for this graph define a background color.
259        if (!$load_color) $load_color = "ffffff";
260        $background = "--color BACK#'$load_color'";
261
262        $title = $hostname;
263      }
264    else if ($style)
265       $title = "$hostname $style last $range";
266    else
267       $title = $metricname;
268   }
269
270# Fix from Phil Radden, but step is not always 15 anymore.
271if ($range=="month")
272   $end = floor($end / 672) * 672;
273
274#
275# Generate the rrdtool graph command.
276#
277$command = RRDTOOL . " graph - --start $start --end $end ".
278   "--width $width --height $height $upper_limit $lower_limit ".
279   "--title '$title' $vertical_label $extras $background ".
280   $series;
281
282$debug=0;
283
284# Did we generate a command?   Run it.
285if($command)
286 {
287   /*Make sure the image is not cached*/
288   header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");   // Date in the past
289   header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
290   header ("Cache-Control: no-cache, must-revalidate");   // HTTP/1.1
291   header ("Pragma: no-cache");                     // HTTP/1.0
292   if ($debug) {
293     header ("Content-type: text/html");
294     print "$command\n\n\n\n\n";
295    }
296   else {
297     header ("Content-type: image/gif");
298     passthru($command);
299    }
300 }
301
302?>
303
Note: See TracBrowser for help on using the repository browser.