-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from w-vision/feat/database-table-size-check
Feat/database table size check
- Loading branch information
Showing
6 changed files
with
221 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Defaults | ||
|
||
```yaml | ||
pimcore_monitor: | ||
checks: | ||
app_environment: | ||
enabled: true | ||
skip: false | ||
environment: '%kernel.environment%' | ||
disk_usage: | ||
enabled: true | ||
skip: false | ||
warning_threshold: 90 # percentage | ||
critical_threshold: 95 # percentage | ||
path: '%kernel.project_dir%' | ||
doctrine_migrations: | ||
enabled: true | ||
skip: false | ||
hosting_size: | ||
enabled: true | ||
skip: false | ||
warning_threshold: 48318382080 # 45 GB | ||
critical_threshold: 53687091200 # 50 GB | ||
path: '%kernel.project_dir%' | ||
database_size: | ||
enabled: true | ||
skip: false | ||
warning_threshold: 964689920 # 920 MB | ||
critical_threshold: 1073741824 # 1 GB | ||
database_table_size: | ||
enabled: true | ||
skip: false | ||
warning_threshold: 94371840 # 90 MB | ||
critical_threshold: 104857600 # 100 MB | ||
https_connection: | ||
enabled: true | ||
skip: false | ||
mysql_version: | ||
enabled: true | ||
skip: false | ||
version: '10.5' | ||
operator: '>=' | ||
php_version: | ||
enabled: true | ||
skip: false | ||
version: '8.0' | ||
operator: '>=' | ||
pimcore_areabricks: | ||
enabled: true | ||
skip: false | ||
pimcore_bundles: | ||
enabled: true | ||
skip: false | ||
pimcore_element_count: | ||
enabled: true | ||
skip: false | ||
warning_threshold: 100000 | ||
critical_threshold: 150000 | ||
pimcore_maintenance: | ||
enabled: true | ||
skip: false | ||
pimcore_users: | ||
enabled: true | ||
skip: false | ||
pimcore_version: | ||
enabled: true | ||
skip: false | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore Monitor | ||
* | ||
* LICENSE | ||
* | ||
* This source file is subject to the GNU General Public License version 3 (GPLv3) | ||
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt | ||
* files that are distributed with this source code. | ||
* | ||
* @copyright Copyright (c) 2023 w-vision AG (https://www.w-vision.ch) | ||
* @license https://github.com/w-vision/PimcoreMonitorBundle/blob/master/gpl-3.0.txt GNU General Public License version 3 (GPLv3) | ||
*/ | ||
|
||
namespace Wvision\Bundle\PimcoreMonitorBundle\Check; | ||
|
||
use Doctrine\DBAL\Connection; | ||
use Laminas\Diagnostics\Result\Failure; | ||
use Laminas\Diagnostics\Result\ResultInterface; | ||
use Laminas\Diagnostics\Result\Skip; | ||
use Laminas\Diagnostics\Result\Success; | ||
use Laminas\Diagnostics\Result\Warning; | ||
|
||
class DatabaseTableSize extends AbstractCheck | ||
{ | ||
protected const IDENTIFIER = 'device:database_table_size'; | ||
|
||
public function __construct( | ||
protected bool $skip, | ||
protected int $warningThreshold, | ||
protected int $criticalThreshold, | ||
protected Connection $connection | ||
) {} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function check(): ResultInterface | ||
{ | ||
if ($this->skip) { | ||
return new Skip('Check was skipped'); | ||
} | ||
|
||
$sizes = $this->getDatabaseTableSizes(); | ||
|
||
if (!\is_array($sizes)) { | ||
return new Failure('Database table sizes could not be retrieved'); | ||
} | ||
|
||
$data = [ | ||
'ok' => 0, | ||
'warning' => [], | ||
'critical' => [], | ||
]; | ||
|
||
foreach ($sizes as $size) { | ||
if ($size['size'] >= $this->criticalThreshold) { | ||
$data['critical'][$size['table']] = \formatBytes($size['size']); | ||
continue; | ||
} | ||
|
||
if ($size['size'] >= $this->warningThreshold) { | ||
$data['warning'][$size['table']] = \formatBytes($size['size']); | ||
continue; | ||
} | ||
|
||
++$data['ok']; | ||
} | ||
|
||
if (\count($data['critical']) > 0) { | ||
return new Failure( | ||
\sprintf( | ||
'Following database table sizes are too high: %s', | ||
\implode(',', \array_keys($data['critical']))), | ||
$data | ||
); | ||
} | ||
|
||
if (\count($data['warning']) > 0) { | ||
return new Warning( | ||
\sprintf( | ||
'Following database table sizes are high: %s', | ||
\implode(',', \array_keys($data['warning']))), | ||
$data | ||
); | ||
} | ||
|
||
return new Success('All database table sizes are ok.', $data); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getLabel(): string | ||
{ | ||
return 'Database Table Size'; | ||
} | ||
|
||
/** | ||
* Returns the sizes of the connected database tables | ||
*/ | ||
private function getDatabaseTableSizes(): ?array | ||
{ | ||
$query = "SELECT TABLE_NAME AS `table`, | ||
(DATA_LENGTH + INDEX_LENGTH) AS `size` | ||
FROM information_schema.TABLES | ||
ORDER BY | ||
(DATA_LENGTH + INDEX_LENGTH) | ||
DESC;"; | ||
return $this->connection->fetchAll($query); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters