-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAPCStats.php
209 lines (163 loc) · 5.75 KB
/
APCStats.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<?php
class APCStats {
private $fileCacheInfo;
private $userCacheInfo;
private $memoryInfo;
function __construct() {
$this->checkEnvironment();
$this->setFileCacheInfo();
$this->setUserCacheInfo();
$this->setMemoryInfo();
}
protected function checkEnvironment() {
if (!function_exists('apc_cache_info')) {
throw new Exception('No cache info available. APC does not appear to be running or installed', 1);
}
}
protected function setFileCacheInfo() {
$this->fileCacheInfo = new ArrayObject(apc_cache_info('opcode', 1));
}
protected function setUserCacheInfo() {
$this->userCacheInfo = new ArrayObject(apc_cache_info('user', 1));
}
protected function setMemoryInfo() {
$this->memoryInfo = new ArrayObject(apc_sma_info());
}
public function getFileCacheInfo() {
return $this->fileCacheInfo;
}
public function getUserCacheInfo() {
return $this->userCacheInfo;
}
public function getMemoryInfo() {
return $this->memoryInfo;
}
public function getSegmentSize() {
return $this->getMemoryInfo()->offsetGet('seg_size');
}
public function getNumberOfSegments() {
return $this->getMemoryInfo()->offsetGet('num_seg');
}
public function getMemoryType() {
return $this->getFileCacheInfo()->offsetGet('memory_type');
}
public function getLockingType() {
return $this->getFileCacheInfo()->offsetGet('locking_type');
}
public function getFileUploadSupport() {
return $this->getFileCacheInfo()->offsetGet('file_upload_progress');
}
public function getApcSettings() {
return new ArrayObject(ini_get_all('apc'));
}
public function getTotalMemory() {
return $this->getSegmentSize() * $this->getNumberOfSegments();
}
public function getAvailableMemory() {
return $this->getMemoryInfo()->offsetGet('avail_mem');
}
public function getUsedMemory() {
return $this->getTotalMemory() - $this->getAvailableMemory();
}
public function getCacheStartTime() {
return $this->getFileCacheInfo()->offsetGet('start_time');
}
public function getNow() {
return time();
}
public function getUptime() {
return $this->getNow() - $this->getCacheStartTime();
}
public function getFileHits() {
return $this->getFileCacheInfo()->offsetGet('num_hits');
}
public function getFileMisses() {
return $this->getFileCacheInfo()->offsetGet('num_misses');
}
public function getFileRequestRate() {
return ($this->getFileHits() + $this->getFileMisses()) / $this->getUptime();
}
public function getFileHitRate() {
return $this->getFileHits() / $this->getUptime();
}
public function getFileMissRate() {
return $this->getFileMisses() / $this->getUptime();
}
public function getFileInserts() {
return $this->getFileCacheInfo()->offsetGet('num_inserts');
}
public function getFileInsertRate() {
return $this->getFileInserts() / $this->getUptime();
}
public function getUserHits() {
return $this->getUserCacheInfo()->offsetGet('num_hits');
}
public function getUserMisses() {
return $this->getUserCacheInfo()->offsetGet('num_misses');
}
public function getUserRequestRate() {
return ($this->getUserHits() + $this->getUserMisses()) / $this->getUptime();
}
public function getUserHitRate() {
return $this->getUserHits() / $this->getUptime();
}
public function getUserMissRate() {
return $this->getUserMisses() / $this->getUptime();
}
public function getUserInserts() {
return $this->getUserCacheInfo()->offsetGet('num_inserts');
}
public function getUserInsertRate() {
return $this->getUserInserts() / $this->getUptime();
}
public function getPhpVersion() {
return phpversion();
}
public function getApcVersion() {
return phpversion('apc');
}
public function getNumberOfFiles() {
return $this->getFileCacheInfo()->offsetGet('num_entries');
}
public function getNumberOfVariables() {
return $this->getUserCacheInfo()->offsetGet('num_entries');
}
public function getSizeOfFiles() {
return $this->getFileCacheInfo()->offsetGet('mem_size');
}
public function getSizeOfVariables() {
return $this->getUserCacheInfo()->offsetGet('mem_size');
}
public function formatBytes($bytes) {
$units = array(
'B',
'KB',
'MB',
'GB',
'TB'
);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
$bytes /= pow(1024, $pow);
return number_format($bytes, 2) . ' ' . $units[$pow];
}
public function formatNumbers($number) {
return number_format($number, 2);
}
public function makeBar($amount, $total = 100) {
$percent = number_format(($amount / $total) * 100);
$remaining = 100 - $percent;
if ($percent < 10) {
echo "<div class='success bar' style='width: 100%;'>% $percent</div>";
} elseif ($percent >= 10 && $percent < 90) {
echo "<div class='error bar' style='width: $percent%;'>% $percent</div>";
echo "<div class='success bar' style='width: $remaining%;'>% $remaining</div>";
} elseif ($percent >= 90 && $percent < 100) {
echo "<div class='notice bar' style='width: 100%;'>% $percent</div>";
} elseif ($percent >= 100) {
echo "<div class='error bar' style='width: 100%;'>% $percent</div>";
}
echo "<div class='clear'></div>";
}
}
?>