Server Status Total Bandwidth

Hey guys,

I know some of you like me use GitHub - IIPoliII/ServerStatus: Display and monitor your servers statistics in a beatiful way (or botox one)
But I was wondering if someone has an idea of how I could do it to add the value of every bandwidth.
This is really a specific part of the code, but i know that some of you are more skilled than me in JS. I litterlay don’t know why but JS is the language i definitly can’t fucking read.

I tried something like this

                TotalBandwidth = result.servers[i].network_rx.toFixed(0) + LastestBandwidth;
				if (TotalBandwidth < 1000)
					TotalBandwidthText = TotalBandwidth + "B";
				else if (TotalBandwidth < 1000 * 1000)
					TotalBandwidthText = (TotalBandwidth / 1000 / 1000).toFixed(0) + "K";
					TotalBandwidthText = (TotalBandwidth / 1000 / 1000 / 1000).toFixed(1) + "M";

				$("#TotalBandwidth").html("Total Bandwidth : " + TotalBandwidthText);
				if (i != "0") {
					LastestBandwidth = result.servers[i].network_rx.toFixed(0);

Thanks for your help as always :stuck_out_tongue:

Why don’t you just cat /sys/class/net/eth0/statistics/rx_bytes on the clients rather than using a counter which will be highly unreliable, even if your refresh rate is set to 1 second.


Have you considered using Netdata? You should be able to do something like this with it, either through its customizable JS widgets or by directly hitting its API.

1 Like

Netdata is great :slight_smile:

1 Like

It’s also more efficient than a lot of other scripts because the core is written in C.


Ah don’t get me wrong the app it self is written in C it’s just named like this in the json.

I know about netdata but i don’t wanna put a lot of time on decoding their API again and bound every server together :C

Just curious what exactly you’re trying to do here since I also use the ServerStatus program ( Are you just trying to total up the current bandwidth of ALL servers into one metric and display that?

1 Like

Exaccttllyyy what I want c:

You can pass the --disable-cloud parameter to the Agent installation when using a kickstart script ( or, or a manual installation from Git.

When you pass this parameter, the installer does not download or compile any extra libraries. Once running, the Agent kills the thread responsible for the ACLK and claiming behavior, and behaves as though the ACLK, and thus Netdata Cloud, does not exist.

1 Like

Try this. You’ll need to call it every time the stats json is called.

function total_network() {
	var bw_in_total = 0;
	var bw_out_total = 0;
	var bw_in = 0;
	var bw_out = 0;
	var bw_in_size = "";
	var bw_out_size = "";
	var cnt = 0;
	$('[id="network"]').each(function() {
		if(cnt > 1) {
			// IN
			bw_in = $(this).text().split("|")[0];
			bw_in_size = bw_in.slice(-1);
			bw_in = bw_in.slice(0, -1);
			if(bw_in_size == 'K') {bw_in *= 1000;}
			if(bw_in_size == 'M') {bw_in *= 1000000;}
			bw_in_total += bw_in; // Ttoal in B
			// OUT
			bw_out = $(this).text().split("|")[1];
			bw_out_size = bw_out.slice(-1);
			bw_out = bw_out.slice(0, -1);
			if(bw_out_size == 'K') {bw_out *= 1000;}
			if(bw_out_size == 'M') {bw_out *= 1000000;}
			bw_out_total += bw_out; // Ttoal in B
	// Debug
	console.log('Total BW In: ' + bw_in_total);
	console.log('Total BW Out: ' + bw_out_total);

	// Insert values into element
	$('#TotalBandwidthIn').text('Total Bandwidth In: ' + bw_in_total);
	$('#TotalBandwidthOut').text('Total Bandwidth Out: ' + bw_out_total);

Mhmm very intressting. Didn’t knew about that.


damn thanks a lot for your work i will check that right now if i can make it work.
Thanks for the time that you too to work on it! :+1:

Niether i am really bad or i didn’t understood something so right i should declare my function then i call it every time the json is updated but what does $('[id="network"]').each(function () { define?

I pasted the code here if needed.

I will try my way around but god damn js is really not my cup of tea. It’s weird i had no big issues understand Go or Java it self. But JS like what?

I am really thank ful for your work Andrei and this page doesn’t mean we stop using hetrixtools :stuck_out_tongue: it’s an addition to it c: I find it awesome you help me set it up.

1 Like

Yes, declare it in the serverstatus.js file and call it in the uptime() function when the json file is fetched.

It’s jQuery to parse the network values on the page by looping over all the network row values on the page. Personally, I would use the ‘result’ variable in uptime(), which holds the raw json results, rather than getting what’s on the page.

1 Like

I tried like you said but the page froze XD

  • Between yes i failed frankenstein with flankenstein

Do you have an element with IDs ‘TotalBandwidthIn’ and ‘TotalBandwidthOut’ on the page?

1 Like


Yeah like this c:

			<div id="TotalBandwidthIn">Total Bandwidth In updating...</div>
			<div id="TotalBandwidthOut">Total Bandwidth Out updating...</div>

As @Manson said that bit of code gets the network values from your status page and then for each of them it figures out the in/out traffic and adds that up.

Reading the data from what’s on the page already I would load it after the page has finished loading and I’d then call it after new data is pushed by whatever function pushes data into the page from the stats json.

1 Like

Yeah i see. I will try to change a bit to have the raw json values. But sadly i don’t exactly understand on how i could do it. Since i need to loop trought each values. And add them it looks easy like doing bw_in = result.servers[i].network_rx + bw_in but didn’t exactly worked for me

Use developer tools → console. ‘bw_out is undefined’

1 Like

Oh wait yes wtf