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({
@ -136,9 +136,9 @@ class OManager:
if self.instances: if self.instances:
xs = [j.isoformat() for j in ping_tas.get_ts()] xs = [j.isoformat() for j in ping_tas.get_ts()]
return { return {
"time": xs, "time": xs,
"stat": stat "stat": stat
} }
return {} return {}
def generate_lb_cfg(self, load_balance_mode): def generate_lb_cfg(self, load_balance_mode):

View File

@ -21,11 +21,24 @@ 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 [datetime.utcfromtimestamp(self.start_timestamp+(i+1)*self.bin_time) for i in range(self.n_bins)] 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)]
if __name__ == "__main__": if __name__ == "__main__":

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,107 +430,95 @@
<script src="./dist/js/tabler.min.js"></script> <script src="./dist/js/tabler.min.js"></script>
<script> <script>
// @formatter:off $.get("/stat", function (data) {
document.addEventListener("DOMContentLoaded", function () { // @formatter:off
window.ApexCharts && (new ApexCharts(document.getElementById('chart-mentions'), { document.addEventListener("DOMContentLoaded", function () {
chart: { window.ApexCharts && (new ApexCharts(document.getElementById('chart-mentions'), {
type: "line", chart: {
fontFamily: 'inherit', type: "line",
height: 240, fontFamily: 'inherit',
parentHeightOffset: 0, height: 240,
toolbar: { parentHeightOffset: 0,
show: false, toolbar: {
show: false,
},
animations: {
enabled: false
},
stacked: true,
}, },
animations: { plotOptions: {
enabled: false bar: {
}, columnWidth: '50%',
stacked: true,
},
plotOptions: {
bar: {
columnWidth: '50%',
}
},
dataLabels: {
enabled: false,
},
fill: {
opacity: 0.6,
},
series: [{
name: "Web",
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,
26, 50, 26, 41, 22, 46, 47, 81, 46, 6
]
}, {
name: "Social",
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,
15, 20, 47, 18, 15, 11, 10, 0
]
}, {
name: "Other",
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,
3,
2, 3, 4, 9, 7, 1, 6
]
}],
grid: {
padding: {
top: -20,
right: 0,
left: -4,
bottom: -4
},
strokeDashArray: 4,
xaxis: {
lines: {
show: true
} }
}, },
}, dataLabels: {
xaxis: { enabled: false,
labels: {
padding: 0
}, },
tooltip: { fill: {
enabled: false opacity: 0.6,
}, },
axisBorder: { series: [{
show: false, name: "Down rate",
data: data.stat[0].io_mean
}, {
name: "Up rate",
data: data.stat[0].io_mean
}, {
name: "d rate",
data: data.stat[0].io_mean
}],
grid: {
padding: {
top: -20,
right: 0,
left: -4,
bottom: -4
},
strokeDashArray: 4,
xaxis: {
lines: {
show: true
}
},
}, },
type: 'datetime', xaxis: {
}, labels: {
yaxis: { padding: 0
labels: { },
padding: 4 tooltip: {
enabled: false
},
axisBorder: {
show: false,
},
type: 'datetime',
}, },
}, yaxis: {
labels: [ labels: {
'2020-06-20', '2020-06-21', '2020-06-22', '2020-06-23', '2020-06-24', '2020-06-25', '2020-06-26', padding: 4
'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"],
legend: {
show: true,
position: 'bottom',
height: 32,
offsetY: 8,
markers: {
width: 8,
height: 8,
radius: 100,
}, },
itemMargin: { labels: data.time,
horizontal: 8, colors: ["#206bc4", "#79a6dc", "#bfe399"],
legend: {
show: true,
position: 'bottom',
height: 32,
offsetY: 8,
markers: {
width: 8,
height: 8,
radius: 100,
},
itemMargin: {
horizontal: 8,
},
}, },
}, })).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"})
]) ])