Can a Firebase client determine the bytes sent and received?

While inspecting the structure of the various Firebase JavaScript objects in the browser's console, I noticed that some objects have these properties:

bytes_received: 429
bytes_sent: 64

This seems to indicate the amount of data that was sent and received for this node/ref/snapshot.

Is there a structured way for a client to access this information?

Answers:

Answer

Not really. :-)

You're seeing some internal stats the client keeps track of. The only way to get at them is with:

Firebase.INTERNAL.stats(firebaseRef);

And it'll dump them to the console. (Note that the stats are for all interactions with the Firebase, not just that particular firebaseRef.)

This isn't a supported API and could disappear or change at any time. It also may not match up exactly with what you see in the Forge dashboard (the client is unaware of some of the transport overhead that goes on). But if it helps you at all during development / debugging, great.

Answer

Since Firebase.INTERNAL.stats(ref) only dumps the stats to the console, I've written a module, firebase-stats, that does naughty things to access and return the byte stats so that you can do more useful programmatic things with the information.

var firebaseStats = require('firebase-stats'),
    Firebase = require('firebase'),
    ref = new Firebase('https://docs-examples.firebaseio.com');

firebaseStats(ref); // -> { bytes_received: 287, bytes_sent: 58 }

This works by looking for an object with a property called bytes_sent. This should continue to work across releases, but we're obviously well in to undocumented internal territory, so this comes with absolutely no warranty; use at your own risk. This module will throw if it can't find the stats object.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.