Skip to content

Commit

Permalink
Fixing #5824: Properly cache data source type info
Browse files Browse the repository at this point in the history
* Properly cache the data source information for dsstats processing
  • Loading branch information
TheWitness committed Sep 15, 2024
1 parent f6b43ee commit 2aef389
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Cacti CHANGELOG
-issue#5802: Cacti should not convert non-base tables as they may have an focused characters set and engine
-issue#5806: Issues with Cacti posix_kill wrapper in Windows
-issue#5813: Can't change password when first installing
-issue#5824: Properly cache the data source information for dsstats processing
-feature#5784: Provide a means by which a user can track Cacti connections and disconnects from the php error_log
-feature#5796: Due to Conflicting Interpretations of TCP Ping, Introduce new Ping Method
-feature#5819: Be more precise on the Graph End time when an end time is not provided
Expand Down
2 changes: 1 addition & 1 deletion lib/dsdebug.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function dsdebug_error_handler($errno, $errmsg, $filename, $linenum, $vars = [])
}

function dsdebug_poller_output(&$rrd_update_array) {
global $config, $ds_types, $ds_last, $ds_steps, $ds_multi;
global $config;

/* suppress warnings */
if (defined('E_DEPRECATED')) {
Expand Down
48 changes: 27 additions & 21 deletions lib/dsstats.php
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ function dsstats_error_handler($errno, $errmsg, $filename, $linenum, $vars = [])
/**
* dsstats_poller_output - this routine runs in parallel with the cacti poller and
* populates the last and cache tables. On larger systems, it should be noted that
* the memory overhead for the global arrays, $ds_types, $ds_last, $ds_steps, $ds_multi
* the memory overhead for the global arrays, $ds_types, $ds_last, $ds_multi
* could be serval hundred megabytes. So, this should be kept in mind when running the
* sizing your system.
*
Expand All @@ -635,7 +635,6 @@ function dsstats_error_handler($errno, $errmsg, $filename, $linenum, $vars = [])
* $ds_types - The type of data source, keyed by the local_data_id and the rrd_name stored inside
* of the RRDfile.
* $ds_last - For the COUNTER, and DERIVE DS types, the last measured and stored value.
* $ds_steps - Records the poller interval for every Data Source so that rates can be stored.
* $ds_multi - For Multi Part responses, stores the mapping of the Data Input Fields to the
* Internal RRDfile DS names.
*
Expand All @@ -653,7 +652,10 @@ function dsstats_error_handler($errno, $errmsg, $filename, $linenum, $vars = [])
* @return - NULL
*/
function dsstats_poller_output(&$rrd_update_array) {
global $config, $ds_types, $ds_last, $ds_steps, $ds_multi;
global $config;

static $ds_types = array();
static $ds_multi = array();

/* suppress warnings */
if (defined('E_DEPRECATED')) {
Expand Down Expand Up @@ -681,28 +683,32 @@ function dsstats_poller_output(&$rrd_update_array) {
$overhead_last = strlen($sql_last_prefix) + strlen($sql_last_suffix);

/* determine the keyvalue pairs to decide on how to store data */
$ds_types = array_rekey(
db_fetch_assoc('SELECT DISTINCT data_source_name, data_source_type_id, rrd_step, rrd_maximum
FROM data_template_rrd AS dtr
INNER JOIN data_template_data AS dtd
ON dtd.local_data_id = dtr.local_data_id
WHERE dtd.local_data_id > 0'),
'data_source_name', array('data_source_type_id', 'rrd_step', 'rrd_maximum')
);
if (!cacti_sizeof($ds_types)) {
$ds_types = array_rekey(
db_fetch_assoc('SELECT DISTINCT data_source_name, data_source_type_id, rrd_step, rrd_maximum
FROM data_template_rrd AS dtr
INNER JOIN data_template_data AS dtd
ON dtd.local_data_id = dtr.local_data_id
WHERE dtd.local_data_id > 0'),
'data_source_name', array('data_source_type_id', 'rrd_step', 'rrd_maximum')
);
}

/* make the association between the multi-part name value pairs and the RRDfile internal
* data source names.
*/
$ds_multi = array_rekey(
db_fetch_assoc('SELECT DISTINCT data_name, data_source_name
FROM graph_templates_item AS gti
INNER JOIN data_template_rrd AS dtr
ON gti.task_item_id = dtr.id
INNER JOIN data_input_fields AS dif
ON dif.id = dtr.data_input_field_id
WHERE dtr.data_input_field_id != 0'),
'data_name', 'data_source_name'
);
if (!cacti_sizeof($ds_multi)) {
$ds_multi = array_rekey(
db_fetch_assoc('SELECT DISTINCT data_name, data_source_name
FROM graph_templates_item AS gti
INNER JOIN data_template_rrd AS dtr
ON gti.task_item_id = dtr.id
INNER JOIN data_input_fields AS dif
ON dif.id = dtr.data_input_field_id
WHERE dtr.data_input_field_id != 0'),
'data_name', 'data_source_name'
);
}

/* required for updating tables */
$cache_i = 1;
Expand Down

0 comments on commit 2aef389

Please sign in to comment.