diff --git a/README.md b/README.md index f62ab4c..efd47f4 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ requirements, like availability of PHP extensions. - **DoctrineMigrations:** Checks whether all Doctrine Migrations have been migrated. - **HostingSize:** Checks how much Disk space is used by this hosting. - **DatabaseSize:** Checks how much space the Database uses on this hosting. +- **DatabaseTableSize:** Checks how much space each Database Table uses on this hosting. - **HttpsConnection:** Checks whether the HTTPS encryption is enabled. - **MySqlVersion:** Checks what MySQL version is configured. - **PhpVersion:** Checks what PHP version is configured. @@ -27,6 +28,7 @@ requirements, like availability of PHP extensions. * [Installation & Bundle Configuration](docs/00-installation-configuration.md) * [Adding and Running Checks](docs/01-adding-custom-checks.md) * [Commands](docs/02-commands.md) +* [Defaults](docs/03-defaults.md) ## License **w-vision AG**, Sandgruebestrasse 4, 6210 Sursee, Switzerland diff --git a/docs/03-defaults.md b/docs/03-defaults.md new file mode 100644 index 0000000..5d678f2 --- /dev/null +++ b/docs/03-defaults.md @@ -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 +``` diff --git a/src/PimcoreMonitorBundle/Check/DatabaseSize.php b/src/PimcoreMonitorBundle/Check/DatabaseSize.php index 7767d56..3126f57 100644 --- a/src/PimcoreMonitorBundle/Check/DatabaseSize.php +++ b/src/PimcoreMonitorBundle/Check/DatabaseSize.php @@ -11,7 +11,7 @@ * 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) 2022 w-vision AG (https://www.w-vision.ch) + * @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) */ diff --git a/src/PimcoreMonitorBundle/Check/DatabaseTableSize.php b/src/PimcoreMonitorBundle/Check/DatabaseTableSize.php new file mode 100644 index 0000000..8b4c8a9 --- /dev/null +++ b/src/PimcoreMonitorBundle/Check/DatabaseTableSize.php @@ -0,0 +1,115 @@ +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); + } +} diff --git a/src/PimcoreMonitorBundle/DependencyInjection/Configuration.php b/src/PimcoreMonitorBundle/DependencyInjection/Configuration.php index a7e96a1..5cc3a08 100644 --- a/src/PimcoreMonitorBundle/DependencyInjection/Configuration.php +++ b/src/PimcoreMonitorBundle/DependencyInjection/Configuration.php @@ -181,6 +181,31 @@ private function buildChecksNode(): NodeDefinition ->end() ->end() ->end() + ->arrayNode('database_table_size') + ->addDefaultsIfNotSet() + ->children() + ->booleanNode('enabled') + ->info('Enables this check globally.') + ->defaultValue(true) + ->end() + ->booleanNode('skip') + ->info('Skips this check globally.') + ->defaultValue(false) + ->end() + ->integerNode('warning_threshold') + ->info('The warning threshold for all database tables size in bytes.') + ->defaultValue(94371840) + ->isRequired() + ->min(0) + ->end() + ->integerNode('critical_threshold') + ->info('The critical threshold for all database tables size in bytes.') + ->defaultValue(104857600) + ->isRequired() + ->min(0) + ->end() + ->end() + ->end() ->arrayNode('https_connection') ->addDefaultsIfNotSet() ->children() diff --git a/src/PimcoreMonitorBundle/Resources/config/services/checks.yaml b/src/PimcoreMonitorBundle/Resources/config/services/checks.yaml index f7a8e30..908ee17 100644 --- a/src/PimcoreMonitorBundle/Resources/config/services/checks.yaml +++ b/src/PimcoreMonitorBundle/Resources/config/services/checks.yaml @@ -46,6 +46,16 @@ services: tags: - { name: pimcore_monitor.check, alias: database_size } + # Database Table Size Check + Wvision\Bundle\PimcoreMonitorBundle\Check\DatabaseTableSize: + arguments: + - '%pimcore_monitor.checks.database_table_size.skip%' + - '%pimcore_monitor.checks.database_table_size.warning_threshold%' + - '%pimcore_monitor.checks.database_table_size.critical_threshold%' + - '@doctrine.dbal.default_connection' + tags: + - { name: pimcore_monitor.check, alias: database_table_size } + # HTTPS Connection Check Wvision\Bundle\PimcoreMonitorBundle\Check\HttpsConnection: arguments: