Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordiosmosis <diosmosis@users.noreply.github.com>2019-03-13 02:16:41 +0300
committerGitHub <noreply@github.com>2019-03-13 02:16:41 +0300
commite26f5e7a359e990b4c4d726de85839e8923619ab (patch)
treec142c489e7c600adef97b7d5ada7bef1f5cdea83 /plugins/Diagnostics
parent549578d0d34d15bfe4f1048225e29a2e5ad2fb4d (diff)
Add diagnostic to check last time archiving was run successfully and … (#13972)
* Add diagnostic to check last time archiving was run successfully and display notification if empty report and archiving has not been run recently. * Move cron archiving diagnostics next to each other. * Add new test for archiving not done in time check. * Remove TODO comment.
Diffstat (limited to 'plugins/Diagnostics')
-rw-r--r--plugins/Diagnostics/Diagnostic/CronArchivingLastRunCheck.php104
-rw-r--r--plugins/Diagnostics/Diagnostics.php35
-rw-r--r--plugins/Diagnostics/config/config.php3
-rw-r--r--plugins/Diagnostics/lang/en.json11
4 files changed, 151 insertions, 2 deletions
diff --git a/plugins/Diagnostics/Diagnostic/CronArchivingLastRunCheck.php b/plugins/Diagnostics/Diagnostic/CronArchivingLastRunCheck.php
new file mode 100644
index 0000000000..b5e47b62de
--- /dev/null
+++ b/plugins/Diagnostics/Diagnostic/CronArchivingLastRunCheck.php
@@ -0,0 +1,104 @@
+<?php
+/**
+ * Piwik - free/libre analytics platform
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ *
+ */
+namespace Piwik\Plugins\Diagnostics\Diagnostic;
+
+use Piwik\ArchiveProcessor\Rules;
+use Piwik\Config;
+use Piwik\CronArchive;
+use Piwik\Date;
+use Piwik\Metrics\Formatter;
+use Piwik\Option;
+use Piwik\Plugins\Intl\DateTimeFormatProvider;
+use Piwik\Translation\Translator;
+
+/**
+ * Check if cron archiving has run in the last 24-48 hrs.
+ */
+class CronArchivingLastRunCheck implements Diagnostic
+{
+ const SECONDS_IN_DAY = 86400;
+
+ /**
+ * @var Translator
+ */
+ private $translator;
+
+ public function __construct(Translator $translator)
+ {
+ $this->translator = $translator;
+ }
+
+ public function execute()
+ {
+ $label = $this->translator->translate('Diagnostics_CronArchivingLastRunCheck');
+ $commandToRerun = '<code>' . $this->getArchivingCommand() . '</code>';
+ $coreArchiveShort = '<code>core:archive</code>';
+ $mailto = '<code>MAILTO</code>';
+
+ // check cron archiving has been enabled
+ $isBrowserTriggerDisabled = !Rules::isBrowserTriggerEnabled();
+ if (!$isBrowserTriggerDisabled) {
+ $comment = $this->translator->translate('Diagnostics_BrowserTriggeredArchivingEnabled', [
+ '<a href="https://matomo.org/docs/setup-auto-archiving/" target="_blank" rel="noreferrer noopener">', '</a>']);
+ return [DiagnosticResult::singleResult($label, DiagnosticResult::STATUS_WARNING, $comment)];
+ }
+
+ // check archiving has been run
+ $lastRunTime = (int)Option::get(CronArchive::OPTION_ARCHIVING_FINISHED_TS);
+ if (empty($lastRunTime)) {
+ $comment = $this->translator->translate('Diagnostics_CronArchivingHasNotRun')
+ . '<br/><br/>' . $this->translator->translate('Diagnostics_CronArchivingRunDetails', [$coreArchiveShort, $mailto, $commandToRerun]);;
+ return [DiagnosticResult::singleResult($label, DiagnosticResult::STATUS_ERROR, $comment)];
+ }
+
+ $lastRunTimePretty = Date::factory($lastRunTime)->getLocalized(DateTimeFormatProvider::DATETIME_FORMAT_LONG);
+
+ $diffTime = self::getTimeSinceLastSuccessfulRun($lastRunTime);
+
+ $formatter = new Formatter();
+ $diffTimePretty = $formatter->getPrettyTimeFromSeconds($diffTime);
+
+ $errorComment = $this->translator->translate('Diagnostics_CronArchivingHasNotRunInAWhile', [$lastRunTimePretty, $diffTimePretty])
+ . '<br/><br/>' . $this->translator->translate('Diagnostics_CronArchivingRunDetails', [$coreArchiveShort, $mailto, $commandToRerun]);
+
+ // check archiving has been run recently
+ if ($diffTime > self::SECONDS_IN_DAY * 2) {
+ $result = DiagnosticResult::singleResult($label, DiagnosticResult::STATUS_ERROR, $errorComment);
+ } else if ($diffTime > self::SECONDS_IN_DAY) {
+ $result = DiagnosticResult::singleResult($label, DiagnosticResult::STATUS_WARNING, $errorComment);
+ } else {
+ $comment = $this->translator->translate('Diagnostics_CronArchivingRanSuccessfullyXAgo', $diffTimePretty);
+ $result = DiagnosticResult::singleResult($label, DiagnosticResult::STATUS_OK, $comment);
+ }
+
+ return [$result];
+ }
+
+ private function getArchivingCommand()
+ {
+ $domain = Config::getHostname();
+ return PIWIK_INCLUDE_PATH . ' --matomo-domain=' . $domain . ' core:archive';
+ }
+
+ public static function getTimeSinceLastSuccessfulRun($lastRunTime = null)
+ {
+ if (empty($lastRunTime)) {
+ $lastRunTime = (int)Option::get(CronArchive::OPTION_ARCHIVING_FINISHED_TS);
+ }
+
+ if (empty($lastRunTime)) {
+ return null;
+ }
+
+ $now = Date::now()->getTimestamp();
+ $diffTime = $now - $lastRunTime;
+
+ return $diffTime;
+ }
+}
diff --git a/plugins/Diagnostics/Diagnostics.php b/plugins/Diagnostics/Diagnostics.php
index 9760be5b05..e588af1fbe 100644
--- a/plugins/Diagnostics/Diagnostics.php
+++ b/plugins/Diagnostics/Diagnostics.php
@@ -8,10 +8,17 @@
namespace Piwik\Plugins\Diagnostics;
+use Piwik\ArchiveProcessor\Rules;
+use Piwik\Notification;
+use Piwik\Piwik;
use Piwik\Plugin;
+use Piwik\Plugins\Diagnostics\Diagnostic\CronArchivingLastRunCheck;
+use Piwik\View;
class Diagnostics extends Plugin
{
+ const NO_DATA_ARCHIVING_NOT_RUN_NOTIFICATION_ID = 'DiagnosticsNoDataArchivingNotRun';
+
/**
* @see Piwik\Plugin::registerEvents
*/
@@ -19,6 +26,7 @@ class Diagnostics extends Plugin
{
return array(
'AssetManager.getStylesheetFiles' => 'getStylesheetFiles',
+ 'Visualization.onNoData' => ['function' => 'onNoData', 'before' => true],
);
}
@@ -27,4 +35,31 @@ class Diagnostics extends Plugin
$stylesheets[] = "plugins/Diagnostics/stylesheets/configfile.less";
}
+ public function onNoData(View $dataTableView)
+ {
+ if (!Piwik::isUserHasSomeAdminAccess()) {
+ return;
+ }
+
+ if (Rules::isBrowserTriggerEnabled()) {
+ return;
+ }
+
+ $lastSuccessfulRun = CronArchivingLastRunCheck::getTimeSinceLastSuccessfulRun();
+ if ($lastSuccessfulRun > CronArchivingLastRunCheck::SECONDS_IN_DAY) {
+ $content = Piwik::translate('Diagnostics_NoDataForReportArchivingNotRun', [
+ '<a href="https://matomo.org/docs/setup-auto-archiving/" target="_blank" rel="noreferrer noopener">',
+ '</a>',
+ ]);
+
+ $notification = new Notification($content);
+ $notification->priority = Notification::PRIORITY_HIGH;
+ $notification->context = Notification::CONTEXT_INFO;
+ $notification->flags = Notification::FLAG_NO_CLEAR;
+ $notification->type = Notification::TYPE_TRANSIENT;
+ $notification->raw = true;
+
+ $dataTableView->notifications[self::NO_DATA_ARCHIVING_NOT_RUN_NOTIFICATION_ID] = $notification;
+ }
+ }
}
diff --git a/plugins/Diagnostics/config/config.php b/plugins/Diagnostics/config/config.php
index 0a7c51bf72..b450de958a 100644
--- a/plugins/Diagnostics/config/config.php
+++ b/plugins/Diagnostics/config/config.php
@@ -1,5 +1,7 @@
<?php
+use Piwik\Plugins\Diagnostics\Diagnostic\CronArchivingLastRunCheck;
+
return array(
// Diagnostics for everything that is required for Piwik to run
'diagnostics.required' => array(
@@ -23,6 +25,7 @@ return array(
DI\get('Piwik\Plugins\Diagnostics\Diagnostic\RecommendedFunctionsCheck'),
DI\get('Piwik\Plugins\Diagnostics\Diagnostic\NfsDiskCheck'),
DI\get('Piwik\Plugins\Diagnostics\Diagnostic\CronArchivingCheck'),
+ DI\get(CronArchivingLastRunCheck::class),
DI\get('Piwik\Plugins\Diagnostics\Diagnostic\LoadDataInfileCheck'),
Di\get('Piwik\Plugins\Diagnostics\Diagnostic\DbOverSSLCheck'),
Di\get('Piwik\Plugins\Diagnostics\Diagnostic\DbMaxPacket'),
diff --git a/plugins/Diagnostics/lang/en.json b/plugins/Diagnostics/lang/en.json
index 5accb4c430..d228ab5c83 100644
--- a/plugins/Diagnostics/lang/en.json
+++ b/plugins/Diagnostics/lang/en.json
@@ -5,6 +5,13 @@
"MysqlMaxPacketSizeWarning": "It is recommended to configure a 'max_allowed_packet' size in your MySQL database of at least %1$s. Configured is currently %2$s.",
"ConfigFileIntroduction": "Here you can view the Matomo configuration. If you are running Matomo in a load balanced environment the page might be different depending from which server this page is loaded. Rows with a different background color are changed config values that are specified for example in the %1$s file.",
"HideUnchanged": "If you want to see only changed values you can %1$shide all unchanged values%2$s.",
- "Sections": "Sections"
+ "Sections": "Sections",
+ "CronArchivingLastRunCheck": "Last Successful Archiving Completion",
+ "CronArchivingHasNotRun": "Archiving has not yet run successfully.",
+ "CronArchivingHasNotRunInAWhile": "Archiving last ran successfully on %1$s which is %2$s ago.",
+ "CronArchivingRunDetails": "Please check that you have setup a crontab calling the %1$s console command, and that you have configured a %2$s to receive errors by email if archiving fails. You can also try to run the console command to archive your reports manually: %3$s",
+ "CronArchivingRanSuccessfullyXAgo": "The archiving process completed successfully %1$s ago.",
+ "BrowserTriggeredArchivingEnabled": "For optimal performance and a speedy Matomo, it is highly recommended to set up a crontab to automatically archive your reports, and to disable browser triggering in the Matomo settings. %1$sLearn more.%2$s",
+ "NoDataForReportArchivingNotRun": "The archiving of your reports hasn't been executed recently, %1$slearn more about how to generate your reports.%2$s"
}
-}
+} \ No newline at end of file