mirror of
https://github.com/wikihost-opensource/als.git
synced 2025-12-24 12:57:59 +08:00
fix #1
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
backend/app/webspaces/speedtest-static/*
|
||||
@@ -1,30 +1,32 @@
|
||||
<?php
|
||||
Swoole\Timer::tick(1000, function () {
|
||||
preg_match_all(
|
||||
'/^\s*(?\'name\'[A-Za-z0-9]+):\s+(?\'recv\'\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(?\'send\'\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/m',
|
||||
file_get_contents('/proc/net/dev'),
|
||||
$matches,
|
||||
PREG_SET_ORDER,
|
||||
0
|
||||
);
|
||||
$interfaces = [];
|
||||
foreach ($matches as $match) {
|
||||
if (in_array($match['name'], ['lo', 'ip6tnl0', 'tunl0', 'docker0'])) continue;
|
||||
if (strpos($match['name'], 'veth') !== false) continue;
|
||||
$interfaces[$match['name']] = [
|
||||
'recv' => $match['recv'],
|
||||
'send' => $match['send'],
|
||||
];
|
||||
}
|
||||
|
||||
foreach (Client\Websocket::$clients as $client) {
|
||||
foreach ($interfaces as $interface => $data) {
|
||||
$client->send(implode("|", [
|
||||
100,
|
||||
$interface,
|
||||
$data['recv'],
|
||||
$data['send']
|
||||
]));
|
||||
if (env('DISPLAY_TRAFFIC', true)) {
|
||||
Swoole\Timer::tick(1000, function () {
|
||||
preg_match_all(
|
||||
'/^\s*(?\'name\'[A-Za-z0-9]+):\s+(?\'recv\'\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(?\'send\'\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/m',
|
||||
file_get_contents('/proc/net/dev'),
|
||||
$matches,
|
||||
PREG_SET_ORDER,
|
||||
0
|
||||
);
|
||||
$interfaces = [];
|
||||
foreach ($matches as $match) {
|
||||
if (in_array($match['name'], ['lo', 'ip6tnl0', 'tunl0', 'docker0'])) continue;
|
||||
if (strpos($match['name'], 'veth') !== false) continue;
|
||||
$interfaces[$match['name']] = [
|
||||
'recv' => $match['recv'],
|
||||
'send' => $match['send'],
|
||||
];
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
foreach (Client\Websocket::$clients as $client) {
|
||||
foreach ($interfaces as $interface => $data) {
|
||||
$client->send(implode("|", [
|
||||
100,
|
||||
$interface,
|
||||
$data['recv'],
|
||||
$data['send']
|
||||
]));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3,7 +3,11 @@ if (!function_exists('env')) {
|
||||
function env($key, $default = false)
|
||||
{
|
||||
$result = getenv($key);
|
||||
if ($result !== false) return $result;
|
||||
if ($result !== false) {
|
||||
if ($result === "true") return true;
|
||||
if ($result === "false") return false;
|
||||
return $result;
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ export default defineComponent({
|
||||
},
|
||||
methods: {
|
||||
initWebsocket() {
|
||||
if (this.isLoaded) return;
|
||||
this.ws = new WebSocket(location.protocol.replace('http', 'ws') + '//' + location.host + '/ws')
|
||||
this.ws.onopen = () => {
|
||||
this.isLoaded = true
|
||||
|
||||
Reference in New Issue
Block a user