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