forked from j62/ctbrec
1
0
Fork 0

Add current bandwidth throughput to webinterface

This commit is contained in:
0xboobface 2020-06-12 19:11:14 +02:00
parent f45429a01e
commit a4ceb2f513
3 changed files with 26 additions and 8 deletions

View File

@ -23,6 +23,7 @@ import com.squareup.moshi.Moshi;
import ctbrec.Model;
import ctbrec.Recording;
import ctbrec.io.BandwidthMeter;
import ctbrec.io.InstantJsonAdapter;
import ctbrec.io.ModelJsonAdapter;
import ctbrec.recorder.Recorder;
@ -186,8 +187,13 @@ public class RecorderServlet extends AbstractCtbrecServlet {
resp.getWriter().write(response);
break;
case "space":
response = "{\"status\": \"success\", \"spaceTotal\": "+recorder.getTotalSpaceBytes()+", \"spaceFree\": "+recorder.getFreeSpaceBytes()+"}";
resp.getWriter().write(response);
JSONObject jsonResponse = new JSONObject();
jsonResponse.put("status", "success");
jsonResponse.put("spaceTotal", recorder.getTotalSpaceBytes());
jsonResponse.put("spaceFree", recorder.getFreeSpaceBytes());
jsonResponse.put("throughput", BandwidthMeter.getThroughput());
jsonResponse.put("throughputTimeframe", BandwidthMeter.MEASURE_TIMEFRAME.getSeconds());
resp.getWriter().write(jsonResponse.toString());
break;
case "changePriority":
recorder.priorityChanged(request.model);

View File

@ -122,13 +122,14 @@
<div class="row">
<div class="col-lg-4 mx-auto">
Space left: <span data-bind="text: space.text()"></span>
<div class="progress">
<div class="progress-bar progress-bar-striped" role="progressbar" aria-valuemin="0"
<span data-bind="text: throughput.text()" style="float:right"></span>
<span class="progress">
<span class="progress-bar progress-bar-striped" role="progressbar" aria-valuemin="0"
data-bind="attr: {'aria-valuemax': space.total, 'aria-valuenow': space.free},
style: { width: space.percent() + '%' },
text: space.percent() + '%'">
</div>
</div>
</span>
</span>
</div>
</div>
<div class="row">
@ -162,7 +163,7 @@
<button class="btn btn-secondary fa fa-download" title="Download recording" data-bind="enable: ko_status() == 'FINISHED' && singleFile, click: download"></button>
</td>
<td>
<button class="btn btn-secondary fa fa-trash" title="Delete recording" data-bind="enable: ko_status() == 'FINISHED', click: ctbrec.deleteRecording"></button>
<button class="btn btn-secondary fa fa-trash" title="Delete recording" data-bind="enable: (ko_status() == 'FINISHED' || ko_status() == 'WAITING'), click: ctbrec.deleteRecording"></button>
</td>
</tr>
</tbody>
@ -253,6 +254,11 @@
percent: ko.observable(0),
text: ko.observable('')
};
let throughput = {
bytes: ko.observable(0),
timeframe: ko.observable(0),
text: ko.observable('')
};
let hmac;
function addModelKeyPressed(e) {
@ -464,7 +470,8 @@
models : observableModelsArray,
recordings: observableRecordingsArray,
settings: observableSettingsArray,
space
space,
throughput
});
updateOnlineModels();

View File

@ -192,6 +192,11 @@ function updateDiskSpace() {
space.free(data.spaceFree);
space.percent((data.spaceFree / data.spaceTotal * 100).toFixed(2));
space.text(calculateSize(data.spaceFree) + ' / ' + calculateSize(data.spaceTotal));
throughput.bytes(data.throughput);
throughput.timeframe(data.throughputTimeframe);
let bytesPerSecond = data.throughput / data.throughputTimeframe;
console.log(data.throughput, data.throughputTimeframe, bytesPerSecond, calculateSize(bytesPerSecond) + '/s');
throughput.text(calculateSize(bytesPerSecond) + '/s');
} else {
if (console)
console.log('request failed', data);