Skip to content

Commit d5d28ff

Browse files
committed
More tests
1 parent d56a1fc commit d5d28ff

18 files changed

Lines changed: 659 additions & 35 deletions

‎src/Dashboards/AnalysisTrait.php‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@ trait AnalysisTrait {
1818
*/
1919
private array $top_thresholds = [];
2020

21+
/**
22+
* Cutoffs left over from a previous run would silently drop rows from the next one, so every analysis has to start with this.
23+
*/
24+
private function resetTopThresholds(): void {
25+
$this->top_thresholds = [];
26+
}
27+
2128
/**
2229
* Collect a row only if it can still make the top list.
2330
*
24-
* A keyspace can hold hundreds of thousands of keys, so buffering every one of them just to sort
25-
* out the largest handful is what would actually run the process out of memory.
26-
*
2731
* @param array<int, array<string, mixed>> $buffer
2832
* @param array<string, mixed> $row
2933
*/

‎src/Dashboards/Memcached/MemcachedAnalysis.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ public function analyzeKeys(array $lines): array {
9494
$separator = $this->servers[$this->current_server]['separator'] ?? ':';
9595
$time = time();
9696

97+
$this->resetTopThresholds();
98+
9799
$analyzed = 0;
98100
$total_memory = 0;
99101
$no_expiry = ['count' => 0, 'memory' => 0];

‎src/Dashboards/Memcached/MemcachedHealth.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ trait MemcachedHealth {
1717
*
1818
* @return array<int, array<string, mixed>>
1919
*/
20-
private function getHealthChecks(array $info): array {
20+
public function getHealthChecks(array $info): array {
2121
return [
2222
$this->memoryCheck($info),
2323
$this->hitRateCheck($info),

‎src/Dashboards/Memcached/MemcachedKeysList.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function keysTableView(array $raw_lines): array {
5656

5757
foreach ($raw_lines as $line) {
5858
$key_data = $this->memcached->parseLine($line);
59-
$ttl = $key_data['exp'] ?? null;
59+
$ttl = $key_data['exp'] ?? -1;
6060
$ttl_display = $ttl === -1 ? 'Doesn\'t expire' : $ttl - $time;
6161

6262
$formatted_keys[] = [
@@ -99,7 +99,7 @@ public function keysTreeView(array $raw_lines): array {
9999
continue;
100100
}
101101

102-
$ttl = $key_data['exp'] ?? null;
102+
$ttl = $key_data['exp'] ?? -1;
103103

104104
$keys[] = [
105105
'key' => $key_data['key'],

‎src/Dashboards/Memcached/MemcachedMetrics.php‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ public function __construct(
2727
parent::__construct($servers, $selected);
2828
}
2929

30-
protected function dbPrefix(): string {
31-
return 'memcached';
32-
}
33-
3430
protected function schema(): string {
3531
return <<<SQL
3632
CREATE TABLE IF NOT EXISTS metrics (

‎src/Dashboards/Metrics.php‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ public function __construct(array $servers, int $selected) {
2626
$server_name = Helpers::getServerTitle($servers[$selected]);
2727
$hash = md5($server_name.Config::get('hash', 'pca'));
2828
$dir = Config::get('metricsdir', __DIR__.'/../../tmp/metrics');
29-
$db = $dir.'/'.$this->dbPrefix().'_metrics_'.$hash.'.db';
29+
30+
$prefix = strtolower(str_replace('Metrics', '', substr((string) strrchr(static::class, '\\'), 1)));
31+
$db = $dir.'/'.$prefix.'_metrics_'.$hash.'.db';
3032

3133
if (!is_dir($dir) && !mkdir($dir, 0777, true) && !is_dir($dir)) {
3234
throw new RuntimeException(sprintf('Directory "%s" was not created', $dir));
@@ -39,11 +41,6 @@ public function __construct(array $servers, int $selected) {
3941
$this->pdo->exec('CREATE INDEX IF NOT EXISTS metrics_timestamp ON metrics (timestamp)');
4042
}
4143

42-
/**
43-
* Prefix for the database file name, e.g. "redis".
44-
*/
45-
abstract protected function dbPrefix(): string;
46-
4744
/**
4845
* "CREATE TABLE" statement for the metrics table.
4946
*/

‎src/Dashboards/OPCache/OPCacheHealth.php‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,19 @@
1313

1414
trait OPCacheHealth {
1515
/**
16+
* @param array<string, mixed>|null $status
17+
* @param array<string, mixed>|null $directives
18+
*
1619
* @return array<int, array<string, mixed>>
1720
*/
18-
private function getHealthChecks(): array {
19-
$status = opcache_get_status(false);
21+
public function getHealthChecks(?array $status = null, ?array $directives = null): array {
22+
$status ??= opcache_get_status(false) ?: null;
2023

21-
if ($status === false) {
24+
if ($status === null) {
2225
return [];
2326
}
2427

25-
$directives = opcache_get_configuration()['directives'];
28+
$directives ??= opcache_get_configuration()['directives'];
2629
$memory = $status['memory_usage'];
2730
$stats = $status['opcache_statistics'];
2831

‎src/Dashboards/Redis/RedisAnalysis.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ public function analyzeKeys(array $keys, array $pipeline, int $depth, int $total
345345
'hash_limit' => $context['hash_limit'] ?? null,
346346
];
347347

348+
$this->resetTopThresholds();
348349
$stats = $this->emptyStats();
349350

350351
foreach ($keys as $key) {

‎src/Dashboards/Redis/RedisClients.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private function killClient(string $id): void {
8181
*
8282
* @return array<string, mixed>
8383
*/
84-
private function formatClient(array $client): array {
84+
public function formatClient(array $client): array {
8585
$age = (int) ($client['age'] ?? 0);
8686
$idle = (int) ($client['idle'] ?? 0);
8787
$memory = (int) ($client['tot-mem'] ?? 0);

‎src/Dashboards/Redis/RedisHealth.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ trait RedisHealth {
1717
*
1818
* @return array<int, array<string, mixed>>
1919
*/
20-
private function getHealthChecks(array $info): array {
20+
public function getHealthChecks(array $info): array {
2121
$memory = $info['memory'] ?? [];
2222
$stats = $info['stats'] ?? [];
2323
$clients = $info['clients'] ?? [];

0 commit comments

Comments
 (0)