| 
									
										
										
										
											2011-10-28 18:29:22 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-10 13:36:21 +02:00
										 |  |  | $dest = device_by_id_cache($_GET['dest']); | 
					
						
							| 
									
										
										
										
											2011-10-28 18:29:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-25 12:24:34 +00:00
										 |  |  | // This is my translation of Smokeping's graphing.
 | 
					
						
							|  |  |  | // Thanks to Bill Fenner for Perl->Human translation:>
 | 
					
						
							| 
									
										
										
										
											2015-07-10 13:36:21 +02:00
										 |  |  | $scale_min   = 0; | 
					
						
							|  |  |  | $scale_rigid = true; | 
					
						
							| 
									
										
										
										
											2011-10-28 18:29:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-10 13:36:21 +02:00
										 |  |  | require 'includes/graphs/common.inc.php'; | 
					
						
							|  |  |  | require 'smokeping_common.inc.php'; | 
					
						
							| 
									
										
										
										
											2011-10-28 18:29:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-10 13:36:21 +02:00
										 |  |  | $i         = 0; | 
					
						
							| 
									
										
										
										
											2015-12-29 07:10:15 +10:00
										 |  |  | $pings     = $config['smokeping']['pings']; | 
					
						
							| 
									
										
										
										
											2015-07-10 13:36:21 +02:00
										 |  |  | $iter      = 0; | 
					
						
							|  |  |  | $colourset = 'mixed'; | 
					
						
							| 
									
										
										
										
											2011-10-28 18:29:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-10 13:36:21 +02:00
										 |  |  | if ($width > '500') { | 
					
						
							|  |  |  |     $descr_len = 18; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | else { | 
					
						
							|  |  |  |     $descr_len = (12 + round(($width - 275) / 8)); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-10-28 18:29:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-10 13:36:21 +02:00
										 |  |  | if ($width > '500') { | 
					
						
							|  |  |  |     $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, ($descr_len + 5)), 0, ($descr_len + 5))." RTT      Loss    SDev   RTT\:SDev                              \l'"; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | else { | 
					
						
							|  |  |  |     $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, ($descr_len + 5)), 0, ($descr_len + 5))." RTT      Loss    SDev   RTT\:SDev                              \l'"; | 
					
						
							| 
									
										
										
										
											2011-10-28 18:29:22 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-10 13:36:21 +02:00
										 |  |  | if ($device['hostname'] == $config['own_hostname']) { | 
					
						
							|  |  |  |     $filename = $config['smokeping']['dir'].$dest['hostname'].'.rrd'; | 
					
						
							|  |  |  |     if (!file_exists($filename)) { | 
					
						
							|  |  |  |         // Try with dots in hostname replaced by underscores
 | 
					
						
							|  |  |  |         $filename = $config['smokeping']['dir'].str_replace('.', '_', $dest['hostname']).'.rrd'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | else { | 
					
						
							|  |  |  |     $filename = $config['smokeping']['dir'].$dest['hostname'].'~'.$device['hostname'].'.rrd'; | 
					
						
							|  |  |  |     if (!file_exists($filename)) { | 
					
						
							|  |  |  |         // Try with dots in hostname replaced by underscores
 | 
					
						
							|  |  |  |         $filename = $config['smokeping']['dir'].str_replace('.', '_', $dest['hostname']).'~'.$device['hostname'].'.rrd'; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-10-28 18:29:22 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-10 13:36:21 +02:00
										 |  |  | if (!isset($config['graph_colours'][$colourset][$iter])) { | 
					
						
							|  |  |  |     $iter = 0; | 
					
						
							| 
									
										
										
										
											2011-10-28 18:29:22 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   $colour = $config['graph_colours'][$colourset][$iter]; | 
					
						
							|  |  |  |   $iter++; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-10 13:36:21 +02:00
										 |  |  |   $descr = rrdtool_escape($source, $descr_len); | 
					
						
							| 
									
										
										
										
											2011-10-28 18:29:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-10 13:36:21 +02:00
										 |  |  |   $rrd_options .= " DEF:median$i=".$filename.':median:AVERAGE '; | 
					
						
							|  |  |  |   $rrd_options .= " DEF:loss$i=".$filename.':loss:AVERAGE'; | 
					
						
							| 
									
										
										
										
											2011-10-28 18:29:22 +00:00
										 |  |  |   $rrd_options .= " CDEF:ploss$i=loss$i,$pings,/,100,*"; | 
					
						
							|  |  |  |   $rrd_options .= " CDEF:dm$i=median$i"; | 
					
						
							| 
									
										
										
										
											2015-07-10 13:36:21 +02:00
										 |  |  | // $rrd_options .= " CDEF:dm$i=median$i,0,".$max->{$start}.",LIMIT";
 | 
					
						
							| 
									
										
										
										
											2012-05-25 12:24:34 +00:00
										 |  |  |   // start emulate Smokeping::calc_stddev
 | 
					
						
							| 
									
										
										
										
											2015-07-10 13:36:21 +02:00
										 |  |  | foreach (range(1, $pings) as $p) { | 
					
						
							|  |  |  |     $rrd_options .= ' DEF:pin'.$i.'p'.$p.'='.$filename.':ping'.$p.':AVERAGE'; | 
					
						
							|  |  |  |     $rrd_options .= ' CDEF:p'.$i.'p'.$p.'=pin'.$i.'p'.$p.',UN,0,pin'.$i.'p'.$p.',IF'; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-10-28 18:29:22 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   unset($pings_options, $m_options, $sdev_options); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-10 13:36:21 +02:00
										 |  |  | foreach (range(2, $pings) as $p) { | 
					
						
							|  |  |  |     $pings_options .= ',p'.$i.'p'.$p.',UN,+'; | 
					
						
							|  |  |  |     $m_options     .= ',p'.$i.'p'.$p.',+'; | 
					
						
							|  |  |  |     $sdev_options  .= ',p'.$i.'p'.$p.',m'.$i.',-,DUP,*,+'; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-10-28 18:29:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-10 13:36:21 +02:00
										 |  |  |   $rrd_options .= ' CDEF:pings'.$i.'='.$pings.',p'.$i.'p1,UN'.$pings_options.',-'; | 
					
						
							|  |  |  |   $rrd_options .= ' CDEF:m'.$i.'=p'.$i.'p1'.$m_options.',pings'.$i.',/'; | 
					
						
							|  |  |  |   $rrd_options .= ' CDEF:sdev'.$i.'=p'.$i.'p1,m'.$i.',-,DUP,*'.$sdev_options.',pings'.$i.',/,SQRT'; | 
					
						
							| 
									
										
										
										
											2011-10-28 18:29:22 +00:00
										 |  |  |   // end emulate Smokeping::calc_stddev
 | 
					
						
							|  |  |  |   $rrd_options .= " CDEF:dmlow$i=dm$i,sdev$i,2,/,-"; | 
					
						
							|  |  |  |   $rrd_options .= " CDEF:s2d$i=sdev$i"; | 
					
						
							|  |  |  |   $rrd_options .= " AREA:dmlow$i"; | 
					
						
							| 
									
										
										
										
											2015-07-10 13:36:21 +02:00
										 |  |  |   $rrd_options .= " AREA:s2d$i#".$colour.'30::STACK'; | 
					
						
							| 
									
										
										
										
											2011-10-28 18:29:22 +00:00
										 |  |  |   $rrd_options .= " LINE1:dm$i#".$colour.":'$descr'"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-10 13:36:21 +02:00
										 |  |  | // $rrd_options .= " LINE1:sdev$i#000000:$descr";
 | 
					
						
							| 
									
										
										
										
											2011-10-28 18:29:22 +00:00
										 |  |  |   $rrd_options .= " VDEF:avmed$i=median$i,AVERAGE"; | 
					
						
							|  |  |  |   $rrd_options .= " VDEF:avsd$i=sdev$i,AVERAGE"; | 
					
						
							|  |  |  |   $rrd_options .= " CDEF:msr$i=median$i,POP,avmed$i,avsd$i,/"; | 
					
						
							|  |  |  |   $rrd_options .= " VDEF:avmsr$i=msr$i,AVERAGE"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   $rrd_options .= " GPRINT:avmed$i:'%5.1lf%ss'"; | 
					
						
							|  |  |  |   $rrd_options .= " GPRINT:ploss$i:AVERAGE:'%5.1lf%%'"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   $rrd_options .= " GPRINT:avsd$i:'%5.1lf%Ss'"; | 
					
						
							|  |  |  |   $rrd_options .= " GPRINT:avmsr$i:'%5.1lf%s\\l'"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   $i++; |