You are here

public function SolrDiskUsageSensorPlugin::convertToMegabyte in Monitoring 8

Converts human readable size to megabytes.

Parameters

string $value: The human readable size (10 MB, 1 gb, 100 bytes) to be converted. There needs to be a space between the number and type.

Return value

string|null Returns the megabyte value or NULL.

1 call to SolrDiskUsageSensorPlugin::convertToMegabyte()
SolrDiskUsageSensorPlugin::runSensor in src/Plugin/monitoring/SensorPlugin/SolrDiskUsageSensorPlugin.php
Runs the sensor, updating $sensor_result.

File

src/Plugin/monitoring/SensorPlugin/SolrDiskUsageSensorPlugin.php, line 322

Class

SolrDiskUsageSensorPlugin
Monitors the Solr disk usage.

Namespace

Drupal\monitoring\Plugin\monitoring\SensorPlugin

Code

public function convertToMegabyte($value) {
  $number = explode(' ', trim($value))[0];
  $type = explode(' ', trim($value))[1];
  switch (strtoupper($type)) {
    case "BYTES":
      return $number / 1024 / 1024;
    case "KB":
      return $number / 1024;
    case "MB":
      return $number;
    case "GB":
      return $number * 1024;
    case "TB":
      return $number * pow(1024, 2);
    case "PB":
      return $number * pow(1024, 3);
    default:
      return NULL;
  }
}