Skip to content

Commit c271df5

Browse files
authored
add boost graph panels - memory usage, pending records (#325)
* add boost graph panels * update
1 parent 481f201 commit c271df5

File tree

3 files changed

+148
-9
lines changed

3 files changed

+148
-9
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* issue316: Fix php error when db check skip huge db
77
* issue: Fix support for Cacti 1.3+
88
* feature: Add 24h averages for CPU and poller stats panel
9+
* feature: Add Boost graphs panels - memory usage, pending records
910

1011
--- 4.0.4 ---
1112

panellib/system.php

+140-8
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,23 @@ function register_system() {
8181
'details_func' => false,
8282
'trends_func' => false
8383
),
84+
'boost_history' => array(
85+
'name' => __('Boost History', 'intropage'),
86+
'description' => __('Information about boost process history.', 'intropage'),
87+
'class' => 'system',
88+
'level' => PANEL_SYSTEM,
89+
'refresh' => 300,
90+
'trefresh' => read_config_option('poller_interval'),
91+
'force' => true,
92+
'width' => 'quarter-panel',
93+
'priority' => 48,
94+
'alarm' => 'grey',
95+
'requires' => false,
96+
'update_func' => 'boost_history',
97+
'details_func' => false,
98+
'trends_func' => 'boost_history_trend'
99+
),
100+
84101
'extrem' => array(
85102
'name' => __('24 Hour Extremes', 'intropage'),
86103
'description' => __('Table with 24 hours of Polling Extremes (longest poller run, down hosts)', 'intropage'),
@@ -263,6 +280,122 @@ function admin_alert($panel, $user_id) {
263280
save_panel_result($panel, $user_id);
264281
}
265282

283+
284+
function boost_history_trend() {
285+
286+
$data_length = db_fetch_cell("SELECT data_length
287+
FROM INFORMATION_SCHEMA.TABLES WHERE table_schema=SCHEMA()
288+
AND (table_name LIKE 'poller_output_boost_arch_%' OR table_name LIKE 'poller_output_boost')");
289+
290+
db_execute_prepared('INSERT INTO plugin_intropage_trends
291+
(name, value, user_id)
292+
VALUES ("boost_mem_size", ?, 0)',
293+
array($data_length));
294+
295+
$boost_table_status = db_fetch_assoc("SELECT *
296+
FROM INFORMATION_SCHEMA.TABLES WHERE table_schema=SCHEMA()
297+
AND (table_name LIKE 'poller_output_boost_arch_%' OR table_name LIKE 'poller_output_boost')");
298+
299+
$pending_records = 0;
300+
$arch_records = 0;
301+
302+
if (cacti_sizeof($boost_table_status)) {
303+
foreach ($boost_table_status as $table) {
304+
if ($table['TABLE_NAME'] == 'poller_output_boost') {
305+
$pending_records += $table['TABLE_ROWS'];
306+
} else {
307+
$arch_records += $table['TABLE_ROWS'];
308+
}
309+
}
310+
}
311+
312+
db_execute_prepared('INSERT INTO plugin_intropage_trends
313+
(name, value, user_id)
314+
VALUES ("boost_pending", ?, 0)',
315+
array($pending_records));
316+
}
317+
318+
319+
function boost_history($panel, $user_id, $timespan = 0) {
320+
global $config;
321+
322+
$panel['alarm'] = 'green';
323+
324+
$graph = array (
325+
'line' => array(
326+
'title' => __('Boost history: ', 'intropage'),
327+
'label1' => array(),
328+
'data1' => array(),
329+
'label2' => array(),
330+
'data2' => array(),
331+
),
332+
);
333+
334+
if ($timespan == 0) {
335+
if (isset($_SESSION['sess_user_id'])) {
336+
$timespan = read_user_setting('intropage_timespan', read_config_option('intropage_timespan'), $_SESSION['sess_user_id']);
337+
} else {
338+
$timespan = $panel['refresh'];
339+
}
340+
}
341+
342+
if (!isset($panel['refresh_interval'])) {
343+
$refresh = db_fetch_cell_prepared('SELECT refresh_interval
344+
FROM plugin_intropage_panel_data
345+
WHERE id = ?',
346+
array($panel['id']));
347+
} else {
348+
$refresh = $panel['refresh'];
349+
}
350+
351+
$rows = db_fetch_assoc_prepared("SELECT cur_timestamp AS `date`, value
352+
FROM plugin_intropage_trends
353+
WHERE cur_timestamp > date_sub(NOW(), INTERVAL ? SECOND)
354+
AND name = 'boost_mem_size'
355+
ORDER BY cur_timestamp ASC",
356+
array($timespan));
357+
358+
if (cacti_sizeof($rows)) {
359+
$graph['line']['title1'] = __('Mem ', 'intropage');
360+
$graph['line']['unit1']['title'] = 'Used mem [KB]';
361+
362+
foreach ($rows as $row) {
363+
$graph['line']['label1'][] = $row['date'];
364+
$graph['line']['data1'][] = $row['value']/1024;
365+
}
366+
367+
$rows = db_fetch_assoc_prepared("SELECT cur_timestamp AS `date`, value
368+
FROM plugin_intropage_trends
369+
WHERE cur_timestamp > date_sub(NOW(), INTERVAL ? SECOND)
370+
AND name = 'boost_pending'
371+
ORDER BY cur_timestamp ASC",
372+
array($timespan));
373+
374+
if (cacti_sizeof($rows)) {
375+
$graph['line']['title2'] = __('Pending records ', 'intropage');
376+
$graph['line']['unit2']['title'] = 'Records';
377+
378+
foreach ($rows as $row) {
379+
$graph['line']['label2'][] = $row['date'];
380+
$graph['line']['data2'][] = $row['value'];
381+
}
382+
} else {
383+
unset($graph['line']['label2']);
384+
unset($graph['line']['data2']);
385+
unset($graph['line']['title2']);
386+
unset($graph['line']['unit2']);
387+
}
388+
389+
$panel['data'] = intropage_prepare_graph($graph, $user_id);
390+
} else {
391+
unset($graph);
392+
$panel['data'] = __('Waiting for data', 'intropage');
393+
}
394+
395+
save_panel_result($panel, $user_id);
396+
}
397+
398+
266399
//--------------------------------boost--------------------------------
267400
function boost($panel, $user_id) {
268401
global $config, $boost_refresh_interval, $boost_max_runtime;
@@ -290,6 +423,7 @@ function boost($panel, $user_id) {
290423
$data_length = 0;
291424
$engine = '';
292425
$max_data_length = 0;
426+
$total_records = 0;
293427

294428
if (cacti_sizeof($boost_table_status)) {
295429
foreach ($boost_table_status as $table) {
@@ -369,14 +503,12 @@ function boost($panel, $user_id) {
369503

370504
$panel['data'] .= '<tr><td>' . __('Approximate Next Start Time: %s', $next_run_time, 'intropage') . '</td></tr>';
371505

372-
if ($total_records) {
373-
$panel['data'] .= '<tr><td>' . __('Pending/Archived Records: %s / %s', number_format_i18n($pending_records, -1), number_format_i18n($arch_records, -1), 'intropage') . '</td></tr>';
506+
$panel['data'] .= '<tr><td>' . __('Pending/Archived Records: %s / %s', number_format_i18n($pending_records, -1), number_format_i18n($arch_records, -1), 'intropage') . '</td></tr>';
374507

375-
if ($total_records > ($max_records - ($max_records / 10)) && $panel['alarm'] == 'green') {
376-
$panel['alarm'] = 'yellow';
377-
} elseif ($total_records > ($max_records - ($max_records / 20)) && $panel['alarm'] == 'green') {
378-
$panel['alarm'] = 'red';
379-
}
508+
if ($total_records > ($max_records - ($max_records / 10)) && $panel['alarm'] == 'green') {
509+
$panel['alarm'] = 'yellow';
510+
} elseif ($total_records > ($max_records - ($max_records / 20)) && $panel['alarm'] == 'green') {
511+
$panel['alarm'] = 'red';
380512
}
381513

382514
$data_length = db_fetch_cell("SELECT data_length
@@ -444,7 +576,7 @@ function extrem_trend() {
444576
//------------------------------------ extrem -----------------------------------------------------
445577
function extrem($panel, $user_id) {
446578
global $config;
447-
579+
448580
$lines = read_user_setting('intropage_number_of_lines', read_config_option('intropage_number_of_lines'), false, $user_id);
449581
$poller_interval = read_config_option('poller_interval');
450582

poller_intropage.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,13 @@ function intropage_gather_stats() {
257257

258258
db_execute("DELETE FROM plugin_intropage_trends
259259
WHERE cur_timestamp < date_sub(now(), INTERVAL 2 DAY) AND
260-
name IN ('poller','cpuload','failed_polls','thold_trig','thold_brea','thold_disa','host_down','host_reco','host_disa','poller_output','syslog_incoming','syslog_total','syslog_alert','dsstats_all','dsstats_null')");
260+
name IN (
261+
'poller', 'cpuload', 'failed_polls', 'thold_trig', 'thold_brea', 'thold_disa',
262+
'host_down', 'host_reco', 'host_disa',
263+
'poller_output',
264+
'syslog_incoming', 'syslog_total', 'syslog_alert', 'syslog_levels',
265+
'dsstats_all', 'dsstats_null', 'boost_mem_size', 'boost_pending'
266+
)");
261267

262268
// automatic autorefresh
263269
intropage_debug('Checking Triggered Thresholds');

0 commit comments

Comments
 (0)