Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bandwidth tracking and reporting #1860

Open
ryangriggs opened this issue May 9, 2024 · 5 comments
Open

Bandwidth tracking and reporting #1860

ryangriggs opened this issue May 9, 2024 · 5 comments

Comments

@ryangriggs
Copy link

Is your feature request related to a problem? Please describe.
No. My feature request is related to monitoring statistics of the MQTT connection.

Describe the solution you'd like
It would be nice to have some telemetry properties available in the MQTT class, that provide tracking of the following connection statistics:

  • Bandwidth usage (upload and download as separate properties)

  • Number of reconnections

  • Also expose functions or setters to reset the counters as needed. (Don't reset between connections)

Example usage:

// Create a mqtt object and connect to the server:
const mqtt = require('mqtt');
mqtt.connectAsync(uri, { ...props })
.then((conn) => {
   // On successful connection, set up a repeating task to log bandwidth usage
   setInterval( ()=> { bandwidthReport(conn); }, 60000 );
});

function bandwidthReport(connection)
{
    console.log(`MQTT Bandwidth Usage:  Download: ${connection.bandwidthDownload} bytes, Upload: ${connection.bandwithUpload} bytes, Reconnections: ${connection.reconnectionCount}`);
}

These parameters should already be available from the underlying socket object, or could easily be counted within the methods which transmit data over the wire (i.e. before calling socket.write() and within the data event handler).

Describe alternatives you've considered
N/A

Additional context

@robertsLando
Copy link
Member

Would you like to submit a PR? I would enable statistics tracking behind an option BTW

@ryangriggs
Copy link
Author

Would you like to submit a PR? I would enable statistics tracking behind an option BTW

Can you explain what you mean "behind an option"? Do you mean that they can be enabled/disabled by setting a flag (i.e. give the user an option to enable them) or do you mean behind an optional plugin of some sort? Sorry for the confusion.

@robertsLando
Copy link
Member

Behind a client option because this comes with a little overhead that some users may want to avoid if not needed :)

@ryangriggs
Copy link
Author

So, something like a client.statisticsEnabled boolean on the client instance (disabled by default), which would enable stats tracking if set to true?

@robertsLando
Copy link
Member

yeah

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants