add code for snmp targets, _bytes --> _bytes_total
This commit is contained in:
parent
0d0b5ac741
commit
8971a6cdf4
|
@ -1 +1,7 @@
|
|||
# promPHPWeathermap
|
||||
|
||||
to be put into the `lib/datasources` folder of your weathermap code
|
||||
|
||||
an example on how to use this is given within the datasource code itself
|
||||
|
||||
use this at your own risk, you probably can do this more elegant
|
|
@ -1,3 +1,16 @@
|
|||
<?php
|
||||
// Pluggable datasource for PHP Weathermap 0.9
|
||||
// - return values from prometheus
|
||||
|
||||
// for interfaces scraped via node_exporter
|
||||
// prometheus:instance:interface
|
||||
// Example: TARGET prometheus:suede0.hamburg.freifunk.net:ens2.310
|
||||
|
||||
// for interfaces scraped via snmp_exporter
|
||||
// the label to match the interface name with has to be given:
|
||||
// prometheus:instance:interface:label
|
||||
// Example: TARGET prometheus:192.168.112.30:ath0:ifDescr
|
||||
|
||||
<?php
|
||||
// Pluggable datasource for PHP Weathermap 0.9
|
||||
// - return a static value
|
||||
|
@ -25,8 +38,13 @@ class WeatherMapDataSource_prometheus extends WeatherMapDataSource {
|
|||
$router = $parts[1];
|
||||
$device = $parts[2];
|
||||
|
||||
$query_rx = "irate(node_network_receive_bytes{instance='$router:9100',device='$device'}[5m])";
|
||||
$query_tx = "irate(node_network_transmit_bytes{instance='$router:9100',device='$device'}[5m])";
|
||||
if (count($parts) > 3) {
|
||||
$query_rx = "irate(ifInOctets{instance='$router',$parts[3]='$device'}[10m])";
|
||||
$query_tx = "irate(ifOutOctets{instance='$router',$parts[3]='$device'}[10m])";
|
||||
} else {
|
||||
$query_rx = "irate(node_network_receive_bytes_total{instance='$router:9100',device='$device'}[5m])";
|
||||
$query_tx = "irate(node_network_transmit_bytes_total{instance='$router:9100',device='$device'}[5m])";
|
||||
}
|
||||
|
||||
$rx_rate = $this->prometheus_query($query_rx) * 8;
|
||||
$tx_rate = $this->prometheus_query($query_tx) * 8;
|
||||
|
@ -60,4 +78,4 @@ class WeatherMapDataSource_prometheus extends WeatherMapDataSource {
|
|||
}
|
||||
|
||||
// vim:ts=4:sw=4:
|
||||
?>
|
||||
?>
|
Loading…
Reference in a new issue