From 0e7f26f7e878f989e4cff25aca9ffafc93685dca Mon Sep 17 00:00:00 2001 From: Oliver Herms Date: Thu, 7 Dec 2017 21:22:15 +0100 Subject: [PATCH] Init --- promPHPWeathermap.php | 63 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 promPHPWeathermap.php diff --git a/promPHPWeathermap.php b/promPHPWeathermap.php new file mode 100644 index 0000000..3da1f90 --- /dev/null +++ b/promPHPWeathermap.php @@ -0,0 +1,63 @@ +prometheus_query($query_rx) * 8; + $tx_rate = $this->prometheus_query($query_tx) * 8; + + return ( array($rx_rate, $tx_rate, 0) ); + } + + function prometheus_query($query) + { + $time = time(); + $query = urlencode($query); + $url = "http://localhost:9090/api/v1/query?time=$time&query=$query"; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + $content = curl_exec($ch); + $data = json_decode($content, true); + + if ($data['status'] != "success") + { + return -1; + } + + if ($data['data']['resultType'] != "vector") + { + return -1; + } + + return $data['data']['result'][0]['value'][1]; + } +} + +// vim:ts=4:sw=4: +?>