class QueueSizeSensorPlugin in Monitoring 8
Monitors number of items for a given core queue.
@SensorPlugin( id = "queue_size", label = @Translation("Queue Size"), description = @Translation("Monitors number of items for a given core queue."), addable = TRUE )
Every instance represents a single queue. Once all queue items are processed, the value should be 0.
Hierarchy
- class \Drupal\monitoring\SensorPlugin\SensorPluginBase implements SensorPluginInterface uses MessengerTrait, StringTranslationTrait
- class \Drupal\monitoring\Plugin\monitoring\SensorPlugin\QueueSizeSensorPlugin
Expanded class hierarchy of QueueSizeSensorPlugin
See also
\DrupalQueue
File
- src/
Plugin/ monitoring/ SensorPlugin/ QueueSizeSensorPlugin.php, line 28 - Contains \Drupal\monitoring\Plugin\monitoring\SensorPlugin\QueueSizeSensorPlugin.
Namespace
Drupal\monitoring\Plugin\monitoring\SensorPluginView source
class QueueSizeSensorPlugin extends SensorPluginBase {
/**
* {@inheritdoc}
*/
protected $configurableValueType = FALSE;
/**
* Adds UI to select Queue for the sensor.
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$queues = \Drupal::service('plugin.manager.queue_worker')
->getDefinitions();
$options = [];
foreach ($queues as $id => $definition) {
$options[$id] = $definition['title'];
}
$form['queue'] = array(
'#type' => 'select',
'#options' => $options,
'#default_value' => $this->sensorConfig
->getSetting('queue'),
'#required' => TRUE,
'#title' => t('Queues'),
);
return $form;
}
/**
* {@inheritdoc}
*/
public function runSensor(SensorResultInterface $result) {
$result
->setValue(\Drupal::queue($this->sensorConfig
->getSetting('queue'))
->numberOfItems());
}
/**
* {@inheritdoc}
*/
public function getDefaultConfiguration() {
$default_config = array(
'value_type' => 'number',
);
return $default_config;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
QueueSizeSensorPlugin:: |
protected | property |
Allows plugins to control if the value type can be configured. Overrides SensorPluginBase:: |
|
QueueSizeSensorPlugin:: |
public | function |
Adds UI to select Queue for the sensor. Overrides SensorPluginBase:: |
|
QueueSizeSensorPlugin:: |
public | function |
Default configuration for a sensor. Overrides SensorPluginBase:: |
|
QueueSizeSensorPlugin:: |
public | function |
Runs the sensor, updating $sensor_result. Overrides SensorPluginInterface:: |
|
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 |
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 |
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. |