Skip to content

Commit

Permalink
First attempt to remediate #5279
Browse files Browse the repository at this point in the history
Rebuild poller cache does not work as expected.

This change modifies the output during runtime and separates each poller_id into larger loops.
  • Loading branch information
TheWitness committed Apr 1, 2023
1 parent 7e27e03 commit a1d8a82
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -9,6 +9,7 @@ Cacti CHANGELOG
-issue#5272: Boost continues to loose data when archive tables are missed due to overloaded MariaDB
-issue#5275: Boost stats can display odd values when running
-issue#5277: Boost should not attempt to start if there are no poller_output_boost records
-issue#5279: Rebuild poller cache does not work as expected
-issue#5282: Script ss_host_cpu.php does not work as expected when on a remote data collector with hmib enabled
-issue#5283: Trying to access array offset on value of type null in file lib/functions.php on line: 2276
-feature: Upgrade billboard.js to version 3.7.4
Expand Down
83 changes: 51 additions & 32 deletions cli/rebuild_poller_cache.php
Expand Up @@ -109,41 +109,60 @@
$params[] = $host_template_id;
}

/* get the data_local Id's for the poller cache */
$poller_data = db_fetch_assoc_prepared("SELECT dl.*
FROM data_local AS dl
INNER JOIN host AS h
ON dl.host_id = h.id
$sql_where",
$params);

/* initialize some variables */
$current_ds = 1;
$total_ds = cacti_sizeof($poller_data);

/* setting local_data_ids to an empty array saves time during updates */
$local_data_ids = array();
$poller_items = array();

/* issue warnings and start message if applicable */
print 'WARNING: Do not interrupt this script. Rebuilding the Poller Cache can take quite some time' . PHP_EOL;
debug("There are '" . cacti_sizeof($poller_data) . "' data source elements to update.");

/* start rebuilding the poller cache */
if (cacti_sizeof($poller_data)) {
foreach ($poller_data as $data) {
if (!$debug) print '.';
$local_data_ids[] = $data['id'];
$poller_items = array_merge($poller_items, update_poller_cache($data));

debug("Data Source Item '$current_ds' of '$total_ds' updated");
$current_ds++;
}
$pollers = array_rekey(
db_fetch_assoc('SELECT DISTINCT poller_id
FROM host
WHERE disabled = ""'),
'poller_id', 'poller_id'
);

if (cacti_sizeof($pollers)) {
print 'NOTE: Do not interrupt this script. Rebuilding the Poller Cache can take quite some time' . PHP_EOL;

foreach($pollers as $poller_id) {
/* get the data_local Id's for the poller cache */
$poller_data = db_fetch_assoc_prepared("SELECT dl.*, h.description
FROM data_local AS dl
INNER JOIN host AS h
ON dl.host_id = h.id
$sql_where
AND poller_id = $poller_id
ORDER BY dl.host_id",
$params);

/* initialize some variables */
$current_ds = 1;
$current_host = -1;
$total_ds = cacti_sizeof($poller_data);

/* setting local_data_ids to an empty array saves time during updates */
$local_data_ids = array();
$poller_items = array();

/* issue warnings and start message if applicable */
debug("There are '" . cacti_sizeof($poller_data) . "' data source elements to update for poller id number $poller_id.");

/* start rebuilding the poller cache */
if (cacti_sizeof($poller_data)) {
foreach ($poller_data as $data) {
if ($data['host_id'] != $current_host) {
print "NOTE: Processing Device:'{$data['description']}' with Poller:'$poller_id'" . PHP_EOL;
}

$local_data_ids[] = $data['id'];
$poller_items = array_merge($poller_items, update_poller_cache($data));

if (cacti_sizeof($local_data_ids)) {
poller_update_poller_cache_from_buffer($local_data_ids, $poller_items);
$current_ds++;
$current_host = $data['host_id'];
}

if (cacti_sizeof($local_data_ids)) {
poller_update_poller_cache_from_buffer($local_data_ids, $poller_items, $poller_id);
}
}
}
}

if (!$debug) {
print PHP_EOL;
}
Expand Down

0 comments on commit a1d8a82

Please sign in to comment.