3 require_once('common.php');
4 require_once('functions_tool_main.php');
5 require_once('functions_tool_graphs.php');
7 require_once("jpgraph/jpgraph.php");
8 require_once("jpgraph/jpgraph_line.php");
9 require_once("jpgraph/jpgraph_log.php");
12 if (!tool_admin_applications_check('tool_graph')) nt_common_redirect('index.php');
14 nt_common_add_debug('-- Starting on \'tool_graphs.php\'');
16 if (!isset($NELTOOL['GET_VARS']['toolmode']))
18 $NELTOOL['GET_VARS']['toolmode'] = 'ccu';
19 nt_auth_unset_session_var('view_shard_id');
20 nt_auth_unset_session_var('view_time_highframe');
21 nt_auth_unset_session_var('view_time_lowframe');
24 $tool_menu_item = tool_graphs_menu_get_item_from_key($NELTOOL['GET_VARS']['toolmode']);
25 $tpl->assign('toolmode', $NELTOOL['GET_VARS']['toolmode']);
27 $tpl->assign('tool_title', 'Graphs / '. $tool_menu_item['title']);
28 $tpl->assign('tool_menu', tool_graphs_menu_get_list());
30 $view_domain_id = nt_auth_get_session_var('view_domain_id');
31 $view_shard_id = nt_auth_get_session_var('view_shard_id');
32 $view_time_highframe = nt_auth_get_session_var('view_time_highframe');
33 $view_time_lowframe = nt_auth_get_session_var('view_time_lowframe');
37 $view_domain_id = $nel_user['group_default_domain_id'];
38 $view_shard_id = $nel_user['group_default_shard_id'];
39 nt_auth_set_session_var('view_domain_id', $view_domain_id);
40 nt_auth_set_session_var('view_shard_id', $view_shard_id);
43 if (isset($NELTOOL['GET_VARS']['domain']))
45 if ($view_domain_id != $NELTOOL['GET_VARS']['domain'])
47 $view_domain_id = $NELTOOL['GET_VARS']['domain'];
48 nt_auth_set_session_var('view_domain_id', $view_domain_id);
50 $view_shard_id = null;
51 nt_auth_unset_session_var('view_shard_id');
55 if (isset($NELTOOL['GET_VARS']['shard']))
57 $view_shard_id = $NELTOOL['GET_VARS']['shard'];
58 nt_auth_set_session_var('view_shard_id', $view_shard_id);
61 if (isset($NELTOOL['GET_VARS']['highframe']))
63 $view_time_highframe = $NELTOOL['GET_VARS']['highframe'];
64 nt_auth_set_session_var('view_time_highframe', $view_time_highframe);
67 if (isset($NELTOOL['GET_VARS']['lowframe']))
69 $view_time_lowframe = $NELTOOL['GET_VARS']['lowframe'];
70 nt_auth_set_session_var('view_time_lowframe', $view_time_lowframe);
73 if ($view_time_highframe == null)
75 $view_time_highframe = tool_graphs_time_frame_get_default($tool_hires_frames);
78 if ($view_time_lowframe == null)
80 $view_time_lowframe = tool_graphs_time_frame_get_default($tool_lowres_frames);
84 $current_refresh_rate = nt_auth_get_session_var('current_refresh_rate');
85 if (isset($_POST['services_refresh']))
87 if ($current_refresh_rate != $_POST['services_refresh'])
89 $current_refresh_rate = $_POST['services_refresh'];
90 nt_auth_set_session_var('current_refresh_rate',$current_refresh_rate);
94 if ($current_refresh_rate == null)
96 $current_refresh_rate = 0;
98 elseif ($current_refresh_rate > 0)
100 $tpl->assign('nel_tool_refresh', '<meta http-equiv=refresh content="'. $current_refresh_rate .'">');
103 $tpl->assign('tool_refresh_list', $refresh_rates);
104 $tpl->assign('tool_refresh_rate', $current_refresh_rate);
106 $tpl->assign('tool_domain_list', $nel_user['access']['domains']);
107 $tpl->assign('tool_domain_selected', $view_domain_id);
109 $tpl->assign('tool_shard_list', $nel_user['access']['shards']);
110 $tpl->assign('tool_shard_selected', $view_shard_id);
112 $tool_shard_filters = tool_main_get_shard_ids($view_shard_id);
113 $tpl->assign('tool_shard_filters', $tool_shard_filters);
117 $tool_as_error = null;
119 $AS_Name = tool_main_get_domain_name($view_domain_id);
120 $AS_Host = tool_main_get_domain_host($view_domain_id);
121 $AS_Port = tool_main_get_domain_port($view_domain_id);
122 $AS_ShardName = tool_main_get_shard_name($view_shard_id);
123 $AS_InternalName = tool_main_get_shard_as_id($view_shard_id);
124 $AS_RRDPath = tool_main_get_domain_rrd_path($view_domain_id);
127 if ($AS_RRDPath != "")
129 // lets make sure there is a trailing /
130 if (substr($AS_RRDPath, -1) != '/') $AS_RRDPath .= '/';
132 $tpl->assign('tool_page_title', 'Graphs - '. $AS_Name . ($AS_ShardName != '' ?
' / '. $AS_ShardName : ''));
134 switch($NELTOOL['GET_VARS']['toolmode'])
138 * ###################################################################################################
140 * ###################################################################################################
143 $tpl->assign('tool_frame_list', $tool_lowres_frames);
144 $tpl->assign('tool_frame_selected', $view_time_lowframe);
146 if ($view_time_lowframe)
148 $graph_data_tmp = tool_graphs_get_list_v2($AS_RRDPath, strtolower($AS_InternalName), false, true);
150 $tool_tech_graph_list = array( array('service' => 'su', 'variable' => 'TotalConcurentUser'),
151 array('service' => 'egs', 'variable' => 'NbPlayers'),
154 $graph_list = tool_graphs_find($tool_tech_graph_list, $graph_data_tmp['datas']);
155 nt_common_add_debug($graph_list);
159 foreach($graph_list as $graph_item)
161 $rrd_path = $AS_RRDPath . $graph_item['rd_file'];
162 $rrd_def = "DEF:val=". $rrd_path .":var:AVERAGE";
163 $rrd_draw = "LINE2:val#0000FF --no-legend";
164 $rrd_output = NELTOOL_RRDSYSBASE
. $graph_item['rd_file'] ."-". $view_time_lowframe .".gif";
165 $rrd_web = NELTOOL_RRDWEBBASE
. $graph_item['rd_file'] ."-". $view_time_lowframe .".gif";
166 $rrd_exec = NELTOOL_RRDTOOL
." graph ". $rrd_output ." --width 916 --height 110 --start -". $view_time_lowframe ." ". $rrd_def ." ". $rrd_draw;
168 nt_common_add_debug($rrd_exec);
169 exec($rrd_exec, $rrd_result, $rrd_code);
171 $file_description = str_replace(array('.rrd','.hrd','.'),
172 array('', '', ' - '),
173 $graph_item['rd_file']);
176 tool_main_get_elapsed_time_string($view_time_lowframe, $time_string);
178 $rrd_webs[] = array('desc' => $file_description .' over '. $time_string,
183 $tpl->assign('tool_rrd_output', $rrd_webs);
189 * ###################################################################################################
190 * Tech Shard Pages (Low Res)
191 // ts_mainland01.TotalSpeedLoop.rrd
192 // egs_mainland01.NbPlayers.rrd
193 // egs_mainland01.ProcessUsedMemory.rrd
194 // egs_mainland01.TickSpeedLoop.rrd
195 * ###################################################################################################
198 $tpl->assign('tool_frame_list', $tool_lowres_frames);
199 $tpl->assign('tool_frame_selected', $view_time_lowframe);
201 if ($view_shard_id && $view_time_lowframe)
203 $graph_data_tmp = tool_graphs_get_list_v2($AS_RRDPath, strtolower($AS_InternalName), false);
205 $tool_tech_graph_list = array( array('service' => 'ts', 'variable' => 'TotalSpeedLoop'),
206 array('service' => 'egs', 'variable' => 'NbPlayers'),
207 array('service' => 'egs', 'variable' => 'ProcessUsedMemory'),
208 array('service' => 'egs', 'variable' => 'TickSpeedLoop'),
211 $graph_list = tool_graphs_find($tool_tech_graph_list, $graph_data_tmp['datas']);
212 nt_common_add_debug($graph_list);
216 foreach($graph_list as $graph_item)
218 $rrd_path = $AS_RRDPath . $graph_item['rd_file'];
219 $rrd_def = "DEF:val=". $rrd_path .":var:AVERAGE";
220 $rrd_draw = "LINE2:val#0000FF --no-legend";
221 $rrd_output = NELTOOL_RRDSYSBASE
. $graph_item['rd_file'] ."-". $view_time_lowframe .".gif";
222 $rrd_web = NELTOOL_RRDWEBBASE
. $graph_item['rd_file'] ."-". $view_time_lowframe .".gif";
223 $rrd_exec = NELTOOL_RRDTOOL
." graph ". $rrd_output ." --width 916 --height 110 --start -". $view_time_lowframe ." ". $rrd_def ." ". $rrd_draw;
225 nt_common_add_debug($rrd_exec);
226 exec($rrd_exec, $rrd_result, $rrd_code);
228 $file_description = str_replace(array('.rrd','.hrd','.'),
229 array('', '', ' - '),
230 $graph_item['rd_file']);
233 tool_main_get_elapsed_time_string($view_time_lowframe, $time_string);
235 $rrd_webs[] = array('desc' => $file_description .' over '. $time_string,
240 $tpl->assign('tool_rrd_output', $rrd_webs);
246 * ###################################################################################################
248 // ts_mainland01.TotalSpeedLoop.hrd
249 // egs_mainland01.TickSpeedLoop.hrd
250 // ais_fyros_mainland01.ProcessUsedMemory.hrd
251 // ais_matis_mainland01.ProcessUsedMemory.hrd
252 // ais_zorai_mainland01.ProcessUsedMemory.hrd
253 // ais_tryker_mainland01.ProcessUsedMemory.hrd
254 // ais_pr_mainland01.ProcessUsedMemory.hrd
255 // ais_newbyland_mainland01.ProcessUsedMemory.hrd
256 // gpms_mainland01.ProcessUsedMemory.hrd
257 // fes_mainland01.ProcessUsedMemory.hrd
258 * ###################################################################################################
261 $tpl->assign('tool_frame_list', $tool_hires_frames);
262 $tpl->assign('tool_frame_selected', $view_time_highframe);
264 if ($view_shard_id && $view_time_highframe)
266 $graph_data_tmp = tool_graphs_get_list_v2($AS_RRDPath, strtolower($AS_InternalName), true);
268 $tool_tech_graph_list = array( array('service' => 'ts', 'variable' => 'TotalSpeedLoop'),
269 array('service' => 'egs', 'variable' => 'TickSpeedLoop'),
270 array('service' => 'ais', 'variable' => 'TickSpeedLoop'),
271 array('service' => 'gpms', 'variable' => 'TickSpeedLoop'),
272 array('service' => 'fes', 'variable' => 'TickSpeedLoop'),
275 $graph_list = tool_graphs_find($tool_tech_graph_list, $graph_data_tmp['datas']);
276 nt_common_add_debug($graph_list);
278 $adminService = new MyAdminService
;
279 if (@$adminService->connect($AS_Host, $AS_Port, $res) === false)
281 nt_common_add_debug($res);
282 $tpl->assign('tool_domain_error', $res );
290 foreach($graph_list as $graph_item)
292 nt_common_add_debug(" getHighRezGraph : ". $graph_item['service'] .".". $graph_item['variable'] ." , ". ($now - ($view_time_highframe / 1000)) ." , ". $now ." , 0");
293 $tmp = $adminService->getHighRezGraph($graph_item['service'] .'.'. $graph_item['variable'], $now - ($view_time_highframe / 1000), $now, 0);
295 //nt_common_add_debug($tmp);
297 $mean_values = tool_graphs_extract_mean_values($tmp);
298 //nt_common_add_debug($mean_values);
300 if (sizeof($mean_values['val']))
302 $graph = new Graph(1000,150);
303 $graph->SetMargin(35,10,5,25); // left - right - top - bottom
304 $graph->SetScale("intlin");
305 $graph->xgrid
->Show(true,true);
306 $graph->ygrid
->Show(true,true);
307 $graph->xaxis
->SetLabelFormatCallback('tool_graphs_xaxis_callback');
309 $line = new LinePlot($mean_values['val'], $mean_values['ref']);
310 $line->SetColor('blue');
311 $line->SetFillColor('lightblue');
314 $high_sys_name = NELTOOL_RRDSYSBASE
. $graph_item['rd_file'] ."-". $view_time_highframe .'_0.png';
315 $high_web_name = NELTOOL_RRDWEBBASE
. $graph_item['rd_file'] ."-". $view_time_highframe .'_0.png';
317 $graph->Stroke($high_sys_name);
319 $file_description = str_replace(array('.rrd','.hrd','.'),
320 array('', '', ' - '),
321 $graph_item['rd_file']);
324 tool_main_get_elapsed_time_string($view_time_highframe / 1000, $time_string);
326 $rrd_webs[] = array('desc' => $file_description .' over '. $time_string .' - ('. sizeof($mean_values['val']) .' values)',
327 'img' => $high_web_name);
331 $rrd_webs[] = array('desc' => 'Not enough values to render plot for '. $graph_item['rd_file'] .' over '. ($view_time_highframe / 1000) .'s.',
338 $tpl->assign('tool_rrd_high_output', $rrd_webs);
345 * ###################################################################################################
347 * ###################################################################################################
350 $tool_as_error = null;
352 if ($AS_Host && $AS_Port)
354 $graph_data_tmp = tool_graphs_get_list($AS_RRDPath, strtolower($AS_InternalName));
355 $graph_variables = $graph_data_tmp['variables'];
356 $graph_datas = $graph_data_tmp['datas'];
358 if (sizeof($graph_datas))
360 $tpl->assign('tool_graph_list', true);
361 $tpl->assign('tool_graph_variables', $graph_variables);
362 $tpl->assign('tool_graph_datas', $graph_datas);
364 $tool_variable_selected = $_GET['variable'];
365 $tool_service_selected = $_GET['service'];
367 $tpl->assign('tool_graph_variable_selected', $tool_variable_selected);
368 $tpl->assign('tool_graph_service_selected', $tool_service_selected);
370 $tool_selected_variable_data = tool_graphs_get_data($graph_datas, $tool_variable_selected, $tool_service_selected);
372 if ($tool_selected_variable_data['low_file'] != '')
374 $rrd_values = array(1200, 10800, 86400, 604800, 2592000, 7776000); // 20mins, 3h, 24h, 7days, 30 days, 90 days (unit is 1 second)
375 $rrd_path = $AS_RRDPath . $tool_selected_variable_data['low_file'];
376 $rrd_def = "DEF:val=". $rrd_path .":var:AVERAGE";
377 $rrd_draw = "LINE2:val#0000FF";
382 foreach($rrd_values as $rrd_value)
384 $rrd_output = NELTOOL_RRDSYSBASE
. $tool_selected_variable_data['low_file'] ."-". $rrd_value .".gif";
385 $rrd_web = NELTOOL_RRDWEBBASE
. $tool_selected_variable_data['low_file'] ."-". $rrd_value .".gif";
386 $rrd_exec = NELTOOL_RRDTOOL
." graph ". $rrd_output ." --start -". $rrd_value ." ". $rrd_def ." ". $rrd_draw;
387 nt_common_add_debug($rrd_exec);
388 exec($rrd_exec, $rrd_result, $rrd_code);
389 $rrd_webs[] = array('desc' => $tool_selected_variable_data['low_file'] .' over '. $rrd_value .'s.',
393 $tpl->assign('tool_rrd_output', $rrd_webs);
396 if ($tool_selected_variable_data['high_file'] != '')
399 $rrd_values = array(array(10000,10), array(30000,10), array(90000,10)); // 10s, 30s, 90s (unit is 1 ms)
401 $adminService = new MyAdminService
;
402 if (@$adminService->connect($AS_Host, $AS_Port, $res) === false)
404 nt_common_add_debug($res);
405 $tpl->assign('tool_domain_error', $res );
413 foreach($rrd_values as $rrd_value)
415 nt_common_add_debug(" getHighRezGraph : ". $tool_selected_variable_data['service'] .".". $tool_selected_variable_data['variable'] ." , ". ($now - ($rrd_value[0] / 1000)) ." , ". $now ." , ". $rrd_value[1]);
416 $tmp = $adminService->getHighRezGraph($tool_selected_variable_data['service'] .'.'. $tool_selected_variable_data['variable'], $now - ($rrd_value[0] / 1000), $now, $rrd_value[1]);
418 //nt_common_add_debug(" getHighRezGraph : ". $tool_selected_variable_data['service'] .".". $tool_selected_variable_data['variable'] ." , ". ($rrd_value[0] / 1000) ." , 0 , 0");
419 //$tmp = $adminService->getHighRezGraph($tool_selected_variable_data['service'] .'.'. $tool_selected_variable_data['variable'], ($rrd_value[0] / 1000), 0, 0);
421 nt_common_add_debug($tmp);
423 $mean_values = tool_graphs_extract_mean_values($tmp);
424 nt_common_add_debug($mean_values);
426 if (sizeof($mean_values['val']))
428 $graph = new Graph(480,160);
429 $graph->SetMargin(35,10,5,25); // left - right - top - bottom
431 // Now specify the X-scale explicit but let the Y-scale be auto-scaled
432 //$graph->SetScale("intlin",0,0,$adjstart,$adjend);
433 $graph->SetScale("intlin");
436 $graph->xgrid
->Show(true,true);
437 $graph->ygrid
->Show(true,true);
438 //$graph->SetGridDepth(DEPTH_FRONT);
440 // Setup the callback and adjust the angle of the labels
441 $graph->xaxis
->SetLabelFormatCallback('tool_graphs_xaxis_callback');
442 //$graph->xaxis->title->Set("ms.");
443 //$graph->xaxis->SetLabelAngle(90);
445 // Set the labels every 5min (i.e. 300seconds) and minor ticks every minute
446 //$graph->xaxis->scale->ticks->Set(1000);
447 //$graph->yscale->SetAutoTicks();
449 $line = new LinePlot($mean_values['val'], $mean_values['ref']);
450 $line->SetColor('blue');
451 $line->SetFillColor('lightblue');
454 $high_sys_name = NELTOOL_RRDSYSBASE
. $tool_selected_variable_data['high_file'] ."-". $rrd_value[0] .'_'. $rrd_value[1] .".png";
455 $high_web_name = NELTOOL_RRDWEBBASE
. $tool_selected_variable_data['high_file'] ."-". $rrd_value[0] .'_'. $rrd_value[1] .".png";
457 $graph->Stroke($high_sys_name);
459 $rrd_webs[] = array('desc' => $tool_selected_variable_data['high_file'] .' over '. ($rrd_value[0] / 1000) .'s. ('. sizeof($mean_values['val']) .' values)',
460 'img' => $high_web_name);
464 $rrd_webs[] = array('desc' => 'Not enough values to render plot for '. $tool_selected_variable_data['high_file'] .' over '. ($rrd_value[0] / 1000) .'s.',
469 $tpl->assign('tool_rrd_high_output', $rrd_webs);
482 $tpl->assign('tool_domain_error', "This domain has not been configured to handle graphs!");
489 $tpl->display($tool_menu_item['tpl']);