This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
projects:gigacube [2021/04/29 01:56] admin created |
projects:gigacube [2021/04/29 15:54] (current) admin |
||
---|---|---|---|
Line 5: | Line 5: | ||
</code> | </code> | ||
- | Then I wrote a quick PHP script to extract that information: | + | That URL returns XML data in this format: |
+ | <code xml> | ||
+ | <?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> | ||
+ | </code> | ||
+ | |||
+ | Then I wrote a quick PHP script to extract that information and send it to my influx database: | ||
<code php extract-gigacube.php> | <code php extract-gigacube.php> | ||
Line 27: | Line 45: | ||
// this outputs the current download rate (in bytes/second) as reported by the device: | // this outputs the current download rate (in bytes/second) as reported by the device: | ||
// echo $xml->CurrentDownloadRate; | // echo $xml->CurrentDownloadRate; | ||
- | |||
// I build a single line payload for my influx database | // I build a single line payload for my influx database | ||
Line 38: | Line 55: | ||
$payload = trim($payload,","); | $payload = trim($payload,","); | ||
- | // That looks something like this: | + | // 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 | // huawei CurrentConnectTime=92016,CurrentUpload=5832119940,CurrentDownload=32772130236,CurrentDownloadRate=895,CurrentUploadRate=1539,TotalUpload=824477229102,TotalDownload=5553380109187,TotalConnectTime=15820842,MaxUploadRate=8737338,MaxDownloadRate=41668223 | ||
Line 50: | Line 67: | ||
</code> | </code> | ||
- | I can then plot these in Grafana (in bytes/second) using a query like this (remember and set the units to bytes/second): | + | 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: |
<code> | <code> | ||
SELECT derivative(mean("CurrentDownload"), 1s)*8 FROM "huawei" WHERE $timeFilter GROUP BY time($__interval) fill(null) | SELECT derivative(mean("CurrentDownload"), 1s)*8 FROM "huawei" WHERE $timeFilter GROUP BY time($__interval) fill(null) | ||
</code> | </code> | ||
+ | Gets me pretty accurate usage information (which I then plot in Grafana). | ||
+ | |||
+ | {{:projects:pasted:20210429-155433.png}} |