class ElysiaCronSensorPlugin in Monitoring 8
Monitors elysia cron channels for last execution.
Plugin annotation
@SensorPlugin(
id = "elysia_cron",
label = @Translation("Elysia Cron"),
description = @Translation("Monitors elysia cron channels for last execution."),
provider = "elysia_cron",
addable = FALSE
)
Hierarchy
- class \Drupal\monitoring\SensorPlugin\SensorPluginBase implements SensorPluginInterface uses MessengerTrait, StringTranslationTrait
- class \Drupal\monitoring\Plugin\monitoring\SensorPlugin\ElysiaCronSensorPlugin
Expanded class hierarchy of ElysiaCronSensorPlugin
File
- src/
Plugin/ monitoring/ SensorPlugin/ ElysiaCronSensorPlugin.php, line 24 - Contains \Drupal\monitoring\Plugin\monitoring\SensorPlugin\ElysiaCronSensorPlugin.
Namespace
Drupal\monitoring\Plugin\monitoring\SensorPluginView source
class ElysiaCronSensorPlugin extends SensorPluginBase {
/**
* {@inheritdoc}
*/
public function runSensor(SensorResultInterface $result) {
// The channel name.
$name = $this->sensorConfig
->getSetting('name');
$query = \Drupal::database()
->select('elysia_cron', 'e')
->fields('e', array(
$this->sensorConfig
->getSetting('metric'),
));
$query
->condition('name', $name);
$value = $query
->execute()
->fetchField();
// In case we are querying for last_run, the value is the seconds ago.
if ($this->sensorConfig
->getSetting('metric') == 'last_run') {
$value = \Drupal::time()
->getRequestTime() - $value;
$result
->addStatusMessage('@time ago', array(
'@time' => \Drupal::service('date.formatter')
->formatInterval($value),
));
}
else {
// metric last_execution_time
$result
->addStatusMessage('at @time', array(
'@time' => \Drupal::service('date.formatter')
->format($value),
));
}
$result
->setValue($value);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ElysiaCronSensorPlugin:: |
public | function |
Runs the sensor, updating $sensor_result. Overrides SensorPluginInterface:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
SensorPluginBase:: |
protected | property | Allows plugins to control if the value type can be configured. | 6 |
SensorPluginBase:: |
protected | property | The plugin implementation definition. | |
SensorPluginBase:: |
protected | property | The plugin_id. | |
SensorPluginBase:: |
protected | property | Current sensor config object. | |
SensorPluginBase:: |
protected | property | ||
SensorPluginBase:: |
public | function |
Service setter. Overrides SensorPluginInterface:: |
|
SensorPluginBase:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
13 |
SensorPluginBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides SensorPluginInterface:: |
4 |
SensorPluginBase:: |
public static | function |
Creates an instance of the sensor with config. Overrides SensorPluginInterface:: |
7 |
SensorPluginBase:: |
public | function |
Configurable value type. Overrides SensorPluginInterface:: |
|
SensorPluginBase:: |
public | function |
Default configuration for a sensor. Overrides SensorPluginInterface:: |
8 |
SensorPluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
|
SensorPluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
SensorPluginBase:: |
public | function |
Gets sensor name (not the label). Overrides SensorPluginInterface:: |
|
SensorPluginBase:: |
public | function |
@todo: Replace with injection Overrides SensorPluginInterface:: |
|
SensorPluginBase:: |
public | function |
Determines if sensor is enabled. Overrides SensorPluginInterface:: |
|
SensorPluginBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
3 |
SensorPluginBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
2 |
SensorPluginBase:: |
function | Instantiates a sensor object. | 8 | |
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. |