mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
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:
@@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user