BT Home Hub 5 usage – follow up

The BT Home Hub project is now almost finished, its just the last few quirks to work out and fix. For the last time, I’ve added a new module to my monitoring dashboard which allows me to see usage against time.

A spike in sent and received usage @ 2am
A spike in sent and received usage @ 2am

While checking out whether this page was working, I noticed an interesting spike in both sent and received traffic…

The obvious issue is that the uptime dropped to zero; but I looked at was the underlying data for more information, which quickly showed what had happened.

Database view of the BT Home Hub statistics
Database view of the BT Home Hub statistics

The HH decided that enough was enough, and restarted at around 1 minute past 2 on Tuesday morning causing the counters to reset. Because the entries were then lower than the previous, my script assumed that a roll-over had occurred and added 4295 to the difference.

It appears as though it’ll be necessary to compare the uptimes when deciding whether a roll-over has occurred. My new collection script is below:

[php]
/**
* Accepts objects:
* uptime->
* received->
* sent->
*
* Compares the 2 and determines the difference for the required $element
*
* @param stdClass $current Objects containing uptime, received and sent figures
* @param stdClass $previous
* @param string $element Either ‘received’ or ‘sent’
* @return number
*/
function determineUsage(stdClass $current, stdClass $previous, $element) {
// If we don’t have a previous value then we can’t figure out a difference
if (is_null($previous->uptime)) {
return 0;
}

// Calculate the difference
$difference = $current->$element – $previous->$element;

// If the uptime is less than before, don’t add a rollover difference modifier
$uptime_difference = $current->uptime – $previous->uptime;
if ($uptime_difference < 0) {
return $difference;
}

if ($difference < 0) {
// If the usage is greater than 4295 it resets – http://s-parker.uk/2014/08/monitoring-bt-home-hub-5-usage
// If we have a negative number then it means we passed the rollover point
// Add the rollover amount to the difference and we get the correct value
$difference += 4295;
}

return $difference;
}
[/php]

This seems to have fixed the issue.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.