add piwik installation
This commit is contained in:
parent
90aa4ef157
commit
8c5d4f0c31
58 changed files with 563902 additions and 0 deletions
1
www/analytics/plugins/DBStats/.gitignore
vendored
Normal file
1
www/analytics/plugins/DBStats/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
tests/UI/processed-ui-screenshots
|
||||
283
www/analytics/plugins/DBStats/API.php
Normal file
283
www/analytics/plugins/DBStats/API.php
Normal file
|
|
@ -0,0 +1,283 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\Plugins\DBStats;
|
||||
|
||||
use Piwik\Common;
|
||||
use Piwik\DataTable;
|
||||
use Piwik\Piwik;
|
||||
|
||||
/**
|
||||
* @see plugins/DBStats/MySQLMetadataProvider.php
|
||||
*/
|
||||
require_once PIWIK_INCLUDE_PATH . '/plugins/DBStats/MySQLMetadataProvider.php';
|
||||
|
||||
/**
|
||||
* DBStats API is used to request the overall status of the Mysql tables in use by Piwik.
|
||||
*
|
||||
* @method static \Piwik\Plugins\DBStats\API getInstance()
|
||||
*/
|
||||
class API extends \Piwik\Plugin\API
|
||||
{
|
||||
/**
|
||||
* The MySQLMetadataProvider instance that fetches table/db status information.
|
||||
*/
|
||||
private $metadataProvider;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
$this->metadataProvider = new MySQLMetadataProvider();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets some general information about this Piwik installation, including the count of
|
||||
* websites tracked, the count of users and the total space used by the database.
|
||||
*
|
||||
* @return array Contains the website count, user count and total space used by the database.
|
||||
*/
|
||||
public function getGeneralInformation()
|
||||
{
|
||||
Piwik::checkUserHasSuperUserAccess();
|
||||
// calculate total size
|
||||
$totalSpaceUsed = 0;
|
||||
foreach ($this->metadataProvider->getAllTablesStatus() as $status) {
|
||||
$totalSpaceUsed += $status['Data_length'] + $status['Index_length'];
|
||||
}
|
||||
|
||||
$siteTableStatus = $this->metadataProvider->getTableStatus('site');
|
||||
$userTableStatus = $this->metadataProvider->getTableStatus('user');
|
||||
|
||||
$siteCount = $siteTableStatus['Rows'];
|
||||
$userCount = $userTableStatus['Rows'];
|
||||
|
||||
return array($siteCount, $userCount, $totalSpaceUsed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets general database info that is not specific to any table.
|
||||
*
|
||||
* @return array See http://dev.mysql.com/doc/refman/5.1/en/show-status.html .
|
||||
*/
|
||||
public function getDBStatus()
|
||||
{
|
||||
Piwik::checkUserHasSuperUserAccess();
|
||||
return $this->metadataProvider->getDBStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a datatable summarizing how data is distributed among Piwik tables.
|
||||
*
|
||||
* This function will group tracker tables, numeric archive tables, blob archive tables
|
||||
* and other tables together so only four rows are shown.
|
||||
*
|
||||
* @return DataTable A datatable with three columns: 'data_size', 'index_size', 'row_count'.
|
||||
*/
|
||||
public function getDatabaseUsageSummary()
|
||||
{
|
||||
Piwik::checkUserHasSuperUserAccess();
|
||||
|
||||
$emptyRow = array('data_size' => 0, 'index_size' => 0, 'row_count' => 0);
|
||||
$rows = array(
|
||||
'tracker_data' => $emptyRow,
|
||||
'metric_data' => $emptyRow,
|
||||
'report_data' => $emptyRow,
|
||||
'other_data' => $emptyRow
|
||||
);
|
||||
|
||||
foreach ($this->metadataProvider->getAllTablesStatus() as $status) {
|
||||
if ($this->isNumericArchiveTable($status['Name'])) {
|
||||
$rowToAddTo = & $rows['metric_data'];
|
||||
} else if ($this->isBlobArchiveTable($status['Name'])) {
|
||||
$rowToAddTo = & $rows['report_data'];
|
||||
} else if ($this->isTrackerTable($status['Name'])) {
|
||||
$rowToAddTo = & $rows['tracker_data'];
|
||||
} else {
|
||||
$rowToAddTo = & $rows['other_data'];
|
||||
}
|
||||
|
||||
$rowToAddTo['data_size'] += $status['Data_length'];
|
||||
$rowToAddTo['index_size'] += $status['Index_length'];
|
||||
$rowToAddTo['row_count'] += $status['Rows'];
|
||||
}
|
||||
|
||||
return DataTable::makeFromIndexedArray($rows);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a datatable describing how much space is taken up by each log table.
|
||||
*
|
||||
* @return DataTable A datatable with three columns: 'data_size', 'index_size', 'row_count'.
|
||||
*/
|
||||
public function getTrackerDataSummary()
|
||||
{
|
||||
Piwik::checkUserHasSuperUserAccess();
|
||||
return $this->getTablesSummary($this->metadataProvider->getAllLogTableStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a datatable describing how much space is taken up by each numeric
|
||||
* archive table.
|
||||
*
|
||||
* @return DataTable A datatable with three columns: 'data_size', 'index_size', 'row_count'.
|
||||
*/
|
||||
public function getMetricDataSummary()
|
||||
{
|
||||
Piwik::checkUserHasSuperUserAccess();
|
||||
return $this->getTablesSummary($this->metadataProvider->getAllNumericArchiveStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a datatable describing how much space is taken up by each numeric
|
||||
* archive table, grouped by year.
|
||||
*
|
||||
* @return DataTable A datatable with three columns: 'data_size', 'index_size', 'row_count'.
|
||||
*/
|
||||
public function getMetricDataSummaryByYear()
|
||||
{
|
||||
Piwik::checkUserHasSuperUserAccess();
|
||||
|
||||
$dataTable = $this->getMetricDataSummary();
|
||||
|
||||
$dataTable->filter('GroupBy', array('label', __NAMESPACE__ . '\API::getArchiveTableYear'));
|
||||
|
||||
return $dataTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a datatable describing how much space is taken up by each blob
|
||||
* archive table.
|
||||
*
|
||||
* @return DataTable A datatable with three columns: 'data_size', 'index_size', 'row_count'.
|
||||
*/
|
||||
public function getReportDataSummary()
|
||||
{
|
||||
Piwik::checkUserHasSuperUserAccess();
|
||||
return $this->getTablesSummary($this->metadataProvider->getAllBlobArchiveStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a datatable describing how much space is taken up by each blob
|
||||
* archive table, grouped by year.
|
||||
*
|
||||
* @return DataTable A datatable with three columns: 'data_size', 'index_size', 'row_count'.
|
||||
*/
|
||||
public function getReportDataSummaryByYear()
|
||||
{
|
||||
Piwik::checkUserHasSuperUserAccess();
|
||||
|
||||
$dataTable = $this->getReportDataSummary();
|
||||
|
||||
$dataTable->filter('GroupBy', array('label', __NAMESPACE__ . '\API::getArchiveTableYear'));
|
||||
|
||||
return $dataTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a datatable describing how much space is taken up by 'admin' tables.
|
||||
*
|
||||
* An 'admin' table is a table that is not central to analytics functionality.
|
||||
* So any table that isn't an archive table or a log table is an 'admin' table.
|
||||
*
|
||||
* @return DataTable A datatable with three columns: 'data_size', 'index_size', 'row_count'.
|
||||
*/
|
||||
public function getAdminDataSummary()
|
||||
{
|
||||
Piwik::checkUserHasSuperUserAccess();
|
||||
return $this->getTablesSummary($this->metadataProvider->getAllAdminTableStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a datatable describing how much total space is taken up by each
|
||||
* individual report type.
|
||||
*
|
||||
* Goal reports and reports of the format .*_[0-9]+ are grouped together.
|
||||
*
|
||||
* @param bool $forceCache false to use the cached result, true to run the queries again and
|
||||
* cache the result.
|
||||
* @return DataTable A datatable with three columns: 'data_size', 'index_size', 'row_count'.
|
||||
*/
|
||||
public function getIndividualReportsSummary($forceCache = false)
|
||||
{
|
||||
Piwik::checkUserHasSuperUserAccess();
|
||||
return $this->metadataProvider->getRowCountsAndSizeByBlobName($forceCache);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a datatable describing how much total space is taken up by each
|
||||
* individual metric type.
|
||||
*
|
||||
* Goal metrics, metrics of the format .*_[0-9]+ and 'done...' metrics are grouped together.
|
||||
*
|
||||
* @param bool $forceCache false to use the cached result, true to run the queries again and
|
||||
* cache the result.
|
||||
* @return DataTable A datatable with three columns: 'data_size', 'index_size', 'row_count'.
|
||||
*/
|
||||
public function getIndividualMetricsSummary($forceCache = false)
|
||||
{
|
||||
Piwik::checkUserHasSuperUserAccess();
|
||||
return $this->metadataProvider->getRowCountsAndSizeByMetricName($forceCache);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a datatable representation of a set of table statuses.
|
||||
*
|
||||
* @param array $statuses The table statuses to summarize.
|
||||
* @return DataTable
|
||||
*/
|
||||
private function getTablesSummary($statuses)
|
||||
{
|
||||
$dataTable = new DataTable();
|
||||
foreach ($statuses as $status) {
|
||||
$dataTable->addRowFromSimpleArray(array(
|
||||
'label' => $status['Name'],
|
||||
'data_size' => $status['Data_length'],
|
||||
'index_size' => $status['Index_length'],
|
||||
'row_count' => $status['Rows']
|
||||
));
|
||||
}
|
||||
return $dataTable;
|
||||
}
|
||||
|
||||
/** Returns true if $name is the name of a numeric archive table, false if otherwise. */
|
||||
private function isNumericArchiveTable($name)
|
||||
{
|
||||
return strpos($name, Common::prefixTable('archive_numeric_')) === 0;
|
||||
}
|
||||
|
||||
/** Returns true if $name is the name of a blob archive table, false if otherwise. */
|
||||
private function isBlobArchiveTable($name)
|
||||
{
|
||||
return strpos($name, Common::prefixTable('archive_blob_')) === 0;
|
||||
}
|
||||
|
||||
/** Returns true if $name is the name of a log table, false if otherwise. */
|
||||
private function isTrackerTable($name)
|
||||
{
|
||||
return strpos($name, Common::prefixTable('log_')) === 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the year of an archive table from its name.
|
||||
*
|
||||
* @param string $tableName
|
||||
*
|
||||
* @return string the year
|
||||
* @ignore
|
||||
*/
|
||||
public static function getArchiveTableYear($tableName)
|
||||
{
|
||||
if (preg_match("/archive_(?:numeric|blob)_([0-9]+)_/", $tableName, $matches) === 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $matches[1];
|
||||
}
|
||||
}
|
||||
160
www/analytics/plugins/DBStats/Controller.php
Normal file
160
www/analytics/plugins/DBStats/Controller.php
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\Plugins\DBStats;
|
||||
|
||||
use Piwik\MetricsFormatter;
|
||||
use Piwik\Piwik;
|
||||
use Piwik\View;
|
||||
use Piwik\ViewDataTable\Factory;
|
||||
|
||||
/**
|
||||
*/
|
||||
class Controller extends \Piwik\Plugin\ControllerAdmin
|
||||
{
|
||||
/**
|
||||
* Returns the index for this plugin. Shows every other report defined by this plugin,
|
||||
* except the '...ByYear' reports. These can be loaded as related reports.
|
||||
*
|
||||
* Also, the 'getIndividual...Summary' reports are loaded by AJAX, as they can take
|
||||
* a significant amount of time to load on setups w/ lots of websites.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
Piwik::checkUserHasSuperUserAccess();
|
||||
$view = new View('@DBStats/index');
|
||||
$this->setBasicVariablesView($view);
|
||||
|
||||
$view->databaseUsageSummary = $this->getDatabaseUsageSummary(true);
|
||||
$view->trackerDataSummary = $this->getTrackerDataSummary(true);
|
||||
$view->metricDataSummary = $this->getMetricDataSummary(true);
|
||||
$view->reportDataSummary = $this->getReportDataSummary(true);
|
||||
$view->adminDataSummary = $this->getAdminDataSummary(true);
|
||||
|
||||
list($siteCount, $userCount, $totalSpaceUsed) = API::getInstance()->getGeneralInformation();
|
||||
$view->siteCount = MetricsFormatter::getPrettyNumber($siteCount);
|
||||
$view->userCount = MetricsFormatter::getPrettyNumber($userCount);
|
||||
$view->totalSpaceUsed = MetricsFormatter::getPrettySizeFromBytes($totalSpaceUsed);
|
||||
|
||||
return $view->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a datatable that displays how much space the tracker tables, numeric
|
||||
* archive tables, report tables and other tables take up in the MySQL database.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDatabaseUsageSummary()
|
||||
{
|
||||
Piwik::checkUserHasSuperUserAccess();
|
||||
return $this->renderReport(__FUNCTION__);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a datatable that displays the amount of space each individual log table
|
||||
* takes up in the MySQL database.
|
||||
* @return string|void
|
||||
*/
|
||||
public function getTrackerDataSummary()
|
||||
{
|
||||
Piwik::checkUserHasSuperUserAccess();
|
||||
return $this->renderReport(__FUNCTION__);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a datatable that displays the amount of space each numeric archive table
|
||||
* takes up in the MySQL database.
|
||||
*
|
||||
* @return string|void
|
||||
*/
|
||||
public function getMetricDataSummary()
|
||||
{
|
||||
Piwik::checkUserHasSuperUserAccess();
|
||||
return $this->renderReport(__FUNCTION__);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a datatable that displays the amount of space each numeric archive table
|
||||
* takes up in the MySQL database, for each year of numeric data.
|
||||
*
|
||||
* @return string|void
|
||||
*/
|
||||
public function getMetricDataSummaryByYear()
|
||||
{
|
||||
Piwik::checkUserHasSuperUserAccess();
|
||||
return $this->renderReport(__FUNCTION__);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a datatable that displays the amount of space each blob archive table
|
||||
* takes up in the MySQL database.
|
||||
*
|
||||
* @return string|void
|
||||
*/
|
||||
public function getReportDataSummary()
|
||||
{
|
||||
Piwik::checkUserHasSuperUserAccess();
|
||||
return $this->renderReport(__FUNCTION__);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a datatable that displays the amount of space each blob archive table
|
||||
* takes up in the MySQL database, for each year of blob data.
|
||||
*
|
||||
* @return string|void
|
||||
*/
|
||||
public function getReportDataSummaryByYear()
|
||||
{
|
||||
Piwik::checkUserHasSuperUserAccess();
|
||||
return $this->renderReport(__FUNCTION__);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a datatable that displays how many occurances there are of each individual
|
||||
* report type stored in the MySQL database.
|
||||
*
|
||||
* Goal reports and reports of the format: .*_[0-9]+ are grouped together.
|
||||
*
|
||||
* @return string|void
|
||||
*/
|
||||
public function getIndividualReportsSummary()
|
||||
{
|
||||
Piwik::checkUserHasSuperUserAccess();
|
||||
return $this->renderReport(__FUNCTION__);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a datatable that displays how many occurances there are of each individual
|
||||
* metric type stored in the MySQL database.
|
||||
*
|
||||
* Goal metrics, metrics of the format .*_[0-9]+ and 'done...' metrics are grouped together.
|
||||
*
|
||||
* @return string|void
|
||||
*/
|
||||
public function getIndividualMetricsSummary()
|
||||
{
|
||||
Piwik::checkUserHasSuperUserAccess();
|
||||
return $this->renderReport(__FUNCTION__);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a datatable that displays the amount of space each 'admin' table takes
|
||||
* up in the MySQL database.
|
||||
*
|
||||
* An 'admin' table is a table that is not central to analytics functionality.
|
||||
* So any table that isn't an archive table or a log table is an 'admin' table.
|
||||
*
|
||||
* @return string|void
|
||||
*/
|
||||
public function getAdminDataSummary()
|
||||
{
|
||||
Piwik::checkUserHasSuperUserAccess();
|
||||
return $this->renderReport(__FUNCTION__);
|
||||
}
|
||||
}
|
||||
386
www/analytics/plugins/DBStats/DBStats.php
Normal file
386
www/analytics/plugins/DBStats/DBStats.php
Normal file
|
|
@ -0,0 +1,386 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\Plugins\DBStats;
|
||||
|
||||
use Piwik\Date;
|
||||
use Piwik\Menu\MenuAdmin;
|
||||
use Piwik\Option;
|
||||
use Piwik\Piwik;
|
||||
use Piwik\Plugin\ViewDataTable;
|
||||
use Piwik\Plugins\CoreVisualizations\Visualizations\Graph;
|
||||
use Piwik\Plugins\CoreVisualizations\Visualizations\HtmlTable;
|
||||
use Piwik\Plugins\CoreVisualizations\Visualizations\JqplotGraph\Pie;
|
||||
use Piwik\ScheduledTask;
|
||||
use Piwik\ScheduledTime\Weekly;
|
||||
use Piwik\ScheduledTime;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class DBStats extends \Piwik\Plugin
|
||||
{
|
||||
const TIME_OF_LAST_TASK_RUN_OPTION = 'dbstats_time_of_last_cache_task_run';
|
||||
|
||||
/**
|
||||
* @see Piwik\Plugin::getListHooksRegistered
|
||||
*/
|
||||
public function getListHooksRegistered()
|
||||
{
|
||||
return array(
|
||||
'AssetManager.getStylesheetFiles' => 'getStylesheetFiles',
|
||||
'Menu.Admin.addItems' => 'addMenu',
|
||||
'TaskScheduler.getScheduledTasks' => 'getScheduledTasks',
|
||||
'ViewDataTable.configure' => 'configureViewDataTable',
|
||||
'ViewDataTable.getDefaultType' => 'getDefaultTypeViewDataTable',
|
||||
"TestingEnvironment.addHooks" => 'setupTestEnvironment'
|
||||
);
|
||||
}
|
||||
|
||||
function addMenu()
|
||||
{
|
||||
MenuAdmin::getInstance()->add('CoreAdminHome_MenuDiagnostic', 'DBStats_DatabaseUsage',
|
||||
array('module' => 'DBStats', 'action' => 'index'),
|
||||
Piwik::hasUserSuperUserAccess(),
|
||||
$order = 6);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all scheduled tasks executed by this plugin.
|
||||
*/
|
||||
public function getScheduledTasks(&$tasks)
|
||||
{
|
||||
$cacheDataByArchiveNameReportsTask = new ScheduledTask(
|
||||
$this,
|
||||
'cacheDataByArchiveNameReports',
|
||||
null,
|
||||
ScheduledTime::factory('weekly'),
|
||||
ScheduledTask::LOWEST_PRIORITY
|
||||
);
|
||||
$tasks[] = $cacheDataByArchiveNameReportsTask;
|
||||
}
|
||||
|
||||
/**
|
||||
* Caches the intermediate DataTables used in the getIndividualReportsSummary and
|
||||
* getIndividualMetricsSummary reports in the option table.
|
||||
*/
|
||||
public function cacheDataByArchiveNameReports()
|
||||
{
|
||||
$api = API::getInstance();
|
||||
$api->getIndividualReportsSummary(true);
|
||||
$api->getIndividualMetricsSummary(true);
|
||||
|
||||
$now = Date::now()->getLocalized("%longYear%, %shortMonth% %day%");
|
||||
Option::set(self::TIME_OF_LAST_TASK_RUN_OPTION, $now);
|
||||
}
|
||||
|
||||
public function getStylesheetFiles(&$stylesheets)
|
||||
{
|
||||
$stylesheets[] = "plugins/DBStats/stylesheets/dbStatsTable.less";
|
||||
}
|
||||
|
||||
/** Returns the date when the cacheDataByArchiveNameReports was last run. */
|
||||
public static function getDateOfLastCachingRun()
|
||||
{
|
||||
return Option::get(self::TIME_OF_LAST_TASK_RUN_OPTION);
|
||||
}
|
||||
|
||||
public function getDefaultTypeViewDataTable(&$defaultViewTypes)
|
||||
{
|
||||
$defaultViewTypes['DBStats.getDatabaseUsageSummary'] = Pie::ID;
|
||||
$defaultViewTypes['DBStats.getTrackerDataSummary'] = HtmlTable::ID;
|
||||
$defaultViewTypes['DBStats.getMetricDataSummary'] = HtmlTable::ID;
|
||||
$defaultViewTypes['DBStats.getMetricDataSummaryByYear'] = HtmlTable::ID;
|
||||
$defaultViewTypes['DBStats.getReportDataSummary'] = HtmlTable::ID;
|
||||
$defaultViewTypes['DBStats.getReportDataSummaryByYear'] = HtmlTable::ID;
|
||||
$defaultViewTypes['DBStats.getIndividualReportsSummary'] = HtmlTable::ID;
|
||||
$defaultViewTypes['DBStats.getIndividualMetricsSummary'] = HtmlTable::ID;
|
||||
$defaultViewTypes['DBStats.getAdminDataSummary'] = HtmlTable::ID;
|
||||
}
|
||||
|
||||
public function configureViewDataTable(ViewDataTable $view)
|
||||
{
|
||||
switch ($view->requestConfig->apiMethodToRequestDataTable) {
|
||||
case 'DBStats.getDatabaseUsageSummar':
|
||||
$this->configureViewForGetDatabaseUsageSummary($view);
|
||||
break;
|
||||
case 'DBStats.getTrackerDataSummary':
|
||||
$this->configureViewForGetTrackerDataSummary($view);
|
||||
break;
|
||||
case 'DBStats.getMetricDataSummary':
|
||||
$this->configureViewForGetMetricDataSummary($view);
|
||||
break;
|
||||
case 'DBStats.getMetricDataSummaryByYear':
|
||||
$this->configureViewForGetMetricDataSummaryByYear($view);
|
||||
break;
|
||||
case 'DBStats.getReportDataSummary':
|
||||
$this->configureViewForGetReportDataSummary($view);
|
||||
break;
|
||||
case 'DBStats.getReportDataSummaryByYear':
|
||||
$this->configureViewForGetReportDataSummaryByYear($view);
|
||||
break;
|
||||
case 'DBStats.getIndividualReportsSummary':
|
||||
$this->configureViewForGetIndividualReportsSummary($view);
|
||||
break;
|
||||
case 'DBStats.getIndividualMetricsSummary':
|
||||
$this->configureViewForGetIndividualMetricsSummary($view);
|
||||
break;
|
||||
case 'DBStats.getAdminDataSummary':
|
||||
$this->configureViewForGetAdminDataSummary($view);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private function configureViewForGetDatabaseUsageSummary(ViewDataTable $view)
|
||||
{
|
||||
$this->addBaseDisplayProperties($view);
|
||||
$this->addPresentationFilters($view, $addTotalSizeColumn = true, $addPercentColumn = true);
|
||||
|
||||
$view->config->show_offset_information = false;
|
||||
$view->config->show_pagination_control = false;
|
||||
|
||||
if ($view->isViewDataTableId(Graph::ID)) {
|
||||
$view->config->show_all_ticks = true;
|
||||
}
|
||||
|
||||
// translate the labels themselves
|
||||
$valueToTranslationStr = array(
|
||||
'tracker_data' => 'DBStats_TrackerTables',
|
||||
'report_data' => 'DBStats_ReportTables',
|
||||
'metric_data' => 'DBStats_MetricTables',
|
||||
'other_data' => 'DBStats_OtherTables'
|
||||
);
|
||||
|
||||
$translateSummaryLabel = function ($value) use ($valueToTranslationStr) {
|
||||
return isset($valueToTranslationStr[$value])
|
||||
? Piwik::translate($valueToTranslationStr[$value])
|
||||
: $value;
|
||||
};
|
||||
|
||||
$view->config->filters[] = array('ColumnCallbackReplace', array('label', $translateSummaryLabel), $isPriority = true);
|
||||
}
|
||||
|
||||
private function configureViewForGetTrackerDataSummary(ViewDataTable $view)
|
||||
{
|
||||
$this->addBaseDisplayProperties($view);
|
||||
$this->addPresentationFilters($view);
|
||||
|
||||
$view->requestConfig->filter_sort_order = 'asc';
|
||||
$view->config->show_offset_information = false;
|
||||
$view->config->show_pagination_control = false;
|
||||
}
|
||||
|
||||
private function configureViewForGetMetricDataSummary(ViewDataTable $view)
|
||||
{
|
||||
$this->addBaseDisplayProperties($view);
|
||||
$this->addPresentationFilters($view);
|
||||
|
||||
$view->config->title = Piwik::translate('DBStats_MetricTables');
|
||||
$view->config->addRelatedReports(array(
|
||||
'DBStats.getMetricDataSummaryByYear' => Piwik::translate('DBStats_MetricDataByYear')
|
||||
));
|
||||
}
|
||||
|
||||
private function configureViewForGetMetricDataSummaryByYear(ViewDataTable $view)
|
||||
{
|
||||
$this->addBaseDisplayProperties($view);
|
||||
$this->addPresentationFilters($view);
|
||||
|
||||
$view->config->title = Piwik::translate('DBStats_MetricDataByYear');
|
||||
$view->config->addTranslation('label', Piwik::translate('CoreHome_PeriodYear'));
|
||||
$view->config->addRelatedReports(array(
|
||||
'DBStats.getMetricDataSummary' => Piwik::translate('DBStats_MetricTables')
|
||||
));
|
||||
}
|
||||
|
||||
private function configureViewForGetReportDataSummary(ViewDataTable $view)
|
||||
{
|
||||
$this->addBaseDisplayProperties($view);
|
||||
$this->addPresentationFilters($view);
|
||||
|
||||
$view->config->title = Piwik::translate('DBStats_ReportTables');
|
||||
$view->config->addRelatedReports(array(
|
||||
'DBStats.getReportDataSummaryByYear' => Piwik::translate('DBStats_ReportDataByYear')
|
||||
));
|
||||
}
|
||||
|
||||
private function configureViewForGetReportDataSummaryByYear(ViewDataTable $view)
|
||||
{
|
||||
$this->addBaseDisplayProperties($view);
|
||||
$this->addPresentationFilters($view);
|
||||
|
||||
$view->config->title = Piwik::translate('DBStats_ReportDataByYear');
|
||||
$view->config->addTranslation('label', Piwik::translate('CoreHome_PeriodYear'));
|
||||
$view->config->addRelatedReports(array(
|
||||
'DBStats.getReportDataSummary' => Piwik::translate('DBStats_ReportTables')
|
||||
));
|
||||
}
|
||||
|
||||
private function configureViewForGetIndividualReportsSummary(ViewDataTable $view)
|
||||
{
|
||||
$this->addBaseDisplayProperties($view);
|
||||
$this->addPresentationFilters($view, $addTotalSizeColumn = false, $addPercentColumn = false,
|
||||
$sizeColumns = array('estimated_size'));
|
||||
|
||||
$view->requestConfig->filter_sort_order = 'asc';
|
||||
$view->config->addTranslation('label', Piwik::translate('General_Report'));
|
||||
|
||||
// this report table has some extra columns that shouldn't be shown
|
||||
if ($view->isViewDataTableId(HtmlTable::ID)) {
|
||||
$view->config->columns_to_display = array('label', 'row_count', 'estimated_size');
|
||||
}
|
||||
|
||||
$this->setIndividualSummaryFooterMessage($view);
|
||||
}
|
||||
|
||||
private function configureViewForGetIndividualMetricsSummary(ViewDataTable $view)
|
||||
{
|
||||
$this->addBaseDisplayProperties($view);
|
||||
$this->addPresentationFilters($view, $addTotalSizeColumn = false, $addPercentColumn = false,
|
||||
$sizeColumns = array('estimated_size'));
|
||||
|
||||
$view->requestConfig->filter_sort_order = 'asc';
|
||||
$view->config->addTranslation('label', Piwik::translate('General_Metric'));
|
||||
|
||||
$this->setIndividualSummaryFooterMessage($view);
|
||||
}
|
||||
|
||||
private function configureViewForGetAdminDataSummary(ViewDataTable $view)
|
||||
{
|
||||
$this->addBaseDisplayProperties($view);
|
||||
$this->addPresentationFilters($view);
|
||||
|
||||
$view->requestConfig->filter_sort_order = 'asc';
|
||||
$view->config->show_offset_information = false;
|
||||
$view->config->show_pagination_control = false;
|
||||
}
|
||||
|
||||
private function addBaseDisplayProperties(ViewDataTable $view)
|
||||
{
|
||||
$view->requestConfig->filter_sort_column = 'label';
|
||||
$view->requestConfig->filter_sort_order = 'desc';
|
||||
$view->requestConfig->filter_limit = 25;
|
||||
|
||||
$view->config->show_exclude_low_population = false;
|
||||
$view->config->show_table_all_columns = false;
|
||||
$view->config->show_tag_cloud = false;
|
||||
$view->config->show_search = false;
|
||||
|
||||
if ($view->isViewDataTableId(HtmlTable::ID)) {
|
||||
$view->config->keep_summary_row = true;
|
||||
$view->config->disable_row_evolution = true;
|
||||
$view->config->highlight_summary_row = true;
|
||||
}
|
||||
|
||||
$view->config->addTranslations(array(
|
||||
'label' => Piwik::translate('DBStats_Table'),
|
||||
'year' => Piwik::translate('CoreHome_PeriodYear'),
|
||||
'data_size' => Piwik::translate('DBStats_DataSize'),
|
||||
'index_size' => Piwik::translate('DBStats_IndexSize'),
|
||||
'total_size' => Piwik::translate('DBStats_TotalSize'),
|
||||
'row_count' => Piwik::translate('DBStats_RowCount'),
|
||||
'percent_total' => '% ' . Piwik::translate('DBStats_DBSize'),
|
||||
'estimated_size' => Piwik::translate('DBStats_EstimatedSize')
|
||||
));
|
||||
}
|
||||
|
||||
private function addPresentationFilters(ViewDataTable $view, $addTotalSizeColumn = true, $addPercentColumn = false,
|
||||
$sizeColumns = array('data_size', 'index_size'))
|
||||
{
|
||||
// add total_size column
|
||||
if ($addTotalSizeColumn) {
|
||||
$getTotalTableSize = function ($dataSize, $indexSize) {
|
||||
return $dataSize + $indexSize;
|
||||
};
|
||||
|
||||
$view->config->filters[] = array('ColumnCallbackAddColumn',
|
||||
array(array('data_size', 'index_size'), 'total_size', $getTotalTableSize), $isPriority = true);
|
||||
|
||||
$sizeColumns[] = 'total_size';
|
||||
}
|
||||
|
||||
$runPrettySizeFilterBeforeGeneric = false;
|
||||
|
||||
if ($view->isViewDataTableId(HtmlTable::ID)) {
|
||||
|
||||
// add summary row only if displaying a table
|
||||
$view->config->filters[] = array('AddSummaryRow', Piwik::translate('General_Total'));
|
||||
|
||||
// add percentage column if desired
|
||||
if ($addPercentColumn
|
||||
&& $addTotalSizeColumn
|
||||
) {
|
||||
$view->config->filters[] = array('ColumnCallbackAddColumnPercentage',
|
||||
array('percent_total', 'total_size', 'total_size', $quotientPrecision = 0,
|
||||
$shouldSkipRows = false, $getDivisorFromSummaryRow = true),
|
||||
$isPriority = true
|
||||
);
|
||||
|
||||
$view->requestConfig->filter_sort_column = 'percent_total';
|
||||
}
|
||||
|
||||
} else if ($view->isViewDataTableId(Graph::ID)) {
|
||||
if ($addTotalSizeColumn) {
|
||||
$view->config->columns_to_display = array('label', 'total_size');
|
||||
|
||||
// when displaying a graph, we force sizes to be shown as the same unit so axis labels
|
||||
// will be readable. NOTE: The unit should depend on the smallest value of the data table,
|
||||
// however there's no way to know this information, short of creating a custom filter. For
|
||||
// now, just assume KB.
|
||||
$fixedMemoryUnit = 'K';
|
||||
$view->config->y_axis_unit = ' K';
|
||||
$view->requestConfig->filter_sort_column = 'total_size';
|
||||
$view->requestConfig->filter_sort_order = 'desc';
|
||||
|
||||
$runPrettySizeFilterBeforeGeneric = true;
|
||||
} else {
|
||||
$view->config->columns_to_display = array('label', 'row_count');
|
||||
$view->config->y_axis_unit = ' ' . Piwik::translate('General_Rows');
|
||||
|
||||
$view->requestConfig->filter_sort_column = 'row_count';
|
||||
$view->requestConfig->filter_sort_order = 'desc';
|
||||
}
|
||||
}
|
||||
|
||||
$getPrettySize = array('\Piwik\MetricsFormatter', 'getPrettySizeFromBytes');
|
||||
$params = !isset($fixedMemoryUnit) ? array() : array($fixedMemoryUnit);
|
||||
|
||||
$view->config->filters[] = array('ColumnCallbackReplace', array($sizeColumns, $getPrettySize, $params), $runPrettySizeFilterBeforeGeneric);
|
||||
|
||||
// jqPlot will display as, well, ' ', so don't replace the spaces when rendering as a graph
|
||||
if ($view->isViewDataTableId(HtmlTable::ID)) {
|
||||
$replaceSpaces = function ($value) {
|
||||
return str_replace(' ', ' ', $value);
|
||||
};
|
||||
|
||||
$view->config->filters[] = array('ColumnCallbackReplace', array($sizeColumns, $replaceSpaces));
|
||||
}
|
||||
|
||||
$getPrettyNumber = array('\Piwik\MetricsFormatter', 'getPrettyNumber');
|
||||
$view->config->filters[] = array('ColumnCallbackReplace', array('row_count', $getPrettyNumber));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the footer message for the Individual...Summary reports.
|
||||
*/
|
||||
private function setIndividualSummaryFooterMessage(ViewDataTable $view)
|
||||
{
|
||||
$lastGenerated = self::getDateOfLastCachingRun();
|
||||
if ($lastGenerated !== false) {
|
||||
$view->config->show_footer_message = Piwik::translate('Mobile_LastUpdated', $lastGenerated);
|
||||
}
|
||||
}
|
||||
|
||||
public function setupTestEnvironment($environment)
|
||||
{
|
||||
Piwik::addAction("MySQLMetadataProvider.createDao", function (&$dao) {
|
||||
require_once dirname(__FILE__) . "/tests/Mocks/MockDataAccess.php";
|
||||
$dao = new Mocks\MockDataAccess();
|
||||
});
|
||||
}
|
||||
}
|
||||
70
www/analytics/plugins/DBStats/MySQLMetadataDataAccess.php
Normal file
70
www/analytics/plugins/DBStats/MySQLMetadataDataAccess.php
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\Plugins\DBStats;
|
||||
|
||||
use Piwik\Db;
|
||||
use Piwik\Config;
|
||||
use \Exception;
|
||||
|
||||
/**
|
||||
* Data Access Object that serves MySQL stats.
|
||||
*/
|
||||
class MySQLMetadataDataAccess
|
||||
{
|
||||
public function getDBStatus()
|
||||
{
|
||||
if (function_exists('mysql_connect')) {
|
||||
$configDb = Config::getInstance()->database;
|
||||
$link = mysql_connect($configDb['host'], $configDb['username'], $configDb['password']);
|
||||
$status = mysql_stat($link);
|
||||
mysql_close($link);
|
||||
$status = explode(" ", $status);
|
||||
} else {
|
||||
$fullStatus = Db::fetchAssoc('SHOW STATUS');
|
||||
if (empty($fullStatus)) {
|
||||
throw new Exception('Error, SHOW STATUS failed');
|
||||
}
|
||||
|
||||
$status = array(
|
||||
'Uptime' => $fullStatus['Uptime']['Value'],
|
||||
'Threads' => $fullStatus['Threads_running']['Value'],
|
||||
'Questions' => $fullStatus['Questions']['Value'],
|
||||
'Slow queries' => $fullStatus['Slow_queries']['Value'],
|
||||
'Flush tables' => $fullStatus['Flush_commands']['Value'],
|
||||
'Open tables' => $fullStatus['Open_tables']['Value'],
|
||||
'Opens' => 'unavailable', // not available via SHOW STATUS
|
||||
'Queries per second avg' => 'unavailable' // not available via SHOW STATUS
|
||||
);
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
public function getTableStatus($tableName)
|
||||
{
|
||||
return Db::fetchRow("SHOW TABLE STATUS LIKE ?", array($tableName));
|
||||
}
|
||||
|
||||
public function getAllTablesStatus()
|
||||
{
|
||||
return Db::fetchAll("SHOW TABLE STATUS");
|
||||
}
|
||||
|
||||
public function getRowCountsByArchiveName($tableName, $extraCols)
|
||||
{
|
||||
// otherwise, create data table & cache it
|
||||
$sql = "SELECT name as 'label', COUNT(*) as 'row_count'$extraCols FROM $tableName GROUP BY name";
|
||||
return Db::fetchAll($sql);
|
||||
}
|
||||
|
||||
public function getColumnsFromTable($tableName)
|
||||
{
|
||||
return Db::fetchAll("SHOW COLUMNS FROM " . $tableName);
|
||||
}
|
||||
}
|
||||
356
www/analytics/plugins/DBStats/MySQLMetadataProvider.php
Executable file
356
www/analytics/plugins/DBStats/MySQLMetadataProvider.php
Executable file
|
|
@ -0,0 +1,356 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\Plugins\DBStats;
|
||||
|
||||
use Exception;
|
||||
use Piwik\Common;
|
||||
use Piwik\Config;
|
||||
use Piwik\DataTable;
|
||||
use Piwik\Db;
|
||||
use Piwik\DbHelper;
|
||||
use Piwik\Option;
|
||||
use Piwik\Piwik;
|
||||
|
||||
/**
|
||||
* Utility class that provides general information about databases, including the size of
|
||||
* the entire database, the size and row count of each table and the size and row count
|
||||
* of each metric/report type currently stored.
|
||||
*
|
||||
* This class will cache the table information it retrieves from the database. In order to
|
||||
* issue a new query instead of using this cache, you must create a new instance of this type.
|
||||
*/
|
||||
class MySQLMetadataProvider
|
||||
{
|
||||
/**
|
||||
* Cached MySQL table statuses. So we won't needlessly re-issue SHOW TABLE STATUS queries.
|
||||
*/
|
||||
private $tableStatuses = null;
|
||||
|
||||
/**
|
||||
* Data access object.
|
||||
*/
|
||||
public $dataAccess = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
Piwik::postTestEvent("MySQLMetadataProvider.createDao", array(&$this->dataAccess));
|
||||
|
||||
if ($this->dataAccess === null) {
|
||||
$this->dataAccess = new MySQLMetadataDataAccess();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets general database info that is not specific to any table.
|
||||
*
|
||||
* @throws Exception
|
||||
* @return array See http://dev.mysql.com/doc/refman/5.1/en/show-status.html .
|
||||
*/
|
||||
public function getDBStatus()
|
||||
{
|
||||
return $this->dataAccess->getDBStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the MySQL table status of the requested Piwik table.
|
||||
*
|
||||
* @param string $table The name of the table. Should not be prefixed (ie, 'log_visit' is
|
||||
* correct, 'piwik_log_visit' is not).
|
||||
* @return array See http://dev.mysql.com/doc/refman/5.1/en/show-table-status.html .
|
||||
*/
|
||||
public function getTableStatus($table)
|
||||
{
|
||||
$prefixed = Common::prefixTable($table);
|
||||
|
||||
// if we've already gotten every table status, don't issue an uneeded query
|
||||
if (!is_null($this->tableStatuses) && isset($this->tableStatuses[$prefixed])) {
|
||||
return $this->tableStatuses[$prefixed];
|
||||
} else {
|
||||
return $this->dataAccess->getTableStatus($prefixed);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the result of a SHOW TABLE STATUS query for every Piwik table in the DB.
|
||||
* Non-piwik tables are ignored.
|
||||
*
|
||||
* @param string $matchingRegex Regex used to filter out tables whose name doesn't
|
||||
* match it.
|
||||
* @return array The table information. See http://dev.mysql.com/doc/refman/5.5/en/show-table-status.html
|
||||
* for specifics.
|
||||
*/
|
||||
public function getAllTablesStatus($matchingRegex = null)
|
||||
{
|
||||
if (is_null($this->tableStatuses)) {
|
||||
$tablesPiwik = DbHelper::getTablesInstalled();
|
||||
|
||||
$this->tableStatuses = array();
|
||||
foreach ($this->dataAccess->getAllTablesStatus() as $t) {
|
||||
if (in_array($t['Name'], $tablesPiwik)) {
|
||||
$this->tableStatuses[$t['Name']] = $t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (is_null($matchingRegex)) {
|
||||
return $this->tableStatuses;
|
||||
}
|
||||
|
||||
$result = array();
|
||||
foreach ($this->tableStatuses as $status) {
|
||||
if (preg_match($matchingRegex, $status['Name'])) {
|
||||
$result[] = $status;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns table statuses for every log table.
|
||||
*
|
||||
* @return array An array of status arrays. See http://dev.mysql.com/doc/refman/5.5/en/show-table-status.html.
|
||||
*/
|
||||
public function getAllLogTableStatus()
|
||||
{
|
||||
$regex = "/^" . Common::prefixTable('log_') . "(?!profiling)/";
|
||||
return $this->getAllTablesStatus($regex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns table statuses for every numeric archive table.
|
||||
*
|
||||
* @return array An array of status arrays. See http://dev.mysql.com/doc/refman/5.5/en/show-table-status.html.
|
||||
*/
|
||||
public function getAllNumericArchiveStatus()
|
||||
{
|
||||
$regex = "/^" . Common::prefixTable('archive_numeric') . "_/";
|
||||
return $this->getAllTablesStatus($regex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns table statuses for every blob archive table.
|
||||
*
|
||||
* @return array An array of status arrays. See http://dev.mysql.com/doc/refman/5.5/en/show-table-status.html.
|
||||
*/
|
||||
public function getAllBlobArchiveStatus()
|
||||
{
|
||||
$regex = "/^" . Common::prefixTable('archive_blob') . "_/";
|
||||
return $this->getAllTablesStatus($regex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retruns table statuses for every admin table.
|
||||
*
|
||||
* @return array An array of status arrays. See http://dev.mysql.com/doc/refman/5.5/en/show-table-status.html.
|
||||
*/
|
||||
public function getAllAdminTableStatus()
|
||||
{
|
||||
$regex = "/^" . Common::prefixTable('') . "(?!archive_|(?:log_(?!profiling)))/";
|
||||
return $this->getAllTablesStatus($regex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a DataTable that lists the number of rows and the estimated amount of space
|
||||
* each blob archive type takes up in the database.
|
||||
*
|
||||
* Blob types are differentiated by name.
|
||||
*
|
||||
* @param bool $forceCache false to use the cached result, true to run the queries again and
|
||||
* cache the result.
|
||||
* @return DataTable
|
||||
*/
|
||||
public function getRowCountsAndSizeByBlobName($forceCache = false)
|
||||
{
|
||||
$extraSelects = array("SUM(OCTET_LENGTH(value)) AS 'blob_size'", "SUM(LENGTH(name)) AS 'name_size'");
|
||||
$extraCols = array('blob_size', 'name_size');
|
||||
return $this->getRowCountsByArchiveName(
|
||||
$this->getAllBlobArchiveStatus(), 'getEstimatedBlobArchiveRowSize', $forceCache, $extraSelects,
|
||||
$extraCols);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a DataTable that lists the number of rows and the estimated amount of space
|
||||
* each metric archive type takes up in the database.
|
||||
*
|
||||
* Metric types are differentiated by name.
|
||||
*
|
||||
* @param bool $forceCache false to use the cached result, true to run the queries again and
|
||||
* cache the result.
|
||||
* @return DataTable
|
||||
*/
|
||||
public function getRowCountsAndSizeByMetricName($forceCache = false)
|
||||
{
|
||||
return $this->getRowCountsByArchiveName(
|
||||
$this->getAllNumericArchiveStatus(), 'getEstimatedRowsSize', $forceCache);
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility function. Gets row count of a set of tables grouped by the 'name' column.
|
||||
* This is the implementation of the getRowCountsAndSizeBy... functions.
|
||||
*/
|
||||
private function getRowCountsByArchiveName($statuses, $getRowSizeMethod, $forceCache = false,
|
||||
$otherSelects = array(), $otherDataTableColumns = array())
|
||||
{
|
||||
$extraCols = '';
|
||||
if (!empty($otherSelects)) {
|
||||
$extraCols = ', ' . implode(', ', $otherSelects);
|
||||
}
|
||||
|
||||
$cols = array_merge(array('row_count'), $otherDataTableColumns);
|
||||
|
||||
$dataTable = new DataTable();
|
||||
foreach ($statuses as $status) {
|
||||
$dataTableOptionName = $this->getCachedOptionName($status['Name'], 'byArchiveName');
|
||||
|
||||
// if option exists && !$forceCache, use the cached data, otherwise create the
|
||||
$cachedData = Option::get($dataTableOptionName);
|
||||
if ($cachedData !== false && !$forceCache) {
|
||||
$table = DataTable::fromSerializedArray($cachedData);
|
||||
} else {
|
||||
$table = new DataTable();
|
||||
$table->addRowsFromSimpleArray($this->dataAccess->getRowCountsByArchiveName($status['Name'], $extraCols));
|
||||
|
||||
$reduceArchiveRowName = array($this, 'reduceArchiveRowName');
|
||||
$table->filter('GroupBy', array('label', $reduceArchiveRowName));
|
||||
|
||||
$serializedTables = $table->getSerialized();
|
||||
$serializedTable = reset($serializedTables);
|
||||
Option::set($dataTableOptionName, $serializedTable);
|
||||
}
|
||||
|
||||
// add estimated_size column
|
||||
$getEstimatedSize = array($this, $getRowSizeMethod);
|
||||
$table->filter('ColumnCallbackAddColumn',
|
||||
array($cols, 'estimated_size', $getEstimatedSize, array($status)));
|
||||
|
||||
$dataTable->addDataTable($table);
|
||||
}
|
||||
return $dataTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the estimated database size a count of rows takes in a table.
|
||||
*/
|
||||
public function getEstimatedRowsSize($row_count, $status)
|
||||
{
|
||||
if ($status['Rows'] == 0) {
|
||||
return 0;
|
||||
}
|
||||
$avgRowSize = ($status['Data_length'] + $status['Index_length']) / $status['Rows'];
|
||||
return $avgRowSize * $row_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the estimated database size a count of rows in a blob_archive table. Depends on
|
||||
* the data table row to contain the size of all blobs & name strings in the row set it
|
||||
* represents.
|
||||
*/
|
||||
public function getEstimatedBlobArchiveRowSize($row_count, $blob_size, $name_size, $status)
|
||||
{
|
||||
// calculate the size of each fixed size column in a blob archive table
|
||||
static $fixedSizeColumnLength = null;
|
||||
if (is_null($fixedSizeColumnLength)) {
|
||||
$fixedSizeColumnLength = 0;
|
||||
foreach ($this->dataAccess->getColumnsFromTable($status['Name']) as $column) {
|
||||
$columnType = $column['Type'];
|
||||
|
||||
if (($paren = strpos($columnType, '(')) !== false) {
|
||||
$columnType = substr($columnType, 0, $paren);
|
||||
}
|
||||
|
||||
$fixedSizeColumnLength += $this->getSizeOfDatabaseType($columnType);
|
||||
}
|
||||
}
|
||||
// calculate the average row size
|
||||
if ($status['Rows'] == 0) {
|
||||
$avgRowSize = 0;
|
||||
} else {
|
||||
$avgRowSize = $status['Index_length'] / $status['Rows'] + $fixedSizeColumnLength;
|
||||
}
|
||||
|
||||
// calculate the row set's size
|
||||
return $avgRowSize * $row_count + $blob_size + $name_size;
|
||||
}
|
||||
|
||||
/** Returns the size in bytes of a fixed size MySQL data type. Returns 0 for unsupported data type. */
|
||||
private function getSizeOfDatabaseType($columnType)
|
||||
{
|
||||
switch (strtolower($columnType)) {
|
||||
case "tinyint":
|
||||
case "year":
|
||||
return 1;
|
||||
case "smallint":
|
||||
return 2;
|
||||
case "mediumint":
|
||||
case "date":
|
||||
case "time":
|
||||
return 3;
|
||||
case "int":
|
||||
case "float": // assumes precision isn't used
|
||||
case "timestamp":
|
||||
return 4;
|
||||
case "bigint":
|
||||
case "double":
|
||||
case "real":
|
||||
case "datetime":
|
||||
return 8;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the option name used to cache the result of an intensive query.
|
||||
*/
|
||||
private function getCachedOptionName($tableName, $suffix)
|
||||
{
|
||||
return 'dbstats_cached_' . $tableName . '_' . $suffix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduces the given metric name. Used to simplify certain reports.
|
||||
*
|
||||
* Some metrics, like goal metrics, can have different string names. For goal metrics,
|
||||
* there's one name per goal ID. Grouping metrics and reports like these together
|
||||
* simplifies the tables that display them.
|
||||
*
|
||||
* This function makes goal names, 'done...' names and names of the format .*_[0-9]+
|
||||
* equivalent.
|
||||
*/
|
||||
public function reduceArchiveRowName($name)
|
||||
{
|
||||
// all 'done...' fields are considered the same
|
||||
if (strpos($name, 'done') === 0) {
|
||||
return 'done';
|
||||
}
|
||||
|
||||
// check for goal id, if present (Goals_... reports should not be reduced here, just Goal_... ones)
|
||||
if (preg_match("/^Goal_(?:-?[0-9]+_)?(.*)/", $name, $matches)) {
|
||||
$name = "Goal_*_" . $matches[1];
|
||||
}
|
||||
|
||||
// remove subtable id suffix, if present
|
||||
if (preg_match("/^(.*)_[0-9]+$/", $name, $matches)) {
|
||||
$name = $matches[1] . "_*";
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the internal cache that stores TABLE STATUS results.
|
||||
*/
|
||||
public function clearStatusCache()
|
||||
{
|
||||
$this->tableStatuses = null;
|
||||
}
|
||||
}
|
||||
10
www/analytics/plugins/DBStats/lang/am.json
Normal file
10
www/analytics/plugins/DBStats/lang/am.json
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"DBStats": {
|
||||
"DatabaseUsage": "የውሂብ ጎታ አጠቃቀም",
|
||||
"DataSize": "የውሂብ መጠን",
|
||||
"IndexSize": "የመረጃ ጠቋሚ መጠን",
|
||||
"MainDescription": "ፒዊክ የድር ምዘናዎቹን ውሂብ በመይ ኤስ ኪው ኤል ይውሂብ ጎታ ውስጥ በማከማቸት ላይ ነው። በአሁን ወቅት የፒዊክ ሰንጠረዦች እየተጠቀሙ ያሉት %s።",
|
||||
"Table": "ሰንጠረዥ",
|
||||
"TotalSize": "አጠቃላይ መጠን"
|
||||
}
|
||||
}
|
||||
17
www/analytics/plugins/DBStats/lang/ar.json
Normal file
17
www/analytics/plugins/DBStats/lang/ar.json
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"DBStats": {
|
||||
"DatabaseUsage": "استهلاك قاعدة البيانات",
|
||||
"DataSize": "حجم البيانات",
|
||||
"EstimatedSize": "الحجم التقريبي",
|
||||
"IndexSize": "حجم السجل",
|
||||
"LearnMore": "للإطلاع على المزيد حول كيفية معالجة Piwik للبيانات وكيفية ضبطه ليعمل على المواقع المتوسطة والكبيرة، انظر مستندات الدعم %s.",
|
||||
"MainDescription": "يقوم Piwik بتخزين كافة بيانات تحليلات ويب في قاعدة بيانات MySQL. حالياً، استهلك Piwik %s.",
|
||||
"MetricTables": "جداول المعيار",
|
||||
"PluginDescription": "هذا التطبيق يعطيك تقريراً عن مدى استهلاك قاعدة البيانات بواسطة جداول Piwik.",
|
||||
"ReportDataByYear": "جداول التقرير بالسنة",
|
||||
"RowCount": "عدد السطور",
|
||||
"Table": "الجدول",
|
||||
"TotalSize": "الحجم الإجمالي",
|
||||
"TrackerTables": "جداول المتتبع"
|
||||
}
|
||||
}
|
||||
13
www/analytics/plugins/DBStats/lang/be.json
Normal file
13
www/analytics/plugins/DBStats/lang/be.json
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"DBStats": {
|
||||
"DatabaseUsage": "Выкарыстанне БД",
|
||||
"DataSize": "Памер дадзеных",
|
||||
"IndexSize": "Памер індэксу",
|
||||
"LearnMore": "Каб даведацца больш аб тым, як Piwik апрацоўвае дадзеныя і як налдзцца больш аб тым, як Piwik апрацоўвае дадзеныя і як налдзиціць Piwik для добрага працавання на сайтах з сярэднімі і высокім трафікам, праверце дакументацыю %s.",
|
||||
"MainDescription": "Piwik захоўвае ўсю Вашу web статыстыку ў базе MySQL. Выкарыстанне Piwik табліц на дадзены момант %s.",
|
||||
"PluginDescription": "Гэты плагін паведамляе аб выкарыстанні базы дадзеных таблицам Piwik",
|
||||
"RowCount": "Колькасць радкоў",
|
||||
"Table": "Табліца",
|
||||
"TotalSize": "Агульны памер"
|
||||
}
|
||||
}
|
||||
21
www/analytics/plugins/DBStats/lang/bg.json
Normal file
21
www/analytics/plugins/DBStats/lang/bg.json
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"DBStats": {
|
||||
"DatabaseUsage": "Натоварване на БД",
|
||||
"DataSize": "Данни (размер)",
|
||||
"DBSize": "Размер на БД",
|
||||
"EstimatedSize": "Ориентировъчен размер",
|
||||
"IndexSize": "Индекс (размер)",
|
||||
"LearnMore": "За да научите повече за това как Piwik обработва данни и колко добре работи за среден и висок трафик на уеб сайтове, проверете документацията %s.",
|
||||
"MainDescription": "Piwik съхранява цялата информация в MySQL база от данни (БД). В момента Piwik таблиците използват %s.",
|
||||
"MetricDataByYear": "Метрични таблици за година",
|
||||
"MetricTables": "Метрични таблици",
|
||||
"OtherTables": "Други таблици",
|
||||
"PluginDescription": "Тази добавка докладва за използваното пространство на таблиците от Piwik в MySQL.",
|
||||
"ReportDataByYear": "Годишен доклад на таблици",
|
||||
"ReportTables": "Докладни таблици",
|
||||
"RowCount": "Брой редове",
|
||||
"Table": "Таблици",
|
||||
"TotalSize": "Общ размер",
|
||||
"TrackerTables": "Таблици на тракера"
|
||||
}
|
||||
}
|
||||
5
www/analytics/plugins/DBStats/lang/bn.json
Normal file
5
www/analytics/plugins/DBStats/lang/bn.json
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"DBStats": {
|
||||
"Table": "সারণি"
|
||||
}
|
||||
}
|
||||
8
www/analytics/plugins/DBStats/lang/bs.json
Normal file
8
www/analytics/plugins/DBStats/lang/bs.json
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"DBStats": {
|
||||
"DataSize": "Veličina podataka",
|
||||
"DBSize": "Veličina baze podataka",
|
||||
"Table": "Tabla",
|
||||
"TotalSize": "Ukupna velična"
|
||||
}
|
||||
}
|
||||
21
www/analytics/plugins/DBStats/lang/ca.json
Normal file
21
www/analytics/plugins/DBStats/lang/ca.json
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"DBStats": {
|
||||
"DatabaseUsage": "Ús de la base de dades",
|
||||
"DataSize": "Grandària de les dades",
|
||||
"DBSize": "Mida de la BD",
|
||||
"EstimatedSize": "Mida estimada",
|
||||
"IndexSize": "Grandària del l'índex",
|
||||
"LearnMore": "Per obtenir més informació sobre com el Piwik procesa la informació i com fer que el Piwik funcioni correctament en llocs amb un tràfic mitja o elevat, consulteu la següent documentació: %s.",
|
||||
"MainDescription": "El Piwik desa totes les anàlisis web la base de dades MySQL. Ara per ara, les taules del Piwik fan servir %s.",
|
||||
"MetricDataByYear": "Taules de mètriques per any.",
|
||||
"MetricTables": "Taules de mètriques",
|
||||
"OtherTables": "Altres taules",
|
||||
"PluginDescription": "Aquesta extensió mostra l'us de la Base de dades MySQL per les taules del Piwik.",
|
||||
"ReportDataByYear": "Taules d'informes per any",
|
||||
"ReportTables": "Taules d'informes",
|
||||
"RowCount": "Nombre de files",
|
||||
"Table": "Taula",
|
||||
"TotalSize": "Grandària total",
|
||||
"TrackerTables": "Taules de rastreig"
|
||||
}
|
||||
}
|
||||
20
www/analytics/plugins/DBStats/lang/cs.json
Normal file
20
www/analytics/plugins/DBStats/lang/cs.json
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"DBStats": {
|
||||
"DatabaseUsage": "Využití databáze",
|
||||
"DataSize": "Velikost dat",
|
||||
"DBSize": "Velikost databáze",
|
||||
"EstimatedSize": "Odhadovaná velikost",
|
||||
"IndexSize": "Velikost indexu",
|
||||
"LearnMore": "Abyste lépe zjistili, jak Piwik zpracovává data a jak jej nastavit pro weby se středním a velkým provozem, podívejte se do dokumentace %s.",
|
||||
"MainDescription": "Piwik ukládá všechny vaše data webové analýzy v MySQL databázi. Nyní tabulky Piwiku využívají %s.",
|
||||
"MetricDataByYear": "Měření tabulek za rok",
|
||||
"MetricTables": "Měřené tabulky",
|
||||
"OtherTables": "Osttaní tabulky",
|
||||
"PluginDescription": "Tento zásuvný modul hlásí využití databáze MySQL tabulkami Piwiku",
|
||||
"ReportDataByYear": "Hlášení tabulek za rok",
|
||||
"ReportTables": "Hlášení tabulek",
|
||||
"RowCount": "Počet řádků",
|
||||
"Table": "Tabulka",
|
||||
"TotalSize": "Celková velikost"
|
||||
}
|
||||
}
|
||||
21
www/analytics/plugins/DBStats/lang/da.json
Normal file
21
www/analytics/plugins/DBStats/lang/da.json
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"DBStats": {
|
||||
"DatabaseUsage": "Database brug",
|
||||
"DataSize": "Data",
|
||||
"DBSize": "DB størrelse",
|
||||
"EstimatedSize": "Anslået størrelse",
|
||||
"IndexSize": "Indeks",
|
||||
"LearnMore": "Hvis du vil vide mere om, hvordan Piwik behandler data, og hvordan man kan få Piwik til arbejde godt på mellem til stærkt trafikerede hjemmesider, se dokumentationen på %s.",
|
||||
"MainDescription": "Piwik gemmer al statistik i MySQL-databasen. Lige nu bruger Piwik-tabellerne %s.",
|
||||
"MetricDataByYear": "Målingstabeller fordelt på år",
|
||||
"MetricTables": "Målingstabeller",
|
||||
"OtherTables": "Andre tabeller",
|
||||
"PluginDescription": "Programudvidelsen viser MySQL-database brugen af Piwik tabeller.",
|
||||
"ReportDataByYear": "Rapport tabeller fordelt på år",
|
||||
"ReportTables": "Rapport tabeller",
|
||||
"RowCount": "Række antal",
|
||||
"Table": "Tabel",
|
||||
"TotalSize": "Samlet størrelse",
|
||||
"TrackerTables": "Sporings tabeller"
|
||||
}
|
||||
}
|
||||
21
www/analytics/plugins/DBStats/lang/de.json
Normal file
21
www/analytics/plugins/DBStats/lang/de.json
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"DBStats": {
|
||||
"DatabaseUsage": "Datenbanknutzung",
|
||||
"DataSize": "Datenmenge",
|
||||
"DBSize": "Datenbankgröße",
|
||||
"EstimatedSize": "Erwartete Größe",
|
||||
"IndexSize": "Indexgröße",
|
||||
"LearnMore": "Um mehr darüber zu erfahren, wie Piwik Daten verarbeitet und wie Sie Piwik auf stark besuchten Webseiten einsetzen können, lesen Sie die Dokumentation unter %s.",
|
||||
"MainDescription": "Piwik speichert sämtliche Webanalyse-Daten in der MySQL-Datenbank. Aktuell belegter Speicherplatz %s.",
|
||||
"MetricDataByYear": "Metriktabellen pro Jahr",
|
||||
"MetricTables": "Metriktabellen",
|
||||
"OtherTables": "Andere Tabellen",
|
||||
"PluginDescription": "Dieses Plugin berichtet über die Nutzung und Auslastung der Piwik-Tabellen in der MySQL Datenbank.",
|
||||
"ReportDataByYear": "Berichtstabellen pro Jahr",
|
||||
"ReportTables": "Berichtstabellen",
|
||||
"RowCount": "Zeilenanzahl",
|
||||
"Table": "Tabelle",
|
||||
"TotalSize": "Gesamtgröße",
|
||||
"TrackerTables": "Trackertabellen"
|
||||
}
|
||||
}
|
||||
21
www/analytics/plugins/DBStats/lang/el.json
Normal file
21
www/analytics/plugins/DBStats/lang/el.json
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"DBStats": {
|
||||
"DatabaseUsage": "Χρήση βάσης δεδομένων",
|
||||
"DataSize": "Μέγεθος δεδομένων",
|
||||
"DBSize": "Μέγεθος Βάσης Δεδομένων",
|
||||
"EstimatedSize": "Εκτιμόμενο μέγεθος",
|
||||
"IndexSize": "Μέγεθος ευρετηρίου",
|
||||
"LearnMore": "Για να μάθετε περισσότερα για τη διαχείριση δεδομένων του Piwik και πως να κάνετε το Piwik να λειτουργεί καλά για ιστοσελίδες μέσης και υψηλής επισκεψιμότητας, δείτε την τεκμηρίωση %s.",
|
||||
"MainDescription": "Το Piwik αποθηκεύει όλα τα δεδομένα της ανάλυσης στη βάση δεδομένων της Mysql. Τώρα, οι πίνακες του Piwik χρησιμοποιούν %s.",
|
||||
"MetricDataByYear": "Πίνακες Μετρήσεων Κατά Έτος",
|
||||
"MetricTables": "Πίνακες Μετρήσεων",
|
||||
"OtherTables": "Άλλοι Πίνακες",
|
||||
"PluginDescription": "Αυτό το πρόσθετο δίνει αναφορά για τη χρήση της βάσης δεδομένων MySQL από τους πίνακες του Piwik.",
|
||||
"ReportDataByYear": "Πίνακες αναφοράς Κατά Έτος",
|
||||
"ReportTables": "Πίνακες Αναφοράς",
|
||||
"RowCount": "Αριθμός σειρών",
|
||||
"Table": "Πίνακας",
|
||||
"TotalSize": "Συνολικό μέγεθος",
|
||||
"TrackerTables": "Πίνακες Καταγραφής"
|
||||
}
|
||||
}
|
||||
21
www/analytics/plugins/DBStats/lang/en.json
Normal file
21
www/analytics/plugins/DBStats/lang/en.json
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"DBStats": {
|
||||
"PluginDescription": "This plugin reports the MySQL database usage by Piwik tables.",
|
||||
"DatabaseUsage": "Database usage",
|
||||
"MainDescription": "Piwik stores all your web analytics data in a MySQL database. Currently, Piwik tables take up %s of space.",
|
||||
"LearnMore": "To learn more about how Piwik processes data and how to make Piwik work well with medium and high traffic websites, see this documentation: %s.",
|
||||
"Table": "Table",
|
||||
"RowCount": "Row count",
|
||||
"DataSize": "Data size",
|
||||
"IndexSize": "Index size",
|
||||
"TotalSize": "Total size",
|
||||
"DBSize": "DB size",
|
||||
"ReportDataByYear": "Report Tables By Year",
|
||||
"MetricDataByYear": "Metric Tables By Year",
|
||||
"EstimatedSize": "Estimated size",
|
||||
"TrackerTables": "Tracker Tables",
|
||||
"ReportTables": "Report Tables",
|
||||
"MetricTables": "Metric Tables",
|
||||
"OtherTables": "Other Tables"
|
||||
}
|
||||
}
|
||||
21
www/analytics/plugins/DBStats/lang/es.json
Normal file
21
www/analytics/plugins/DBStats/lang/es.json
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"DBStats": {
|
||||
"DatabaseUsage": "Uso de la base de datos",
|
||||
"DataSize": "Tamaño de los datos",
|
||||
"DBSize": "Tamaño BD",
|
||||
"EstimatedSize": "Tamaño estimado",
|
||||
"IndexSize": "Tamaño del índice",
|
||||
"LearnMore": "Para aprender más sobre cómo Piwik procesa los datos y cómo hacer que Piwik funcione bien para sitios web de mediano y grande trafico, eche un vistazo a la documentación %s.",
|
||||
"MainDescription": "Piwik está almacenando todos sus datos de análisis web en la base de datos MySQL. Actualmente, las tablas de Piwik están usando %s.",
|
||||
"MetricDataByYear": "Tablas de Medición Anuales",
|
||||
"MetricTables": "Tablas de Medición",
|
||||
"OtherTables": "Otras tablas",
|
||||
"PluginDescription": "Este plugin reporta el uso de la base de datos MySQL de las tablas de Piwik.",
|
||||
"ReportDataByYear": "Reporte de Tablas Anual",
|
||||
"ReportTables": "Tablas de reportes",
|
||||
"RowCount": "Cantidad de filas",
|
||||
"Table": "Tabla",
|
||||
"TotalSize": "Tamaño total",
|
||||
"TrackerTables": "Tablas de Rastreadores"
|
||||
}
|
||||
}
|
||||
21
www/analytics/plugins/DBStats/lang/et.json
Normal file
21
www/analytics/plugins/DBStats/lang/et.json
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"DBStats": {
|
||||
"DatabaseUsage": "Andmebaasi kasutus",
|
||||
"DataSize": "Andmemaht",
|
||||
"DBSize": "Andmebaasi suurus",
|
||||
"EstimatedSize": "Ennustatud maht",
|
||||
"IndexSize": "Indeksi maht",
|
||||
"LearnMore": "Et saada rohkem infot, kuidas Piwik töötleb andmeid ja kuidas optimeerida Piwikut tööks keskmise ja kõrge külastatavusega veebilehtedele, vaata seda dokumentatsiooni: %s.",
|
||||
"MainDescription": "Piwik salvestab kõik veebianalüütika andmed MySQL andmebaasi. Piwiku tabelid kasutavad hetkel %s.",
|
||||
"MetricDataByYear": "Mõõttabelid aasta järgi",
|
||||
"MetricTables": "Mõõttabelid",
|
||||
"OtherTables": "Muud tabelid",
|
||||
"PluginDescription": "Antud lisatarkvara raporteerib Piwiku tabelite MySQL andmebaasi kasutust.",
|
||||
"ReportDataByYear": "Raporti tabelid aasta järgi",
|
||||
"ReportTables": "Raporti tabelid",
|
||||
"RowCount": "Ridade arv",
|
||||
"Table": "Tabel",
|
||||
"TotalSize": "Kogusuurus",
|
||||
"TrackerTables": "Jälitustabelid"
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue