|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* KPI calculation |
|
4
|
|
|
* |
|
5
|
|
|
* @package CacheCheck\Service |
|
6
|
|
|
* @author Tim Lochmüller |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace HDNET\CacheCheck\Service; |
|
10
|
|
|
|
|
11
|
|
|
use HDNET\CacheCheck\Domain\Model\Cache; |
|
12
|
|
|
use HDNET\CacheCheck\Exception; |
|
13
|
|
|
use HDNET\CacheCheck\Service\Analyzer\AnalyzerInterface; |
|
14
|
|
|
use HDNET\CacheCheck\Service\Statistics\StatisticsInterface; |
|
15
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* KPI calculation |
|
19
|
|
|
* |
|
20
|
|
|
* @author Tim Lochmüller |
|
21
|
|
|
*/ |
|
22
|
|
|
class KeyPerformanceIndicator extends AbstractService |
|
23
|
|
|
{ |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Get the current instance |
|
27
|
|
|
* |
|
28
|
|
|
* @return KeyPerformanceIndicator |
|
29
|
|
|
*/ |
|
30
|
|
|
public static function getInstance() |
|
31
|
|
|
{ |
|
32
|
|
|
return GeneralUtility::makeInstance(KeyPerformanceIndicator::class); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Get static cache information |
|
37
|
|
|
* |
|
38
|
|
|
* @param Cache $cache |
|
39
|
|
|
* |
|
40
|
|
|
* @return array |
|
41
|
|
|
*/ |
|
42
|
|
|
public function getStatic(Cache $cache) |
|
43
|
|
|
{ |
|
44
|
|
|
$formatService = GeneralUtility::makeInstance(FormatService::class); |
|
45
|
|
|
$backendParts = GeneralUtility::trimExplode('\\', $cache->getRealBackend(), true); |
|
46
|
|
|
$className = 'HDNET\\CacheCheck\\Service\\Statistics\\' . $backendParts[sizeof($backendParts) - 1]; |
|
47
|
|
|
|
|
48
|
|
|
if (!class_exists($className)) { |
|
49
|
|
|
return false; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** @var StatisticsInterface $statsBackend */ |
|
53
|
|
|
$statsBackend = GeneralUtility::makeInstance($className); |
|
54
|
|
|
$size = $statsBackend->getSize($cache); |
|
55
|
|
|
$entryCount = $statsBackend->countEntries($cache); |
|
56
|
|
|
return [ |
|
57
|
|
|
'cacheEntriesCount' => $entryCount, |
|
58
|
|
|
'allEntrySizeByte' => $size, |
|
59
|
|
|
'averageEntrySizeByte' => $entryCount === 0 ? 0 : $size / $entryCount, |
|
60
|
|
|
'differentTagsCount' => $statsBackend->countTags($cache), |
|
61
|
|
|
'averageAgeOfCache' => $formatService->formatSeconds($statsBackend->getAge($cache)), |
|
62
|
|
|
'averageExpiresOfCache' => $formatService->formatSeconds($statsBackend->getExpires($cache)), |
|
63
|
|
|
]; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Get dynamic cache information |
|
68
|
|
|
* |
|
69
|
|
|
* @param Cache $cache |
|
70
|
|
|
* |
|
71
|
|
|
* @return array |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getDynamic(Cache $cache) |
|
74
|
|
|
{ |
|
75
|
|
|
$kpiClasses = [ |
|
76
|
|
|
'CountLogEntries', |
|
77
|
|
|
'StartTime', |
|
78
|
|
|
'EndTime', |
|
79
|
|
|
'LogTime', |
|
80
|
|
|
'AverageCreationTime', |
|
81
|
|
|
'AverageSelectionTime', |
|
82
|
|
|
'HitRate', |
|
83
|
|
|
'MissRate', |
|
84
|
|
|
'HasPerSecond', |
|
85
|
|
|
'GetPerSecond', |
|
86
|
|
|
'SetPerSecond', |
|
87
|
|
|
]; |
|
88
|
|
|
|
|
89
|
|
|
$kpi = []; |
|
90
|
|
|
foreach ($kpiClasses as $i => $class) { |
|
91
|
|
|
/** @var AnalyzerInterface $kpiObject */ |
|
92
|
|
|
$kpiObject = GeneralUtility::makeInstance('HDNET\\CacheCheck\\Service\\Analyzer\\' . $class); |
|
93
|
|
|
try { |
|
94
|
|
|
$kpiValue = $kpiObject->getKpi($cache); |
|
95
|
|
|
if ($i === 0 && $kpiValue === 0) { |
|
96
|
|
|
return false; |
|
97
|
|
|
} |
|
98
|
|
|
$kpiValue = $kpiObject->getFormat($kpiValue); |
|
99
|
|
|
} catch (Exception $ex) { |
|
100
|
|
|
$kpiValue = 'NaN'; |
|
101
|
|
|
} |
|
102
|
|
|
$kpi[lcfirst($class)] = $kpiValue; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
return $kpi; |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|