-
Notifications
You must be signed in to change notification settings - Fork 101
/
prometheus.php
63 lines (54 loc) · 2.43 KB
/
prometheus.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
<?php
use Automattic\VIP\Feature;
use Automattic\VIP\Prometheus\APCu_Collector;
use Automattic\VIP\Prometheus\Cache_Collector;
use Automattic\VIP\Prometheus\Login_Stats_Collector;
use Automattic\VIP\Prometheus\OpCache_Collector;
use Automattic\VIP\Prometheus\Post_Stats_Collector;
use Automattic\VIP\Prometheus\User_Stats_Collector;
use Automattic\VIP\Prometheus\Error_Stats_Collector;
use Automattic\VIP\Prometheus\Potential_Multi_Dataset_Queries_Collector;
use Automattic\VIP\Prometheus\Multisite_Stats_Collector;
// @codeCoverageIgnoreStart -- this file is loaded before tests start
if ( defined( 'ABSPATH' ) ) {
require_once __DIR__ . '/prometheus/index.php';
$files = [
'/prometheus-collectors/class-cache-collector.php',
'/prometheus-collectors/class-apcu-collector.php',
'/prometheus-collectors/class-opcache-collector.php',
'/prometheus-collectors/class-login-stats-collector.php',
'/prometheus-collectors/class-error-stats-collector.php',
'/prometheus-collectors/class-multisite-stats-collector.php',
];
$should_enable_user_collector = Feature::is_enabled( 'prom-user-collection' );
if ( $should_enable_user_collector ) {
$files[] = '/prometheus-collectors/class-user-stats-collector.php';
}
if ( true === defined( 'VIP_POTENTIAL_MULTI_DATASET_QUERIES_COLLECTOR_ENABLED' ) && true === constant( 'VIP_POTENTIAL_MULTI_DATASET_QUERIES_COLLECTOR_ENABLED' ) ) {
$files[] = '/prometheus-collectors/class-potential-multi-dataset-queries-collector.php';
}
foreach ( $files as $file ) {
if ( file_exists( __DIR__ . $file ) ) {
require_once __DIR__ . $file;
}
}
add_filter( 'vip_prometheus_collectors', function ( array $collectors ): array {
$to_init = [
'cache' => Cache_Collector::class,
'apcu' => APCu_Collector::class,
'opcache' => OpCache_Collector::class,
'login' => Login_Stats_Collector::class,
'error' => Error_Stats_Collector::class,
'user' => User_Stats_Collector::class,
'potential_multi_dataset_queries' => Potential_Multi_Dataset_Queries_Collector::class,
'multisite' => Multisite_Stats_Collector::class,
];
foreach ( $to_init as $slug => $class ) {
if ( class_exists( $class ) && ! isset( $collectors[ $slug ] ) ) {
$collectors[ $slug ] = new $class();
}
}
return $collectors;
} );
}
// @codeCoverageIgnoreEnd