class SensorList in Monitoring 8
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements ContainerInjectionInterface uses LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\monitoring\Controller\SensorList
Expanded class hierarchy of SensorList
File
- src/
Controller/ SensorList.php, line 12
Namespace
Drupal\monitoring\ControllerView source
class SensorList extends ControllerBase {
/**
* The sensor runner.
*
* @var \Drupal\monitoring\SensorRunner
*/
protected $sensorRunner;
/**
* The sensor manager.
*
* @var \Drupal\monitoring\Sensor\SensorManager
*/
protected $sensorManager;
/**
* Constructs a \Drupal\monitoring\Form\SensorDetailForm object.
*
* @param \Drupal\monitoring\SensorRunner $sensor_runner
* The factory for configuration objects.
* @param \Drupal\monitoring\Sensor\SensorManager $sensor_manager
* The sensor manager service.
*/
public function __construct(SensorRunner $sensor_runner, SensorManager $sensor_manager) {
$this->sensorRunner = $sensor_runner;
$this->sensorManager = $sensor_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('monitoring.sensor_runner'), $container
->get('monitoring.sensor_manager'));
}
public function content() {
$rows = array();
$results = $this->sensorRunner
->runSensors();
$status_overview = array(
SensorResultInterface::STATUS_OK => 0,
SensorResultInterface::STATUS_INFO => 0,
SensorResultInterface::STATUS_WARNING => 0,
SensorResultInterface::STATUS_CRITICAL => 0,
SensorResultInterface::STATUS_UNKNOWN => 0,
);
$total_execution_time = 0;
$non_cached_execution_time = 0;
// Oldest sensor age in seconds.
$oldest_sensor_age = 0;
// Oldest sensor config.
$oldest_sensor_config = NULL;
foreach ($this->sensorManager
->getSensorConfigByCategories() as $category => $category_sensor_config) {
// Category grouping row.
$rows[] = array(
'data' => array(
'label' => array(
'data' => array(
'#markup' => '<h3>' . $category . '</h3>',
),
'colspan' => 7,
),
),
);
$ok_row_count = 0;
/** @var \Drupal\monitoring\SensorConfigInterface $sensor_config */
foreach ($category_sensor_config as $sensor_name => $sensor_config) {
if (!isset($results[$sensor_name])) {
continue;
}
/** @var \Drupal\monitoring\Result\SensorResultInterface $sensor_result */
$sensor_result = $results[$sensor_name];
$called_before = \Drupal::time()
->getRequestTime() - $sensor_result
->getTimestamp();
if ($called_before > $oldest_sensor_age) {
$oldest_sensor_config = $sensor_config;
$oldest_sensor_age = $called_before;
}
$row['data']['label']['data'] = array(
'#markup' => '<span title="' . $sensor_config
->getDescription() . '">' . $sensor_config
->getLabel() . '</span>',
);
$row['data']['sensor_status'] = array(
'data' => $sensor_result
->getStatus(),
'class' => array(
'status',
),
);
$row['data']['timestamp'] = \Drupal::service('date.formatter')
->formatInterval(\Drupal::time()
->getRequestTime() - $sensor_result
->getTimestamp());
$row['data']['execution_time'] = array(
'data' => $sensor_result
->getExecutionTime() . 'ms',
'class' => array(
'execution-time',
),
);
$row['data']['sensor_status_message'] = Unicode::truncate(strip_tags($sensor_result
->getMessage()), 200, TRUE, TRUE);
$row['class'] = array(
'monitoring-' . strtolower($sensor_result
->getStatus()),
);
$links = array();
$links['details'] = array(
'title' => t('Details'),
'url' => $sensor_config
->toUrl('details-form'),
);
// Display a force execution link for any sensor that can be cached.
if ($sensor_config
->getCachingTime() && $this
->currentUser()
->hasPermission('monitoring force run')) {
$links['force_execution'] = array(
'title' => t('Force execution'),
'url' => $sensor_config
->toUrl('force-run-sensor'),
);
}
$links['edit'] = array(
'title' => t('Edit'),
'url' => $sensor_config
->toUrl('edit-form'),
'query' => array(
'destination' => 'admin/reports/monitoring',
),
);
\Drupal::moduleHandler()
->alter('monitoring_sensor_links', $links, $sensor_config);
$row['data']['actions'] = array();
if (!empty($links)) {
$row['data']['actions']['data'] = array(
'#type' => 'dropbutton',
'#links' => $links,
);
}
$rows[] = $row;
$status_overview[$sensor_result
->getStatus()]++;
$total_execution_time += $sensor_result
->getExecutionTime();
if (!$sensor_result
->isCached()) {
$non_cached_execution_time += $sensor_result
->getExecutionTime();
}
if ($sensor_result
->getStatus() == SensorResultInterface::STATUS_OK) {
$ok_row_count++;
}
else {
$ok_row_count = -1;
}
}
// Add special class if all sensors of a category are ok.
if ($ok_row_count >= 0) {
$index = count($rows) - $ok_row_count - 1;
$rows[$index]['class'][] = 'sensor-category-ok';
}
}
$output['summary'] = array(
'#theme' => 'monitoring_overview_summary',
'#status_overview' => $status_overview,
'#total_execution_time' => $total_execution_time,
'#non_cached_execution_time' => $non_cached_execution_time,
);
// We can add the oldest_sensor_* data only if there are sensor results cached.
if (!empty($oldest_sensor_config)) {
$output['summary']['#oldest_sensor_label'] = $oldest_sensor_config
->getLabel();
$output['summary']['#oldest_sensor_category'] = $oldest_sensor_config
->getCategory();
$output['summary']['#oldest_sensor_called_before'] = \Drupal::service('date.formatter')
->formatInterval($oldest_sensor_age);
}
$header = array(
t('Sensor name'),
array(
'data' => t('Status'),
'class' => array(
'status',
),
),
t('Called before'),
t('Execution time'),
t('Status Message'),
array(
'data' => t('Actions'),
'class' => array(
'actions',
),
),
);
$monitoring_escalated_sensors = $status_overview[SensorResultInterface::STATUS_WARNING] + $status_overview[SensorResultInterface::STATUS_CRITICAL] + $status_overview[SensorResultInterface::STATUS_UNKNOWN];
$output['table'] = array(
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
'#sticky' => TRUE,
'#attributes' => array(
'class' => array(
'monitoring-severity-colors',
),
'id' => 'monitoring-sensors-overview',
),
'#attached' => [
'drupalSettings' => [
'monitoring_escalated_sensors' => $monitoring_escalated_sensors,
],
'library' => [
'monitoring/monitoring',
],
],
);
return $output;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ControllerBase:: |
protected | property | The configuration factory. | |
ControllerBase:: |
protected | property | The current user service. | 1 |
ControllerBase:: |
protected | property | The entity form builder. | |
ControllerBase:: |
protected | property | The entity manager. | |
ControllerBase:: |
protected | property | The entity type manager. | |
ControllerBase:: |
protected | property | The form builder. | 2 |
ControllerBase:: |
protected | property | The key-value storage. | 1 |
ControllerBase:: |
protected | property | The language manager. | 1 |
ControllerBase:: |
protected | property | The module handler. | 2 |
ControllerBase:: |
protected | property | The state service. | |
ControllerBase:: |
protected | function | Returns the requested cache bin. | |
ControllerBase:: |
protected | function | Retrieves a configuration object. | |
ControllerBase:: |
private | function | Returns the service container. | |
ControllerBase:: |
protected | function | Returns the current user. | 1 |
ControllerBase:: |
protected | function | Retrieves the entity form builder. | |
ControllerBase:: |
protected | function | Retrieves the entity manager service. | |
ControllerBase:: |
protected | function | Retrieves the entity type manager. | |
ControllerBase:: |
protected | function | Returns the form builder service. | 2 |
ControllerBase:: |
protected | function | Returns a key/value storage collection. | 1 |
ControllerBase:: |
protected | function | Returns the language manager service. | 1 |
ControllerBase:: |
protected | function | Returns the module handler. | 2 |
ControllerBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
ControllerBase:: |
protected | function | Returns the state storage service. | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
SensorList:: |
protected | property | The sensor manager. | |
SensorList:: |
protected | property | The sensor runner. | |
SensorList:: |
public | function | ||
SensorList:: |
public static | function |
Instantiates a new instance of this class. Overrides ControllerBase:: |
|
SensorList:: |
public | function | Constructs a \Drupal\monitoring\Form\SensorDetailForm object. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |