Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/frontends/php/api/classes/managers/CHistoryManager.php b/frontends/php/api/classes/managers/CHistoryManager.php
- index 84a8952..a5c5788 100644
- --- a/frontends/php/api/classes/managers/CHistoryManager.php
- +++ b/frontends/php/api/classes/managers/CHistoryManager.php
- @@ -35,14 +35,27 @@ class CHistoryManager {
- public function getLast(array $items, $limit = 1) {
- $queries = array();
- foreach ($items as $item) {
- - $table = self::getTableName($item['value_type']);
- - $queries[$table][] = DBaddLimit(
- - 'SELECT *'.
- - ' FROM '.$table.' h'.
- - ' WHERE h.itemid='.zbx_dbstr($item['itemid']).
- - ' ORDER BY h.clock DESC',
- - $limit
- - );
- + $table = self::getTableNameForPartitioning($item['value_type']);
- +
- + if (isset($item['delay'])) {
- + $period = time() - ( $item['delay'] * LATEST_DATA_MULTIPLIER );
- + $queries[$table][] = DBaddLimit(
- + 'SELECT *'.
- + ' FROM '.$table.' h'.
- + ' WHERE h.itemid='.zbx_dbstr($item['itemid']).
- + ' AND h.clock > '.$period.
- + ' ORDER BY h.clock DESC',
- + $limit
- + );
- + } else {
- + $queries[$table][] = DBaddLimit(
- + 'SELECT *'.
- + ' FROM '.$table.' h'.
- + ' WHERE h.itemid='.zbx_dbstr($item['itemid']).
- + ' ORDER BY h.clock DESC',
- + $limit
- + );
- + }
- }
- $rs = array();
- @@ -75,4 +88,33 @@ class CHistoryManager {
- return $tables[$valueType];
- }
- + /**
- + * Return the name of the partitioned table where the data for the given value type is stored.
- + *
- + * @param int $valueType
- + *
- + * @return string
- + */
- + private static function getTableNameForPartitioning($valueType) {
- + // Is this table define in partitioned tables?
- + if (strripos( PARTITION_TABLES_DAILY, '"'.self::getTableName($valueType).'"' )) {
- + // Is partitions schema and partition dateformat defined?
- + if (PARTITION_DATEFORMAT > "" and PARTITION_SCHEMA > "") {
- +
- + // If tables parted with unix timestamp (first second for each day)
- + if (PARTITION_DATEFORMAT == 'U') {
- + $nowdt= mktime( 0,0,0,date( "m",time() ),date( "d",time() ),date("y",time() ) );
- + return PARTITION_SCHEMA.'.'.self::getTableName($valueType).PARTITION_DATE_PREFIX.date(PARTITION_DATEFORMAT, $nowdt);
- +
- + // For partitioning by current date (current day, current month, etc.)
- + } else {
- + return $table_part = PARTITION_SCHEMA.'.'.self::getTableName($valueType).PARTITION_DATE_PREFIX.date(PARTITION_DATEFORMAT);
- + }
- + }
- + }
- +
- + // Default: return normal table name
- + return self::getTableName($valueType);
- + }
- +
- }
- diff --git a/frontends/php/include/defines.inc.php b/frontends/php/include/defines.inc.php
- index 3d851a7..78569ef 100644
- --- a/frontends/php/include/defines.inc.php
- +++ b/frontends/php/include/defines.inc.php
- @@ -991,3 +991,14 @@ ini_set('precision', 14);
- if (function_exists('bcscale')) {
- bcscale(7);
- }
- +
- +// partitions.history_uint_p2013_01_02
- +// | | | \ PARTITION_DATEFORMAT
- +// | | \ PARTITION_DATE_PREFIX
- +// | \ normal table name
- +// \ PARTITION_SCHEMA
- +define('PARTITION_SCHEMA', 'partitions');
- +define('PARTITION_TABLES_DAILY', '"history" "history_log" "history_str" "history_text" "history_uint"');
- +define('PARTITION_DATE_PREFIX', '_p');
- +define('PARTITION_DATEFORMAT', 'Y_m_d');
- +define('LATEST_DATA_MULTIPLIER', 3);
- diff --git a/frontends/php/latest.php b/frontends/php/latest.php
- index ec2f68b..5f5565e 100644
- --- a/frontends/php/latest.php
- +++ b/frontends/php/latest.php
- @@ -258,7 +258,7 @@ CArrayHelper::sort($applications, $sortFields);
- // fetch items and data
- $allItems = DBfetchArray(DBselect(
- - 'SELECT DISTINCT i.hostid,i.itemid,i.name,i.value_type,i.units,i.state,i.valuemapid,i.key_,ia.applicationid'.
- + 'SELECT DISTINCT i.hostid,i.itemid,i.name,i.value_type,i.units,i.state,i.valuemapid,i.key_,ia.applicationid,i.delay'.
- ' FROM items i '.
- ' LEFT JOIN items_applications ia ON ia.itemid=i.itemid'.
- ' WHERE i.status='.ITEM_STATUS_ACTIVE.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement