Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions teslausb-www/html/cgi-bin/network_tx_bytes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

# Function to get the total tx_bytes for ethernet and wifi devices
get_tx_bytes() {
local total=0
for dev in /sys/class/net/eth* /sys/class/net/en* /sys/class/net/wl*; do
if [ -d "$dev" ] && [ -r "$dev/statistics/tx_bytes" ]; then
val=$(cat "$dev/statistics/tx_bytes")
total=$((total + val))
fi
done
echo $total
}

tx_bytes=$(get_tx_bytes)
sample_ms=$(date +%s%3N)

cat << EOF
HTTP/1.0 200 OK
Content-type: text/plain

${sample_ms} ${tx_bytes}
EOF

38 changes: 38 additions & 0 deletions teslausb-www/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,11 @@
</svg>
</span>
</div>
<div class="status_upload_throughput" style="display:none;">
<span>Upload Speed:
<span class="status_upload_throughput_info"></span>
</span>
</div>
<div class="status_throttled"></div>
</div>
<button class="group2" id="toggledrives" onclick="toggledrivesfunc();">...</button>
Expand Down Expand Up @@ -1694,8 +1699,40 @@
}

var statusvals;
var last_tx_bytes_sample;
const max_status_age = 4000;

function update_upload_throughput() {
var div = document.querySelector(".status_upload_throughput");
var uptimediv = document.querySelector(".status_uptime");
if (isElementVisible(uptimediv) || uptimediv.clientHeight == 0) {
readfile({url:'cgi-bin/network_tx_bytes.sh', callback:function(value) {
var parts = value.trim().split(/\s+/);
var sample_ms = parseInt(parts[0]);
var tx_bytes = parseInt(parts[1]);
if (!isNaN(sample_ms) && !isNaN(tx_bytes)) {
if (last_tx_bytes_sample != undefined) {
var elapsed_ms = sample_ms - last_tx_bytes_sample.sample_ms;
var delta_bytes = tx_bytes - last_tx_bytes_sample.tx_bytes;
if (elapsed_ms > 0 && delta_bytes >= 0) {
var speed = (delta_bytes * 1000) / elapsed_ms;
div.style.display = "inherit";
var span = document.querySelector(".status_upload_throughput_info");
span.innerText = byteRate(speed) + " (" + bitRate(speed) + ")";
} else {
div.style.display = "none";
}
}
last_tx_bytes_sample = {tx_bytes: tx_bytes, sample_ms: sample_ms};
} else {
div.style.display = "none";
last_tx_bytes_sample = undefined;
}
}});
}
setTimeout(update_upload_throughput, 1000);
}

function updateuptimeonly() {
if (statusvals != undefined) {
var status_age = (Date.now() - statusvals.retrieved);
Expand Down Expand Up @@ -1909,6 +1946,7 @@
readfile({pre:'archivelooppre', url:'archiveloop.log', tail:true, button:'aldwnbtn'});
readfile({pre:'setuplogpre', url:'teslausb-headless-setup.log', tail:true, button:'sudwnbtn'});
showstatus();
update_upload_throughput();
refreshdiagnostics();

var settingsbtn = document.querySelector('.settingsbutton');
Expand Down