Modified Prometheus extension to support adding a prefix to metric names (#13272)

* Modified Prometheus extension to allow for a configurable prefix on metric names.

* Added reference in config_definitions.json and updated docs.

* Fixed whitespace in config_definitions.json.

* Added reference to prometheus.prefix in settings.php

* Defined prefix var as private in Prometheus.php
This commit is contained in:
Cathal Mooney
2021-09-29 01:30:28 +01:00
committed by GitHub
parent 66dddbaa66
commit 6bfe1555be
4 changed files with 39 additions and 1 deletions

View File

@@ -38,6 +38,7 @@ class Prometheus extends BaseDatastore
private $base_uri;
private $default_opts;
private $enabled;
private $prefix;
public function __construct(\GuzzleHttp\Client $client)
{
@@ -47,6 +48,10 @@ class Prometheus extends BaseDatastore
$url = Config::get('prometheus.url');
$job = Config::get('prometheus.job', 'librenms');
$this->base_uri = "$url/metrics/job/$job/instance/";
$this->prefix = Config::get('prometheus.prefix', '');
if ($this->prefix) {
$this->prefix = "$this->prefix" . '_';
}
$this->default_opts = [
'headers' => ['Content-Type' => 'text/plain'],
@@ -82,7 +87,7 @@ class Prometheus extends BaseDatastore
foreach ($fields as $k => $v) {
if ($v !== null) {
$vals .= "$k $v\n";
$vals .= $this->prefix . "$k $v\n";
}
}