1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\Module\monitor\TestSuite\Store; |
6
|
|
|
|
7
|
|
|
use SimpleSAML\Memcache as M; |
8
|
|
|
use SimpleSAML\Module\monitor\TestConfiguration; |
9
|
|
|
use SimpleSAML\Module\monitor\TestCase; |
10
|
|
|
use SimpleSAML\Module\monitor\TestData; |
11
|
|
|
use SimpleSAML\Module\monitor\TestResult; |
12
|
|
|
use SimpleSAML\Module\monitor\State; |
13
|
|
|
|
14
|
|
|
use function class_exists; |
15
|
|
|
|
16
|
|
|
final class Memcache extends \SimpleSAML\Module\monitor\TestSuiteFactory |
17
|
|
|
{ |
18
|
|
|
/** var string|null */ |
19
|
|
|
private ?string $class = null; |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param \SimpleSAML\Module\monitor\TestConfiguration $configuration |
24
|
|
|
*/ |
25
|
|
|
public function __construct(TestConfiguration $configuration) |
26
|
|
|
{ |
27
|
|
|
$class = class_exists('Memcache') ? 'Memcache' : (class_exists('Memcached') ? 'Memcached' : null); |
28
|
|
|
if ($class !== null) { |
29
|
|
|
$this->class = $class; |
30
|
|
|
$this->setCategory('Memcache sessions'); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
parent::__construct($configuration); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return void |
39
|
|
|
*/ |
40
|
|
|
public function invokeTest(): void |
41
|
|
|
{ |
42
|
|
|
$testResult = new TestResult('Memcache', 'Overall health'); |
43
|
|
|
|
44
|
|
|
if ($this->class === null) { |
45
|
|
|
$testResult->setState(State::FATAL); |
46
|
|
|
$testResult->setMessage('Missing PHP module'); |
47
|
|
|
$this->addTestResult($testResult); |
48
|
|
|
} else { |
49
|
|
|
// Check Memcache-servers |
50
|
|
|
|
51
|
|
|
$stats = M::getRawStats(); |
52
|
|
|
$i = 1; |
53
|
|
|
foreach ($stats as $key => $serverGroup) { |
54
|
|
|
$results = []; |
55
|
|
|
foreach ($serverGroup as $host => $serverStats) { |
56
|
|
|
$input = [ |
57
|
|
|
'serverStats' => $serverStats, |
58
|
|
|
'host' => $host |
59
|
|
|
]; |
60
|
|
|
$testData = new TestData($input); |
61
|
|
|
$serverTest = new TestCase\Store\Memcache\Server($testData); |
62
|
|
|
$results[] = $serverTest->getTestResult(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
$input = [ |
67
|
|
|
'results' => $results, |
68
|
|
|
'group' => strval($i) |
69
|
|
|
]; |
70
|
|
|
$testData = new TestData($input); |
71
|
|
|
$groupTest = new TestCase\Store\Memcache\ServerGroup($testData); |
72
|
|
|
$groupTestResult = $groupTest->getTestResult(); |
73
|
|
|
$this->addTestResult($groupTestResult); |
74
|
|
|
|
75
|
|
|
// Add individual server results |
76
|
|
|
$this->addTestResults($results); |
77
|
|
|
|
78
|
|
|
$i++; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
$state = $this->calculateState(); |
82
|
|
|
|
83
|
|
|
$testResult->setState($state); |
84
|
|
|
} |
85
|
|
|
$this->setTestResult($testResult); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|