Fix checkRpItemsPosition
[ryzomcore.git] / web / public_php / admin / functions_tool_graphs.php
blobba043891cd07b2bcb4e041829d6e40a108ea689d
1 <?php
3 $tool_graph_menu = array(array('title' => 'CCU',
4 'key' => 'ccu',
5 'uri' => 'tool_graphs.php?toolmode=ccu',
6 'tpl' => 'tool_graphs_ccu.tpl',
7 'access' => '',
8 ),
9 array('title' => 'Tech Shard',
10 'key' => 'tech',
11 'uri' => 'tool_graphs.php?toolmode=tech',
12 'tpl' => 'tool_graphs_tech.tpl',
13 'access' => '',
15 array('title' => 'Hi-Res Shard',
16 'key' => 'hires',
17 'uri' => 'tool_graphs.php?toolmode=hires',
18 'tpl' => 'tool_graphs_hires.tpl',
19 'access' => '',
21 array('title' => 'Old',
22 'key' => 'old',
23 'uri' => 'tool_graphs.php?toolmode=old',
24 'tpl' => 'tool_graphs.tpl',
25 'access' => '',
29 $tool_hires_frames = array(array('title' => '10 seconds',
30 'value' => 10000,
31 'step' => 0,
32 'default' => false,
34 array('title' => '30 seconds',
35 'value' => 30000,
36 'step' => 0,
37 'default' => true,
39 array('title' => '90 seconds',
40 'value' => 90000,
41 'step' => 0,
42 'default' => false,
46 $tool_lowres_frames = array(array('title' => '20 minutes',
47 'value' => 1200,
48 'default' => false,
50 array('title' => '3 hours',
51 'value' => 10800,
52 'default' => false,
54 array('title' => '24 hours',
55 'value' => 86400,
56 'default' => true,
58 array('title' => '7 days',
59 'value' => 604800,
60 'default' => false,
62 array('title' => '30 days',
63 'value' => 2592000,
64 'default' => false,
66 array('title' => '90 days',
67 'value' => 7776000,
68 'default' => false,
72 function tool_graphs_time_frame_get_default($list)
74 reset($list);
75 foreach($list as $frame)
77 if ($frame['default'] == true) return $frame['value'];
81 function tool_graphs_menu_get_list()
83 global $tool_graph_menu;
84 global $nel_user;
86 $new_menu = array();
88 reset($tool_graph_menu);
89 foreach($tool_graph_menu as $menu_item)
91 if (($menu_item['access'] == '') || tool_admin_applications_check($menu_item['access']))
93 $new_menu[] = $menu_item;
97 return $new_menu;
100 function tool_graphs_menu_get_item_from_key($key)
102 global $tool_graph_menu;
104 reset($tool_graph_menu);
105 foreach($tool_graph_menu as $tool_menu)
107 if ($tool_menu['key'] == $key) return $tool_menu;
110 return null;
113 function tool_graphs_find($needles, $list)
115 $result = array();
117 reset($needles);
118 foreach($needles as $needle)
120 if (isset($list[$needle['variable']]))
122 nt_common_add_debug("variable found ". $needle['variable']);
123 reset($list[$needle['variable']]);
124 foreach($list[$needle['variable']] as $var)
126 nt_common_add_debug("checking '". $needle['service'] ."' in '". $var['service'] ."'");
127 if (ereg("^". $needle['service'] .".*$",$var['service']))
129 nt_common_add_debug("adding ". $var['service']);
130 $result[] = $var;
136 return $result;
139 function tool_graphs_get_list_v2($dir, $shard_match, $high=false, $domain=false)
141 $data = array();
143 if (!ereg("^[a-zA-Z0-9_]+$",$shard_match) && !$domain) return $data;
145 if (substr($dir, -1) != '/') $dir .= '/';
147 if (is_dir($dir))
149 if ($handle = opendir($dir))
151 while (($file = readdir($handle)) !== false)
153 if (($file != '.') && ($file != '..'))
155 $filelist[] = $file;
158 closedir($handle);
160 sort($filelist);
161 nt_common_add_debug($filelist);
163 //fes_arispotle_01.NetSpeedLoop.hrd
164 //egs_arispotle.TickSpeedLoop.hrd
165 //$my_ereg = "^([^_]+_(". $shard_match .")(_[^\ \.])?)\.([^\ ]+)\.([hr])rd$";
166 //$my_ereg = "^([^_]+_(". $shard_match .")(_[^\ \.])?)\.([^\ ]+)\.rrd$";
167 $my_ereg = "^([^_]+(_[^_]+)?_(". $shard_match .")(_[^\ \.])?)\.([^.]+)\.". ($high === true ? 'h':'r') ."rd$";
168 nt_common_add_debug("using regexp: ".$my_ereg);
170 // 0: complete file name
171 // 1: service alias (eg. fes_arispotle_01)
172 // 2: n/a
173 // 3: shard (eg. arispotle)
174 // 4: n/a
175 // 5: variable (eg. NetSpeedLoop)
177 // this is special, mainly to catch domain wide variables, such as su.* which don't have a shard
178 $my_ereg2 = "^([^_]+(_[^_]+)?(_[^\ \.])?)\.([^.]+)\.". ($high === true ? 'h':'r') ."rd$";
179 nt_common_add_debug("using regexp2: ".$my_ereg2);
181 // 0: complete file name
182 // 1: service alias (eg. fes_arispotle_01)
183 // 2: n/a
184 // 3: n/a
185 // 4: variable (eg. NetSpeedLoop)
188 reset($filelist);
189 foreach($filelist as $file)
190 //while (($file = readdir($handle)) !== false)
192 //nt_common_add_debug("checking : ". $file);
193 if (ereg($my_ereg, $file, $params))
195 nt_common_add_debug("ok".$file);
196 //nt_common_add_debug($params);
197 $tmp = array( 'rd_file' => $params[0],
198 'service' => $params[1],
199 'shard' => $params[3],
200 'variable' => $params[5]);
202 $data[$params[5]][] = $tmp;
204 elseif (ereg($my_ereg2, $file, $params))
206 nt_common_add_debug("ok2".$file);
207 $tmp = array( 'rd_file' => $params[0],
208 'service' => $params[1],
209 'shard' => 'open',
210 'variable' => $params[4]);
212 $data[$params[4]][] = $tmp;
219 nt_common_add_debug(array(array_keys($data), $data));
221 return array('variables' => array_keys($data), 'datas' => $data);
226 function tool_graphs_get_list($dir, $shard_match)
228 $data = array();
230 if (substr($dir, -1) != '/') $dir .= '/';
232 if (is_dir($dir))
234 if ($handle = opendir($dir))
236 //fes_arispotle_01.NetSpeedLoop.hrd
237 //egs_arispotle.TickSpeedLoop.hrd
238 $my_ereg = "^([^_]+_(". $shard_match .")(_[^\ \.])?)\.([^\ ]+)\.([hr])rd$";
239 $my_ereg = "^([^_]+_(". $shard_match .")(_[^\ \.])?)\.([^\ ]+)\.rrd$";
240 $my_ereg = "^([^_]+(_[^_]+)?_(". $shard_match .")(_[^\ \.])?)\.([^.]+)\.rrd$";
241 //nt_common_add_debug($my_ereg);
243 // 0: complete file name
244 // 1: service alias (eg. fes_arispotle_01)
245 // 2: n/a
246 // 3: shard (eg. arispotle)
247 // 4: n/a
248 // 5: variable (eg. NetSpeedLoop)
249 // 6: graph type, h/r : high/low (removed)
251 while (($file = readdir($handle)) !== false)
253 if (($file != '.') && ($file != '..'))
255 //nt_common_add_debug("checking : ". $file);
256 if (ereg($my_ereg, $file, $params))
258 $high_file = str_replace('.rrd','.hrd',$file);
259 if (!file_exists($dir . $high_file)) $high_file = '';
261 //nt_common_add_debug($params);
262 $tmp = array( 'low_file' => $params[0],
263 'high_file' => $high_file,
264 'service' => $params[1],
265 'shard' => $params[3],
266 'variable' => $params[5]);
268 $data[$params[5]][] = $tmp;
273 closedir($handle);
277 nt_common_add_debug(array(array_keys($data), $data));
279 return array('variables' => array_keys($data), 'datas' => $data);
282 function tool_graphs_get_data($data, $variable, $service)
284 reset($data);
285 foreach($data as $svar => $sdata)
287 if ($svar == $variable)
289 reset($sdata);
290 foreach($sdata as $sidata)
292 if ($sidata['service'] == $service)
294 return $sidata;
300 return null;
303 function tool_graphs_extract_mean_values($data)
305 $result = array('ref' => array(), 'val' => array());
307 $base = null;
309 reset($data);
310 foreach($data as $sdata)
312 $tmp_data = explode(':', $sdata);
314 // get reference as t0
315 if (!$base) $base = trim($tmp_data[1]);
317 $val_data = explode(' ', $tmp_data[2]);
319 $result['ref'][] = $tmp_data[1] - $base;
320 $result['val'][] = trim($val_data[1]);
323 return $result;
326 function tool_graphs_xaxis_callback($aVal)
328 return ($aVal / 1000) .'k';
331 // ######################################################################################################################
332 // ######################################################################################################################
334 function tool_graphs_rrd_get_list($dir)
336 $dir_list = array();
338 if ($handle = opendir($dir))
340 while (false !== ($file = readdir($handle)))
342 if (($file != ".") && ($file != "..") && (substr($file, -4) == '.rrd'))
344 $dir_list[] = array('name' => $file, 'code' => base64_encode($file));
348 closedir($handle);
351 return $dir_list;
354 function tool_graphs_build_rrd($fname,$period=0)
356 $rrdperiod = '-'. $period;
357 $rrdfile = RRD_PATH . $fname;
358 $webimage = GFX_PATH . $fname .'_'. $period .'.gif';
360 $opts = array( "--start", $rrdperiod, "DEF:val=". $rrdfile .":var:AVERAGE", "LINE2:val#0000FF");
361 $ret = rrd_graph($webimage, $opts, count($opts));
363 if ( is_array($ret) )
365 return array('status' => true, 'img' => $webimage);
368 $err = rrd_error();
369 return array('status' => false, 'error' => "Error: rrd_graph() -- $err");