You are here

public function SolrDiskUsageSensorPlugin::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/SolrDiskUsageSensorPlugin.php, line 97

Class

SolrDiskUsageSensorPlugin
Monitors the Solr disk usage.

Namespace

Drupal\monitoring\Plugin\monitoring\SensorPlugin

Code

public function resultVerbose(SensorResultInterface $result) {
  $output = [];
  if (!($solr_info = $this
    ->getSolrInfo())) {
    return $output;
  }
  $output['tables_usage'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t("Solr server: @server_name, host: @host, core: @core", [
      '@server_name' => $solr_info['server_name'],
      '@host' => $solr_info['host'],
      '@core' => $solr_info['core'],
    ]),
  ];
  $total_physical_memory = $solr_info['total_physical_memory'];
  $free_physical_memory = $solr_info['free_physical_memory'];
  $physical_memory_usage_percentage = ($total_physical_memory - $free_physical_memory) * 100 / $total_physical_memory;
  $total_swap_memory = $solr_info['total_swap_memory'];
  $free_swap_memory = $solr_info['free_swap_memory'];
  $swap_memory_usage_percentage = ($total_swap_memory - $free_swap_memory) * 100 / $total_physical_memory;
  $output['tables_usage']['table'] = [
    '#type' => 'table',
    '#header' => [
      'index_size' => [
        'data' => $this
          ->t('Index size'),
      ],
      'index_docs' => [
        'data' => $this
          ->t('Indexed docs'),
      ],
      'physical_memory' => [
        'data' => $this
          ->t('Physical memory (@total available)', [
          '@total' => format_size($total_physical_memory),
        ]),
        'class' => [
          RESPONSIVE_PRIORITY_LOW,
        ],
      ],
      'swap_space' => [
        'data' => $this
          ->t('Swap memory (@total available)', [
          '@total' => format_size($total_swap_memory),
        ]),
        'class' => [
          RESPONSIVE_PRIORITY_LOW,
        ],
      ],
    ],
  ];
  $output['tables_usage']['table'][0]['index_size'] = [
    '#type' => 'item',
    '#plain_text' => $this
      ->getSolrIndexSize(),
  ];
  $output['tables_usage']['table'][0]['index_docs'] = [
    '#type' => 'item',
    '#plain_text' => $solr_info['indexed_docs'],
  ];
  $output['tables_usage']['table'][0]['physical_memory'] = [
    '#type' => 'item',
    '#plain_text' => $this
      ->t('@used (@percentage%) used', [
      '@used' => format_size($total_physical_memory - $free_physical_memory),
      '@percentage' => number_format($physical_memory_usage_percentage, 2),
    ]),
  ];
  $output['tables_usage']['table'][0]['swap_space'] = [
    '#type' => 'item',
    '#plain_text' => $this
      ->t('@used (@percentage%) used', [
      '@used' => format_size($total_swap_memory - $free_swap_memory),
      '@percentage' => number_format($swap_memory_usage_percentage, 2),
    ]),
  ];
  return $output;
}