View source
<?php
namespace Drupal\Tests\monitoring\Kernel;
use Drupal\monitoring\Entity\SensorConfig;
class MonitoringSystemLoadSensorTest extends MonitoringUnitTestBase {
public function testSystemLoadSensorPlugin() {
$sensor = SensorConfig::create([
'id' => 'system_load_test',
'label' => 'System load',
'plugin_id' => 'system_load',
'value_label' => '% Average',
'caching_time' => 86400,
'value_type' => 'number',
'thresholds' => [
'type' => 'exceeds',
'warning' => 80,
'critical' => 100,
],
'settings' => [
'average_monitored' => '1',
],
]);
$sensor
->save();
$this->container
->get('state')
->set('monitoring.test_load_average', [
0.6,
0.6,
0.6,
]);
$sensor_result = $this
->runSensor('system_load_test');
$this
->assertTrue($sensor_result
->isOk());
$this
->assertEquals($sensor_result
->getValue(), 60);
$this
->assertEquals($sensor_result
->getMessage(), '60 % average, 0.6, 0.6, 0.6');
$this->container
->get('state')
->set('monitoring.test_load_average', [
0.9,
0.9,
0.9,
]);
$sensor_result = $this
->runSensor('system_load_test');
$this
->assertTrue($sensor_result
->isWarning());
$this
->assertEquals($sensor_result
->getValue(), 90);
$this
->assertEquals($sensor_result
->getMessage(), '90 % average, exceeds 80, 0.9, 0.9, 0.9');
$this->container
->get('state')
->set('monitoring.test_load_average', [
1.2,
1.2,
1.2,
]);
$sensor_result = $this
->runSensor('system_load_test');
$this
->assertTrue($sensor_result
->isCritical());
$this
->assertEquals($sensor_result
->getValue(), 120);
$this
->assertEquals($sensor_result
->getMessage(), '120 % average, exceeds 100, 1.2, 1.2, 1.2');
}
}