bug fix: ping mean

This commit is contained in:
mantaohuang 2020-07-28 19:11:57 -04:00
parent 02bfc93351
commit d4f444940c
2 changed files with 38 additions and 10 deletions

View File

@ -118,11 +118,15 @@ class OManager:
time, value = line.split(",")
time = datetime.utcfromtimestamp(float(time))
value = float(value)
ping_tas.add(time, delta)
ping_tas.add(time, value)
def ping_mean(x):
x = numpy.array(x)
return numpy.mean(x[x > 0])
x = x[x > 0]
if len(x):
return numpy.mean(x)
else:
return numpy.nan
def ping_rate(x):
x = numpy.array(x)

View File

@ -359,8 +359,16 @@
</div>
</div>
<!-- Libs JS -->
<script src="./dist/libs/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="./dist/libs/jquery/dist/jquery-3.5.1.min.js"></script>
<!-- <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script> -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous">
</script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous">
</script>
<script src="./dist/libs/apexcharts/dist/apexcharts.min.js"></script>
<script src="./dist/libs/jqvmap/dist/jquery.vmap.min.js"></script>
<script src="./dist/libs/jqvmap/dist/maps/jquery.vmap.world.js"></script>
@ -408,6 +416,7 @@
labelString: 'Time'
},
ticks: {
source: "auto",
major: {
fontStyle: 'bold',
fontColor: '#FF0000'
@ -480,24 +489,38 @@
ovpn_table.append($(`<thead>
<tr>
<th>Connection name</th>
<th>Visitors</th>
<th>Unique</th>
<th>Status</th>
<th>Weight</th>
<th>Alive</th>
<th>Actions</th>
</tr>
</thead>`))
data.instances.forEach((instance, index) => {
var tr = `<tr>
var tr = $(`<tr>
<td>
${instance.name}
</td>
<td class="text-muted"></td>
<td class="text-muted"></td>
<td class="text-muted">${instance.status}</td>
<td class="text-muted">${instance.weight}</td>
<td class="text-muted">
<div class="chart-sparkline" id="sparkline-${index}"></div>
</td>
</tr>`
<td class="text-muted">
<a id="start_button_${instance.idx}" href="#!" data-placement="top" data-toggle="tooltip" title="start"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-md" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z"></path><path d="M18 15l-6-6l-6 6h12" transform="rotate(90 12 12)"></path></svg></a>
<a id="stop_button_${instance.idx}" href="#!" data-placement="top" data-toggle="tooltip" title="stop"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-md" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z"></path><rect x="4" y="4" width="16" height="16" rx="2"></rect></svg></a>
<a id="delete_button_${instance.idx}" href="#!" data-placement="top" data-toggle="tooltip" title="delete"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-md" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z"></path><line x1="4" y1="7" x2="20" y2="7"></line><line x1="10" y1="11" x2="10" y2="17"></line><line x1="14" y1="11" x2="14" y2="17"></line><path d="M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l1 -12"></path><path d="M9 7v-3a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3"></path></svg></a>
</td>
</tr>`);
ovpn_table.append(tr);
tr.find(`#delete_button_${instance.idx}`).click(() => {
$.get(`/remove?i=${instance.idx}`, update_stat);
})
tr.find(`#start_button_${instance.idx}`).click(() => {
$.get(`/start?i=${instance.idx}`, update_stat);
})
tr.find(`#stop_button_${instance.idx}`).click(() => {
$.get(`/stop?i=${instance.idx}`, update_stat);
})
$().peity && $(`#sparkline-${index}`).text(instance.ping_rate.join(", ")).peity("line", {
width: 64,
height: 40,
@ -506,6 +529,7 @@
fill: ["#d2e1f3"],
padding: .2,
});
$('[data-toggle="tooltip"]').tooltip()
});