-
Notifications
You must be signed in to change notification settings - Fork 17
/
apc_info.php
executable file
·156 lines (139 loc) · 6.83 KB
/
apc_info.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
<?php
/**
* @file
* APC Info file.
*
* This file should be placed in your website's docroot so the apc_php_ munin
* plugins can read the file to report APC usage statistics.
*/
if (function_exists("apc_cache_info") && function_exists("apc_sma_info")) {
$apcu_mode=function_exists("apcu_cache_info") && function_exists("apcu_sma_info");
$time = time();
// Get memory information.
$mem = apc_sma_info();
$mem_size = $mem['num_seg'] * $mem['seg_size'];
$mem_avail= $mem['avail_mem'];
$mem_used = $mem_size - $mem_avail;
// Some code taken from the file apc.php by The PHP Group.
$nseg = $freeseg = $fragsize = $freetotal = 0;
for ($i=0; $i < $mem['num_seg']; $i++) {
$ptr = 0;
foreach ($mem['block_lists'][$i] as $block) {
if ($block['offset'] != $ptr) {
++$nseg;
}
$ptr = $block['offset'] + $block['size'];
// Only consider blocks < 5M for the fragmentation %.
if ($block['size'] < (5 * 1024 * 1024)) $fragsize += $block['size'];
$freetotal += $block['size'];
}
$freeseg += count($mem['block_lists'][$i]);
}
if ($freeseg < 2) {
$fragsize = 0;
$freeseg = 0;
}
if ($apcu_mode) {
/* User Cache ------------------------------------------------------------- */
$cache = apcu_cache_info();
// Item hits, misses and inserts
$user_hits = $cache['num_hits'];
$user_misses = $cache['num_misses'];
$user_inserts = $cache['num_inserts'];
$user_req_rate = ($cache['num_hits'] + $cache['num_misses']) / ($time - $cache['start_time']);
$user_hit_rate = ($cache['num_hits']) / ($time - $cache['start_time']); // Number of entries in cache $number_entries = $cache['num_entries'];
$user_miss_rate = ($cache['num_misses']) / ($time - $cache['start_time']); // Total number of cache purges $purges = $cache['expunges'];
$user_insert_rate = ($cache['num_inserts']) / ($time - $cache['start_time']);
$user_number_entries = $cache['num_entries']; // Number of entries in cache
$user_purges = $cache['expunges']; // Total number of cache purges
$user_mem_size = $cache['mem_size'];
// Build output array.
$output = array(
'mode: ' . 'apcu',
'size: ' . $mem_size,
'used: ' . $mem_used,
'free: ' . ($mem_avail - $fragsize),
'fragment_percentage: ' . sprintf("%.2f", ($fragsize/$mem_avail)*100),
'fragmented: ' . sprintf("%.2f", $fragsize),
'fragment_segments: ' . $freeseg,
'user_size: ' . $user_mem_size,
'user_hits: ' . sprintf("%.2f", ($user_hits + $user_misses) ? ($user_hits * 100 / ($user_hits + $user_misses)) : 0),
'user_misses: ' . sprintf("%.2f", ($user_hits + $user_misses) ? ($user_misses * 100 / ($user_hits + $user_misses)) : 0),
'user_request_rate: ' . sprintf("%.2f", $user_req_rate),
'user_hit_rate: ' . sprintf("%.2f", $user_hit_rate),
'user_miss_rate: ' . sprintf("%.2f", $user_miss_rate),
'user_insert_rate: ' . sprintf("%.2f", $user_insert_rate),
'user_entries: ' . $user_number_entries,
'user_inserts: ' . $user_inserts,
'user_purges: ' . $user_purges,
'user_purge_rate: ' . sprintf("%.2f", $user_inserts ? (100 - ($user_number_entries / $user_inserts) * 100) : 0),
);
}
else {
/* Optcode (file) Cache --------------------------------------------------- */
$cache_mode = 'opmode';
$cache = @apc_cache_info($cache_mode, true);
// Item hits, misses and inserts
$hits = $cache['num_hits'];
$misses = $cache['num_misses'];
$inserts = $cache['num_inserts'];
$req_rate = ($cache['num_hits'] + $cache['num_misses']) / ($time - $cache['start_time']);
$hit_rate = ($cache['num_hits']) / ($time - $cache['start_time']); // Number of entries in cache $number_entries = $cache['num_entries'];
$miss_rate = ($cache['num_misses']) / ($time - $cache['start_time']); // Total number of cache purges $purges = $cache['expunges'];
$insert_rate = ($cache['num_inserts']) / ($time - $cache['start_time']);
$number_entries = $cache['num_entries']; // Number of entries in cache
$purges = $cache['expunges']; // Total number of cache purges
$optcode_mem_size = $cache['mem_size'];
//apc_clear_cache($cache_mode);
/* User Cache ------------------------------------------------------------- */
$cache_mode = 'user';
$cache = @apc_cache_info($cache_mode, true);
// Item hits, misses and inserts
$user_hits = $cache['num_hits'];
$user_misses = $cache['num_misses'];
$user_inserts = $cache['num_inserts'];
$user_req_rate = ($cache['num_hits'] + $cache['num_misses']) / ($time - $cache['start_time']);
$user_hit_rate = ($cache['num_hits']) / ($time - $cache['start_time']); // Number of entries in cache $number_entries = $cache['num_entries'];
$user_miss_rate = ($cache['num_misses']) / ($time - $cache['start_time']); // Total number of cache purges $purges = $cache['expunges'];
$user_insert_rate = ($cache['num_inserts']) / ($time - $cache['start_time']);
$user_number_entries = $cache['num_entries']; // Number of entries in cache
$user_purges = $cache['expunges']; // Total number of cache purges
$user_mem_size = $cache['mem_size'];
// Build output array.
$output = array(
'mode: ' . 'apc',
'size: ' . $mem_size,
'used: ' . $mem_used,
'free: ' . ($mem_avail - $fragsize),
'hits: ' . sprintf("%.2f", $hits * 100 / ($hits + $misses)),
'misses: ' . sprintf("%.2f", $misses * 100 / ($hits + $misses)),
'request_rate: ' . sprintf("%.2f", $req_rate),
'hit_rate: ' . sprintf("%.2f", $hit_rate),
'miss_rate: ' . sprintf("%.2f", $miss_rate),
'insert_rate: ' . sprintf("%.2f", $insert_rate),
'entries: ' . $number_entries,
'inserts: ' . $inserts,
'purges: ' . $purges,
'purge_rate: ' . sprintf("%.2f", (100 - ($number_entries / $inserts) * 100)),
'fragment_percentage: ' . sprintf("%.2f", ($fragsize/$mem_avail)*100),
'fragmented: ' . sprintf("%.2f", $fragsize),
'fragment_segments: ' . $freeseg,
'optcode_size: ' . $optcode_mem_size,
'user_size: ' . $user_mem_size,
'user_hits: ' . sprintf("%.2f", ($user_hits + $user_misses) ? ($user_hits * 100 / ($user_hits + $user_misses)) : 0),
'user_misses: ' . sprintf("%.2f", ($user_hits + $user_misses) ? ($user_misses * 100 / ($user_hits + $user_misses)) : 0),
'user_request_rate: ' . sprintf("%.2f", $user_req_rate),
'user_hit_rate: ' . sprintf("%.2f", $user_hit_rate),
'user_miss_rate: ' . sprintf("%.2f", $user_miss_rate),
'user_insert_rate: ' . sprintf("%.2f", $user_insert_rate),
'user_entries: ' . $user_number_entries,
'user_inserts: ' . $user_inserts,
'user_purges: ' . $user_purges,
'user_purge_rate: ' . sprintf("%.2f", $user_inserts ? (100 - ($user_number_entries / $user_inserts) * 100) : 0),
);
}
}
else {
$output = array('APC-not-installed');
}
echo implode(' ', $output);