-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Added Prometheus PushGateway metric support (#8437)
* Added Prometheus PushGateway support * fixed formatting * fix set_curl_proxy to correct variable * add documentation * Update Metric-Storage.md * Update mkdocs.yml
- Loading branch information
Showing
11 changed files
with
136 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<meta http-equiv="refresh" content="0; url=/Extensions/metrics/Prometheus/" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
source: Extensions/metrics/Prometheus.md | ||
# Enabling support for Prometheus. | ||
|
||
Please be aware Prometheus support is alpha at best, It hasn't been extensively tested and is still in development | ||
All it provides is the sending of data to a a Prometheus PushGateway. Please be careful when enabling this support | ||
you use it at your own risk! | ||
|
||
### Requirements (Older versions may work but haven't been tested | ||
- Prometheus >= 2.0 | ||
- PushGateway >= 0.4.0 | ||
- Grafana | ||
- PHP-CURL | ||
|
||
The setup of the above is completely out of scope here and we aren't really able to provide any help with this side | ||
of things. | ||
|
||
### What you don't get | ||
- Pretty graphs, this is why at present you need Grafana. You need to build your own graphs within Grafana. | ||
- Support for Prometheus or Grafana, we would highly recommend that you have some level of experience with these. | ||
|
||
RRD will continue to function as normal so LibreNMS itself should continue to function as normal. | ||
|
||
### Configuration | ||
```php | ||
$config['prometheus']['enable'] = true; | ||
$config['prometheus']['url'] = 'http://127.0.0.1:9091'; | ||
$config['prometheus']['job'] = 'librenms'; # Optional | ||
``` | ||
|
||
|
||
### Sample Prometheus Scrape Config (for scraping the Push Gateway) | ||
```yml | ||
- job_name: pushgateway | ||
scrape_interval: 300s | ||
honor_labels: true | ||
static_configs: | ||
- targets: ['127.0.0.1:9091'] | ||
``` | ||
The same data then stored within rrd will be sent to Prometheus and recorded. You can then create graphs within Grafana | ||
to display the information you need. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
/* | ||
* LibreNMS | ||
* | ||
* Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk/fa> | ||
* | ||
* This program is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License as published by the | ||
* Free Software Foundation, either version 3 of the License, or (at your | ||
* option) any later version. Please see LICENSE.txt at the top level of | ||
* the source code distribution for details. | ||
*/ | ||
|
||
function prometheus_push($device, $measurement, $tags, $fields) | ||
{ | ||
global $prometheus, $config; | ||
if ($config['prometheus']['enable'] === true) { | ||
if ($prometheus !== false) { | ||
try { | ||
$ch = curl_init(); | ||
|
||
set_curl_proxy($ch); | ||
$vals = ""; | ||
$promtags = "/measurement/".$measurement; | ||
|
||
foreach ($fields as $k => $v) { | ||
if ($v !== null) { | ||
$vals = $vals . "$k $v\n"; | ||
} | ||
} | ||
|
||
foreach ($tags as $t => $v) { | ||
if ($v !== null) { | ||
$promtags = $promtags . "/$t/$v"; | ||
} | ||
} | ||
|
||
$promurl = $config['prometheus']['url'].'/metrics/job/'.$config['prometheus']['job'].'/instance/'.$device['hostname'].$promtags; | ||
$promurl = str_replace(" ", "-", $promurl); // Prometheus doesn't handle tags with spaces in url | ||
|
||
d_echo("\nPrometheus data:\n"); | ||
d_echo($measurement); | ||
d_echo($tags); | ||
d_echo($fields); | ||
d_echo($vals); | ||
d_echo($promurl); | ||
d_echo("\nEND\n"); | ||
|
||
curl_setopt($ch, CURLOPT_URL, $promurl); | ||
curl_setopt($ch, CURLOPT_POST, 1); | ||
curl_setopt($ch, CURLOPT_POSTFIELDS, $vals); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | ||
|
||
$headers = array(); | ||
$headers[] = "Content-Type: test/plain"; | ||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | ||
|
||
|
||
curl_exec($ch); | ||
|
||
if (curl_errno($ch)) { | ||
d_echo('Error:' . curl_error($ch)); | ||
} | ||
} catch (Exception $e) { | ||
d_echo("Caught exception: " . $e->getMessage() . PHP_EOL); | ||
d_echo($e->getTrace()); | ||
} | ||
} else { | ||
c_echo("[%gPrometheus Push Disabled%n]\n"); | ||
}//end if | ||
}//end if | ||
}// end prometheus_push |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters