User Tools

Site Tools


projects:gigacube

Monitoring: Huawei Vodafone 5G Gigacube

I wanted to get some bandwith statistics from my Gigacube. After browsing around in the web interface I found an unauthenicated API that has most of what I need.

http://192.168.8.1/api/monitoring/traffic-statistics

That URL returns XML data in this format:

<?xml version="1.0" encoding="UTF-8"?>
<response>
<CurrentConnectTime>92016</CurrentConnectTime>
<CurrentUpload>5832119940</CurrentUpload>
<CurrentDownload>32772130236</CurrentDownload>
<CurrentDownloadRate>895</CurrentDownloadRate>
<CurrentUploadRate>1539</CurrentUploadRate>
<TotalUpload>824477229102</TotalUpload>
<TotalDownload>5553380109187</TotalDownload>
<TotalConnectTime>15820842</TotalConnectTime>
<showtraffic>1</showtraffic>
<MaxUploadRate>8737338</MaxUploadRate>
<MaxDownloadRate>41668223</MaxDownloadRate>
</response>

Then I wrote a quick PHP script to extract that information and send it to my influx database:

extract-gigacube.php
$url = "http://192.168.8.1/api/monitoring/traffic-statistics";
$data = file_get_contents($url);
$xml = new SimpleXmlElement($data);
 
$variables = array(
        "CurrentConnectTime",
        "CurrentUpload",
        "CurrentDownload",
        "CurrentDownloadRate",
        "CurrentUploadRate",
        "TotalUpload",
        "TotalDownload",
        "TotalConnectTime",
//      "showtraffic",           // this doesn't seem to change from '1' so I just ignore it
        "MaxUploadRate",
        "MaxDownloadRate");
 
// this outputs the current download rate (in bytes/second) as reported by the device:
// echo $xml->CurrentDownloadRate;
 
// I build a single line payload for my influx database
$payload = "huawei ";
 
foreach($variables as $var) {
        $payload .= "$var=".$xml->$var.",";
}
 
$payload = trim($payload,",");
 
// That looks something like this (timestamp is automatically appended):
// huawei CurrentConnectTime=92016,CurrentUpload=5832119940,CurrentDownload=32772130236,CurrentDownloadRate=895,CurrentUploadRate=1539,TotalUpload=824477229102,TotalDownload=5553380109187,TotalConnectTime=15820842,MaxUploadRate=8737338,MaxDownloadRate=41668223
 
// Then post it to my influx database:
$url = "https://yourinfluxserver/write?db=huawei";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$response = curl_exec($ch);

I run this every minute in a cron job (I could run it more often, but I'm happy with the accuracy I get - CurrentDownRate is very accurate and updated every second it seems, but using the CurrentDownload field (and working out a derivative) using:

SELECT derivative(mean("CurrentDownload"), 1s)*8 FROM "huawei" WHERE $timeFilter GROUP BY time($__interval) fill(null)

Gets me pretty accurate usage information (which I then plot in Grafana).

projects/gigacube.txt · Last modified: 2021/04/29 14:54 by admin