File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed
Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change 33namespace WP_Prometheus_Metrics ;
44
55use WP_Prometheus_Metrics \metrics \Database_Size_Metric ;
6+ use WP_Prometheus_Metrics \metrics \Info_Metric ;
67use WP_Prometheus_Metrics \metrics \Options_Autoloaded_Count_Metric ;
78use WP_Prometheus_Metrics \metrics \Options_Autoloaded_Size_Metric ;
89use WP_Prometheus_Metrics \metrics \Pending_Updates_Metric ;
@@ -29,6 +30,7 @@ function load_default_metrics($metrics = [])
2930 {
3031 if (!$ this ->metrics_loaded ) {
3132 new Database_Size_Metric ();
33+ new Info_Metric ();
3234 new Options_Autoloaded_Count_Metric ();
3335 new Options_Autoloaded_Size_Metric ();
3436 new Pending_Updates_Metric ();
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace WP_Prometheus_Metrics \metrics ;
4+
5+
6+ /**
7+ * A metric that gives information about the WordPress environment.
8+ */
9+ class Info_Metric extends Abstract_Gauge_Metric
10+ {
11+ public function __construct ()
12+ {
13+ parent ::__construct ('info ' );
14+ }
15+
16+ public function get_metric_labels (): array
17+ {
18+ global $ wp_db_version ;
19+
20+ return array_merge (
21+ parent ::get_metric_labels (),
22+ [
23+ 'version ' => get_bloginfo ('version ' ),
24+ 'db_version ' => $ wp_db_version ,
25+ ]
26+ );
27+ }
28+
29+ function get_metric_value ()
30+ {
31+ // This metric as no value, the interesting part is in it's labels.
32+ // Returning a standard 1 value here.
33+ return 1 ;
34+ }
35+
36+ function get_help_text (): string
37+ {
38+ return _x ('Information about the WordPress environment ' , 'Metric Help Text ' , 'prometheus-metrics-for-wp ' );
39+ }
40+ }
You can’t perform that action at this time.
0 commit comments