1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Krenor\Prometheus\Exporter; |
4
|
|
|
|
5
|
|
|
use Krenor\Prometheus\Metrics\Gauge; |
6
|
|
|
use Krenor\Prometheus\Metrics\Counter; |
7
|
|
|
use Krenor\Prometheus\Contracts\Exporter; |
8
|
|
|
use Krenor\Prometheus\MetricFamilySamples; |
9
|
|
|
|
10
|
|
|
class Opcache extends Exporter |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @return MetricFamilySamples |
14
|
|
|
*/ |
15
|
1 |
|
public function enabled(): MetricFamilySamples |
16
|
|
|
{ |
17
|
1 |
|
return $this->sampled( |
18
|
1 |
|
new class extends Gauge { |
19
|
|
|
protected ?string $namespace = 'php_opcache'; |
20
|
|
|
protected string $name = 'enabled'; |
21
|
|
|
protected string $description = 'Indicator if opcache is enabled.'; |
22
|
|
|
}, |
23
|
1 |
|
$this->data['opcache_enabled'] |
24
|
|
|
); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @return MetricFamilySamples |
29
|
|
|
*/ |
30
|
1 |
|
public function oom(): MetricFamilySamples |
31
|
|
|
{ |
32
|
1 |
|
return $this->sampled( |
33
|
1 |
|
new class extends Gauge { |
34
|
|
|
protected ?string $namespace = 'php_opcache'; |
35
|
|
|
protected string $name = 'out_of_memory'; |
36
|
|
|
protected string $description = 'Indicator if cache is full.'; |
37
|
|
|
}, |
38
|
1 |
|
$this->data['cache_full'] |
39
|
|
|
); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return MetricFamilySamples |
44
|
|
|
*/ |
45
|
1 |
|
public function restarts(): MetricFamilySamples |
46
|
|
|
{ |
47
|
1 |
|
return $this->sampled( |
48
|
1 |
|
new class extends Gauge { |
49
|
|
|
protected ?string $namespace = 'php_opcache'; |
50
|
|
|
protected string $name = 'restart_pending'; |
51
|
|
|
protected string $description = 'Indicator if a restart is pending'; |
52
|
|
|
}, |
53
|
1 |
|
$this->data['restart_pending'] |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return MetricFamilySamples |
59
|
|
|
*/ |
60
|
1 |
|
public function restarting(): MetricFamilySamples |
61
|
|
|
{ |
62
|
1 |
|
return $this->sampled( |
63
|
1 |
|
new class extends Gauge { |
64
|
|
|
protected ?string $namespace = 'php_opcache'; |
65
|
|
|
protected string $name = 'is_restarting'; |
66
|
|
|
protected string $description = 'Indicator if a restart is in progress.'; |
67
|
|
|
}, |
68
|
1 |
|
$this->data['restart_in_progress'] |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return MetricFamilySamples |
74
|
|
|
*/ |
75
|
1 |
|
public function consumed(): MetricFamilySamples |
76
|
|
|
{ |
77
|
1 |
|
return $this->sampled( |
78
|
1 |
|
new class extends Gauge { |
79
|
|
|
protected ?string $namespace = 'php_opcache'; |
80
|
|
|
protected string $name = 'memory_used_bytes'; |
81
|
|
|
protected string $description = 'The amount of memory consumed.'; |
82
|
|
|
}, |
83
|
1 |
|
$this->data['memory_usage']['used_memory'] |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return MetricFamilySamples |
89
|
|
|
*/ |
90
|
1 |
|
public function free(): MetricFamilySamples |
91
|
|
|
{ |
92
|
1 |
|
return $this->sampled( |
93
|
1 |
|
new class extends Gauge { |
94
|
|
|
protected ?string $namespace = 'php_opcache'; |
95
|
|
|
protected string $name = 'memory_free_bytes'; |
96
|
|
|
protected string $description = 'The amount of memory available for consumption.'; |
97
|
|
|
}, |
98
|
1 |
|
$this->data['memory_usage']['free_memory'] |
99
|
|
|
); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return MetricFamilySamples |
104
|
|
|
*/ |
105
|
1 |
|
public function wasted(): MetricFamilySamples |
106
|
|
|
{ |
107
|
1 |
|
return $this->sampled( |
108
|
1 |
|
new class extends Gauge { |
109
|
|
|
protected ?string $namespace = 'php_opcache'; |
110
|
|
|
protected string $name = 'memory_wasted_bytes'; |
111
|
|
|
protected string $description = 'The amount of memory wasted.'; |
112
|
|
|
}, |
113
|
1 |
|
$this->data['memory_usage']['wasted_memory'] |
114
|
|
|
); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @return MetricFamilySamples |
119
|
|
|
*/ |
120
|
1 |
|
public function wastePercentage(): MetricFamilySamples |
121
|
|
|
{ |
122
|
1 |
|
return $this->sampled( |
123
|
1 |
|
new class extends Gauge { |
124
|
|
|
protected ?string $namespace = 'php_opcache'; |
125
|
|
|
protected string $name = 'memory_wasted_percent'; |
126
|
|
|
protected string $description = 'The percentage of currently wasted memory.'; |
127
|
|
|
}, |
128
|
1 |
|
$this->data['memory_usage']['current_wasted_percentage'] |
129
|
|
|
); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @return MetricFamilySamples |
134
|
|
|
*/ |
135
|
1 |
|
public function stringsBuffer(): MetricFamilySamples |
136
|
|
|
{ |
137
|
1 |
|
return $this->sampled( |
138
|
1 |
|
new class extends Counter { |
139
|
|
|
protected ?string $namespace = 'php_opcache'; |
140
|
|
|
protected string $name = 'strings_buffer_size_bytes'; |
141
|
|
|
protected string $description = 'The buffer size of interned strings.'; |
142
|
|
|
}, |
143
|
1 |
|
$this->data['interned_strings_usage']['buffer_size'] |
144
|
|
|
); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @return MetricFamilySamples |
149
|
|
|
*/ |
150
|
1 |
|
public function stringsMemoryConsumed(): MetricFamilySamples |
151
|
|
|
{ |
152
|
1 |
|
return $this->sampled( |
153
|
1 |
|
new class extends Gauge { |
154
|
|
|
protected ?string $namespace = 'php_opcache'; |
155
|
|
|
protected string $name = 'strings_memory_used_bytes'; |
156
|
|
|
protected string $description = 'The amount of memory used by interned strings.'; |
157
|
|
|
}, |
158
|
1 |
|
$this->data['interned_strings_usage']['used_memory'] |
159
|
|
|
); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @return MetricFamilySamples |
164
|
|
|
*/ |
165
|
1 |
|
public function stringsMemoryFree(): MetricFamilySamples |
166
|
|
|
{ |
167
|
1 |
|
return $this->sampled( |
168
|
1 |
|
new class extends Gauge { |
169
|
|
|
protected ?string $namespace = 'php_opcache'; |
170
|
|
|
protected string $name = 'strings_memory_free_bytes'; |
171
|
|
|
protected string $description = 'The amount of memory available for interned strings.'; |
172
|
|
|
}, |
173
|
1 |
|
$this->data['interned_strings_usage']['free_memory'] |
174
|
|
|
); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @return MetricFamilySamples |
179
|
|
|
*/ |
180
|
1 |
|
public function strings(): MetricFamilySamples |
181
|
|
|
{ |
182
|
1 |
|
return $this->sampled( |
183
|
1 |
|
new class extends Counter { |
184
|
|
|
protected ?string $namespace = 'php_opcache'; |
185
|
|
|
protected string $name = 'strings_count'; |
186
|
|
|
protected string $description = 'The amount of used interned strings'; |
187
|
|
|
}, |
188
|
1 |
|
$this->data['interned_strings_usage']['number_of_strings'] |
189
|
|
|
); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @return MetricFamilySamples |
194
|
|
|
*/ |
195
|
1 |
|
public function scripts(): MetricFamilySamples |
196
|
|
|
{ |
197
|
1 |
|
return $this->sampled( |
198
|
1 |
|
new class extends Counter { |
199
|
|
|
protected ?string $namespace = 'php_opcache'; |
200
|
|
|
protected string $name = 'cache_scripts_count'; |
201
|
|
|
protected string $description = 'The amount of cached scripts.'; |
202
|
|
|
}, |
203
|
1 |
|
$this->data['opcache_statistics']['num_cached_scripts'] |
204
|
|
|
); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @return MetricFamilySamples |
209
|
|
|
*/ |
210
|
1 |
|
public function keys(): MetricFamilySamples |
211
|
|
|
{ |
212
|
1 |
|
return $this->sampled( |
213
|
1 |
|
new class extends Counter { |
214
|
|
|
protected ?string $namespace = 'php_opcache'; |
215
|
|
|
protected string $name = 'cache_keys_count'; |
216
|
|
|
protected string $description = 'The amount of hash table keys.'; |
217
|
|
|
}, |
218
|
1 |
|
$this->data['opcache_statistics']['num_cached_keys'] |
219
|
|
|
); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* @return MetricFamilySamples |
224
|
|
|
*/ |
225
|
1 |
|
public function maxCachedKeys(): MetricFamilySamples |
226
|
|
|
{ |
227
|
1 |
|
return $this->sampled( |
228
|
1 |
|
new class extends Gauge { |
229
|
|
|
protected ?string $namespace = 'php_opcache'; |
230
|
|
|
protected string $name = 'cache_max_keys_count'; |
231
|
|
|
protected string $description = 'The maximum amount of hash table keys.'; |
232
|
|
|
}, |
233
|
1 |
|
$this->data['opcache_statistics']['max_cached_keys'] |
234
|
|
|
); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @return MetricFamilySamples |
239
|
|
|
*/ |
240
|
1 |
|
public function hits(): MetricFamilySamples |
241
|
|
|
{ |
242
|
1 |
|
return $this->sampled( |
243
|
1 |
|
new class extends Counter { |
244
|
|
|
protected ?string $namespace = 'php_opcache'; |
245
|
|
|
protected string $name = 'cache_hits_count'; |
246
|
|
|
protected string $description = 'The amount of cache hits.'; |
247
|
|
|
}, |
248
|
1 |
|
$this->data['opcache_statistics']['hits'] |
249
|
|
|
); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* @return MetricFamilySamples |
254
|
|
|
*/ |
255
|
1 |
|
public function started(): MetricFamilySamples |
256
|
|
|
{ |
257
|
1 |
|
return $this->sampled( |
258
|
1 |
|
new class extends Counter { |
259
|
|
|
protected ?string $namespace = 'php_opcache'; |
260
|
|
|
protected string $name = 'started'; |
261
|
|
|
protected string $description = 'The timestamp opcache has been started.'; |
262
|
|
|
}, |
263
|
1 |
|
$this->data['opcache_statistics']['start_time'] |
264
|
|
|
); |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
/** |
268
|
|
|
* @return MetricFamilySamples |
269
|
|
|
*/ |
270
|
1 |
|
public function restart(): MetricFamilySamples |
271
|
|
|
{ |
272
|
1 |
|
return $this->sampled( |
273
|
1 |
|
new class extends Counter { |
274
|
|
|
protected ?string $namespace = 'php_opcache'; |
275
|
|
|
protected string $name = 'last_restart'; |
276
|
|
|
protected string $description = 'The last timestamp opcache has been restarted.'; |
277
|
|
|
}, |
278
|
1 |
|
$this->data['opcache_statistics']['last_restart_time'] |
279
|
|
|
); |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
/** |
283
|
|
|
* @return MetricFamilySamples |
284
|
|
|
*/ |
285
|
1 |
|
public function oomRestarts(): MetricFamilySamples |
286
|
|
|
{ |
287
|
1 |
|
return $this->sampled( |
288
|
1 |
|
new class extends Counter { |
289
|
|
|
protected ?string $namespace = 'php_opcache'; |
290
|
|
|
protected string $name = 'restarts_oom_count'; |
291
|
|
|
protected string $description = 'The amount of out of memory restarts.'; |
292
|
|
|
}, |
293
|
1 |
|
$this->data['opcache_statistics']['oom_restarts'] |
294
|
|
|
); |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* @return MetricFamilySamples |
299
|
|
|
*/ |
300
|
1 |
|
public function hashRestarts(): MetricFamilySamples |
301
|
|
|
{ |
302
|
1 |
|
return $this->sampled( |
303
|
1 |
|
new class extends Counter { |
304
|
|
|
protected ?string $namespace = 'php_opcache'; |
305
|
|
|
protected string $name = 'restarts_hash_count'; |
306
|
|
|
protected string $description = 'The amount of hash table overflow restarts.'; |
307
|
|
|
}, |
308
|
1 |
|
$this->data['opcache_statistics']['hash_restarts'] |
309
|
|
|
); |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
/** |
313
|
|
|
* @return MetricFamilySamples |
314
|
|
|
*/ |
315
|
1 |
|
public function manualRestarts(): MetricFamilySamples |
316
|
|
|
{ |
317
|
1 |
|
return $this->sampled( |
318
|
1 |
|
new class extends Counter { |
319
|
|
|
protected ?string $namespace = 'php_opcache'; |
320
|
|
|
protected string $name = 'restarts_manual_count'; |
321
|
|
|
protected string $description = 'The amount of manual restarts.'; |
322
|
|
|
}, |
323
|
1 |
|
$this->data['opcache_statistics']['manual_restarts'] |
324
|
|
|
); |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
/** |
328
|
|
|
* @return MetricFamilySamples |
329
|
|
|
*/ |
330
|
1 |
|
public function misses(): MetricFamilySamples |
331
|
|
|
{ |
332
|
1 |
|
return $this->sampled( |
333
|
1 |
|
new class extends Counter { |
334
|
|
|
protected ?string $namespace = 'php_opcache'; |
335
|
|
|
protected string $name = 'cache_misses_count'; |
336
|
|
|
protected string $description = 'The amount of cache misses.'; |
337
|
|
|
}, |
338
|
1 |
|
$this->data['opcache_statistics']['misses'] |
339
|
|
|
); |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
/** |
343
|
|
|
* @return MetricFamilySamples |
344
|
|
|
*/ |
345
|
1 |
|
public function blacklistMisses(): MetricFamilySamples |
346
|
|
|
{ |
347
|
1 |
|
return $this->sampled( |
348
|
1 |
|
new class extends Counter { |
349
|
|
|
protected ?string $namespace = 'php_opcache'; |
350
|
|
|
protected string $name = 'cache_blacklist_misses_count'; |
351
|
|
|
protected string $description = 'The amount of blacklist cache misses.'; |
352
|
|
|
}, |
353
|
1 |
|
$this->data['opcache_statistics']['blacklist_misses'] |
354
|
|
|
); |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
/** |
358
|
|
|
* @return MetricFamilySamples |
359
|
|
|
*/ |
360
|
1 |
|
public function blacklistMissRatio(): MetricFamilySamples |
361
|
|
|
{ |
362
|
1 |
|
return $this->sampled( |
363
|
1 |
|
new class extends Gauge { |
364
|
|
|
protected ?string $namespace = 'php_opcache'; |
365
|
|
|
protected string $name = 'cache_blacklist_misses_percent'; |
366
|
|
|
protected string $description = 'The percentage of blacklist cache misses. '; |
367
|
|
|
}, |
368
|
1 |
|
$this->data['opcache_statistics']['blacklist_miss_ratio'] |
369
|
|
|
); |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
/** |
373
|
|
|
* @return MetricFamilySamples |
374
|
|
|
*/ |
375
|
1 |
|
public function hitRatio(): MetricFamilySamples |
376
|
|
|
{ |
377
|
1 |
|
return $this->sampled( |
378
|
1 |
|
new class extends Gauge { |
379
|
|
|
protected ?string $namespace = 'php_opcache'; |
380
|
|
|
protected string $name = 'cache_hit_percent'; |
381
|
|
|
protected string $description = 'The percentage of cache hits.'; |
382
|
|
|
}, |
383
|
1 |
|
$this->data['opcache_statistics']['opcache_hit_rate'] |
384
|
|
|
); |
385
|
|
|
} |
386
|
|
|
} |
387
|
|
|
|