Skip to content

Adding an "info" metric #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions includes/classes/Default_Metrics_Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace WP_Prometheus_Metrics;

use WP_Prometheus_Metrics\metrics\Database_Size_Metric;
use WP_Prometheus_Metrics\metrics\Info_Metric;
use WP_Prometheus_Metrics\metrics\Options_Autoloaded_Count_Metric;
use WP_Prometheus_Metrics\metrics\Options_Autoloaded_Size_Metric;
use WP_Prometheus_Metrics\metrics\Pending_Updates_Metric;
Expand All @@ -29,6 +30,7 @@ function load_default_metrics($metrics = [])
{
if (!$this->metrics_loaded) {
new Database_Size_Metric();
new Info_Metric();
new Options_Autoloaded_Count_Metric();
new Options_Autoloaded_Size_Metric();
new Pending_Updates_Metric();
Expand Down
40 changes: 40 additions & 0 deletions includes/classes/metrics/Info_Metric.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace WP_Prometheus_Metrics\metrics;


/**
* A metric that gives information about the WordPress environment.
*/
class Info_Metric extends Abstract_Gauge_Metric
{
public function __construct()
{
parent::__construct('info');
}

public function get_metric_labels(): array
{
global $wp_db_version;

return array_merge(
parent::get_metric_labels(),
[
'version' => get_bloginfo('version'),
'db_version' => $wp_db_version,
]
);
}

function get_metric_value()
{
// This metric as no value, the interesting part is in it's labels.
// Returning a standard 1 value here.
return 1;
}

function get_help_text(): string
{
return _x('Information about the WordPress environment', 'Metric Help Text', 'prometheus-metrics-for-wp');
}
}