add code for snmp targets, _bytes --> _bytes_total

This commit is contained in:
ohrensessel 2019-06-07 08:51:51 +02:00
parent 0d0b5ac741
commit 8971a6cdf4
2 changed files with 27 additions and 3 deletions

View file

@ -1 +1,7 @@
# promPHPWeathermap # 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

View file

@ -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 <?php
// Pluggable datasource for PHP Weathermap 0.9 // Pluggable datasource for PHP Weathermap 0.9
// - return a static value // - return a static value
@ -25,8 +38,13 @@ class WeatherMapDataSource_prometheus extends WeatherMapDataSource {
$router = $parts[1]; $router = $parts[1];
$device = $parts[2]; $device = $parts[2];
$query_rx = "irate(node_network_receive_bytes{instance='$router:9100',device='$device'}[5m])"; if (count($parts) > 3) {
$query_tx = "irate(node_network_transmit_bytes{instance='$router:9100',device='$device'}[5m])"; $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; $rx_rate = $this->prometheus_query($query_rx) * 8;
$tx_rate = $this->prometheus_query($query_tx) * 8; $tx_rate = $this->prometheus_query($query_tx) * 8;