protected function DatabaseDiskUsagePlugin::getDiskUsage in Monitoring 8
Gets the database disk space usage in megabytes.
Return value
string|null Returns the disk usage or NULL.
2 calls to DatabaseDiskUsagePlugin::getDiskUsage()
- DatabaseDiskUsagePlugin::resultVerbose in src/
Plugin/ monitoring/ SensorPlugin/ DatabaseDiskUsagePlugin.php - Provide additional info about sensor call.
- DatabaseDiskUsagePlugin::runSensor in src/
Plugin/ monitoring/ SensorPlugin/ DatabaseDiskUsagePlugin.php - Runs the sensor, updating $sensor_result.
File
- src/
Plugin/ monitoring/ SensorPlugin/ DatabaseDiskUsagePlugin.php, line 189
Class
- DatabaseDiskUsagePlugin
- Monitors database disk usage.
Namespace
Drupal\monitoring\Plugin\monitoring\SensorPluginCode
protected function getDiskUsage() {
// Condition is used to simulate data for purpose of testing.
$test_usage = $this->state
->get('monitoring.test_database_disk_usage');
if (isset($test_usage)) {
return $test_usage;
}
if ($this->database
->databaseType() !== 'mysql') {
throw new \RuntimeException($this
->t('The table information is only available for mysql databases.'));
}
$result = $this->database
->query("SELECT SUM(data_length + index_length + data_free) / 1048576 AS disk_used\n FROM information_schema.tables")
->fetch();
return $result->disk_used;
}