You are here

public function SystemMemorySensorPlugin::resultVerbose in Monitoring 8

Provide additional info about sensor call.

This method is only executed on request. It is guaranteed that runSensor() is executed before this method.

Parameters

\Drupal\monitoring\Result\SensorResultInterface $result: Sensor result.

Return value

array Sensor call verbose info as render array.

Overrides ExtendedInfoSensorPluginInterface::resultVerbose

File

src/Plugin/monitoring/SensorPlugin/SystemMemorySensorPlugin.php, line 156

Class

SystemMemorySensorPlugin
Monitors system memory.

Namespace

Drupal\monitoring\Plugin\monitoring\SensorPlugin

Code

public function resultVerbose(SensorResultInterface $result) {
  $data = $this
    ->readMemInfo();
  $data = explode("\n", $data);
  $rows = [];
  foreach ($data as $line) {
    list($key, $val) = array_pad(explode(':', $line, 2), 2, NULL);
    if (trim($key)) {
      $rows[] = [
        'type' => $key,
        'memory' => trim($val),
      ];
    }
  }
  $output = NULL;
  if (count($rows) > 0) {
    $header = [
      'type' => $this
        ->t('Type'),
      'memory' => $this
        ->t('Memory'),
    ];
    $output['memory_info'] = [
      '#type' => 'verbose_table_result',
      '#title' => $this
        ->t('Memory information'),
      '#header' => $header,
      '#rows' => $rows,
    ];
  }
  return $output;
}