interface test

This commit is contained in:
mantaohuang 2020-07-28 00:20:07 -04:00
parent 6d405bb052
commit 53783025e2
7 changed files with 111 additions and 102 deletions

View File

@ -6,7 +6,7 @@ WORKDIR /ovpn-lb-socks5/go-socks-lb
RUN go build RUN go build
FROM alpine:latest AS python-builder FROM alpine:latest AS python-builder
RUN apk --no-cache add git python3 python3-dev linux-headers musl-dev gcc RUN apk --no-cache add git python3 python3-dev linux-headers musl-dev gcc make automake gcc g++
WORKDIR / WORKDIR /
RUN git clone https://git.hmthsn.com/mantao/ovpn-lb-socks5.git mop RUN git clone https://git.hmthsn.com/mantao/ovpn-lb-socks5.git mop
WORKDIR /mop WORKDIR /mop

View File

@ -1,5 +1,6 @@
humanize==2.4.0 humanize==2.4.0
netaddr==0.7.19 netaddr==0.7.19
numpy==1.19.1
openvpn-api==0.3.0 openvpn-api==0.3.0
openvpn-status==0.2.1 openvpn-status==0.2.1
psutil==5.7.0 psutil==5.7.0

View File

@ -124,8 +124,8 @@ class OManager:
def ping_rate(x): def ping_rate(x):
x = numpy.array(x) x = numpy.array(x)
if len(x)==0: if len(x) == 0:
return numpy.nan return 0
return numpy.count_nonzero(x > 0)/len(x) return numpy.count_nonzero(x > 0)/len(x)
stat.append({ stat.append({

View File

@ -21,10 +21,23 @@ class TimeSeriesAccumulator:
idx = int((timestamp - self.start_timestamp)/self.bin_time) idx = int((timestamp - self.start_timestamp)/self.bin_time)
self.data[idx].append(value) self.data[idx].append(value)
def get_f(self, f): def get_f(self, f, initial=0):
return [f(i) for i in self.data] prev = initial
result = []
for i in self.data:
new = f(i)
if new == numpy.nan:
result.append(prev)
else:
result.append(new)
prev = new
return result
def get_ts(self):
return [f(i) for i in self.data]
def get_ts(self):
return [datetime.utcfromtimestamp(self.start_timestamp+(i+1)*self.bin_time) for i in range(self.n_bins)] return [datetime.utcfromtimestamp(self.start_timestamp+(i+1)*self.bin_time) for i in range(self.n_bins)]

File diff suppressed because one or more lines are too long

View File

@ -421,7 +421,7 @@
</div> </div>
<!-- Libs JS --> <!-- Libs JS -->
<script src="./dist/libs/bootstrap/dist/js/bootstrap.bundle.min.js"></script> <script src="./dist/libs/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="./dist/libs/jquery/dist/jquery.slim.min.js"></script> <script src="./dist/libs/jquery/dist/jquery-3.5.1.min.js"></script>
<script src="./dist/libs/apexcharts/dist/apexcharts.min.js"></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/jquery.vmap.min.js"></script>
<script src="./dist/libs/jqvmap/dist/maps/jquery.vmap.world.js"></script> <script src="./dist/libs/jqvmap/dist/maps/jquery.vmap.world.js"></script>
@ -430,6 +430,7 @@
<script src="./dist/js/tabler.min.js"></script> <script src="./dist/js/tabler.min.js"></script>
<script> <script>
$.get("/stat", function (data) {
// @formatter:off // @formatter:off
document.addEventListener("DOMContentLoaded", function () { document.addEventListener("DOMContentLoaded", function () {
window.ApexCharts && (new ApexCharts(document.getElementById('chart-mentions'), { window.ApexCharts && (new ApexCharts(document.getElementById('chart-mentions'), {
@ -458,21 +459,14 @@
opacity: 0.6, opacity: 0.6,
}, },
series: [{ series: [{
name: "Web", name: "Down rate",
data: [1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 2, 12, 5, 8, 22, 6, 8, 6, 4, 1, 8, 24, 29, 51, 40, 47, 23, data: data.stat[0].io_mean
26, 50, 26, 41, 22, 46, 47, 81, 46, 6
]
}, { }, {
name: "Social", name: "Up rate",
data: [2, 5, 4, 3, 3, 1, 4, 7, 5, 1, 2, 5, 3, 2, 6, 7, 7, 1, 5, 5, 2, 12, 4, 6, 18, 3, 5, 2, 13, data: data.stat[0].io_mean
15, 20, 47, 18, 15, 11, 10, 0
]
}, { }, {
name: "Other", name: "d rate",
data: [2, 9, 10, 7, 8, 3, 6, 5, 5, 4, 6, 4, 1, 9, 3, 6, 7, 5, 2, 8, 4, 9, 1, 2, 6, 7, 5, 1, 8, data: data.stat[0].io_mean
3,
2, 3, 4, 9, 7, 1, 6
]
}], }],
grid: { grid: {
padding: { padding: {
@ -505,14 +499,7 @@
padding: 4 padding: 4
}, },
}, },
labels: [ labels: data.time,
'2020-06-20', '2020-06-21', '2020-06-22', '2020-06-23', '2020-06-24', '2020-06-25', '2020-06-26',
'2020-06-27', '2020-06-28', '2020-06-29', '2020-06-30', '2020-07-01', '2020-07-02', '2020-07-03',
'2020-07-04', '2020-07-05', '2020-07-06', '2020-07-07', '2020-07-08', '2020-07-09', '2020-07-10',
'2020-07-11', '2020-07-12', '2020-07-13', '2020-07-14', '2020-07-15', '2020-07-16', '2020-07-17',
'2020-07-18', '2020-07-19', '2020-07-20', '2020-07-21', '2020-07-22', '2020-07-23', '2020-07-24',
'2020-07-25', '2020-07-26'
],
colors: ["#206bc4", "#79a6dc", "#bfe399"], colors: ["#206bc4", "#79a6dc", "#bfe399"],
legend: { legend: {
show: true, show: true,
@ -531,6 +518,7 @@
})).render(); })).render();
}); });
// @formatter:on // @formatter:on
});
</script> </script>

View File

@ -115,6 +115,9 @@ class ClearCacheInstatnceHandler(tornado.web.RequestHandler):
om.clear_cache() om.clear_cache()
root = os.path.dirname(__file__)
def make_app(): def make_app():
return tornado.web.Application([ return tornado.web.Application([
(r"/", MainHandler), (r"/", MainHandler),
@ -126,6 +129,8 @@ def make_app():
(r"/stop", StopInstatnceHandler), (r"/stop", StopInstatnceHandler),
(r"/remove", RemoveInstatnceHandler), (r"/remove", RemoveInstatnceHandler),
(r"/clear_cache", ClearCacheInstatnceHandler), (r"/clear_cache", ClearCacheInstatnceHandler),
(r"/dashboard/(.*)", tornado.web.StaticFileHandler,
{"path": os.path.join(root, "tabler"), "default_filename": "index.html"})
]) ])