SensorInterface::run(SensorResultInterface $result)
The sensor manager is responsible for collecting information about sensors from hook implementations and manage their settings.
monitoring_sensor_manager()->getSensorInfo()
monitoring_sensor_manager()->enableSensor($sensor_name)
monitoring_sensor_manager()->disableSensor($sensor_name)
monitoring_sensor_run($sensor_name)
monitoring_sensor_run_multiple(array $sensor_names = array())
[Value] [Label] in [Time Frame], expected [ExpectedValue], exceeds [Interval], [Message]
54 watchdog events in 1 Tag, exceeds 50, apple-touch-icon-precomposed.png
CHF 1337.50 in 1 Tag, falls below CHF 1500.00
/** * Implements hook_monitoring_sensor_info() */ function maillog_monitoring_sensor_info() { $info['maillog_records_count'] = array( 'label' => 'Maillog records count', 'sensor_class' => 'Drupal\...\Sensors\SensorDatabaseAggregator', 'value_label' => 'Mail records', 'settings' => array(
'category' => 'Mail', 'table' => 'maillog', 'time_interval_field' => 'sent_date', 'time_interval_value' => 60 * 60 * 24, ), ); return $info; }
$info['core_maintenance_mode'] = array(
'label' => 'Maintenance mode',
'description' => 'Site maintenance mode',
'sensor_class' => 'Drupal\...\Sensors\SensorVariable',
'numeric' => FALSE,
'value_type' => 'bool',
'settings' => array(
'variable_name' => 'maintenance_mode',
'variable_value' => FALSE,
'variable_default_value' => FALSE,
),
);
class SensorUserFailedLogins extends SensorDatabaseAggregator {
/**
* {@inheritdoc}
*/
public function buildQuery() {
$query = parent::buildQuery();
$query->addField('watchdog', 'variables');
$query->groupBy('watchdog.variables');
return $query;
}
/**
* {@inheritdoc}
*/
public function runSensor(SensorResultInterface $result) {
$records_count = 0;
foreach ($this->getQueryResult()->fetchAll() as $row) {
$records_count += $row->records_count;
$variables = unserialize($row->variables);
$result->addStatusMessage('@user: @count', array('@user' => $variables['%user'], '@count' => $row->records_count));
}
$result->setValue($records_count);
}
class SensorQueue extends SensorThresholds {
public function runSensor(SensorResultInterface $result) {
$queue = \DrupalQueue::get($this->info->getSetting('queue'));
$result->setValue($queue->numberOfItems());
}
}
class SensorSearchApi extends SensorThresholds {
public function runSensor(SensorResultInterface $result) {
$indexes = search_api_index_load_multiple(array($this->info->getSetting('index_id')));
$index = reset($indexes);
$status = search_api_index_status($index);
// Set amount of unindexed items.
$result->setValue($status['total'] - $status['indexed']);
}
}
GET /monitoring/sensor-info/dblog_event_severity_error
GET /monitoring/sensor-result
drush monitoring-run cron_core_last_run_age
drush monitoring-run --output=json
drush monitoring-info
drush monitoring-enable <sensor>
drush monitoring-disable <sensor>
foreach (monitoring_sensor_run_multiple() as $result) { print $result->getSensorName() . ": " . $result->getStatus();
}
Config Entity & Plugin?