支持显示网速
This commit is contained in:
parent
a6662450de
commit
a6fa88b981
60
Common.py
60
Common.py
@ -1,6 +1,6 @@
|
|||||||
import queue
|
import queue
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
import psutil
|
||||||
from api import XiGuaLiveApi
|
from api import XiGuaLiveApi
|
||||||
import json
|
import json
|
||||||
|
|
||||||
@ -9,6 +9,62 @@ config = json.load(_config_fp)
|
|||||||
_config_fp.close()
|
_config_fp.close()
|
||||||
|
|
||||||
|
|
||||||
|
network = {
|
||||||
|
"currentTime": datetime.now(),
|
||||||
|
"out":{
|
||||||
|
"currentByte":psutil.net_io_counters().bytes_sent,
|
||||||
|
},
|
||||||
|
"in":{
|
||||||
|
"currentByte": psutil.net_io_counters().bytes_recv,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def updateNetwork():
|
||||||
|
global network
|
||||||
|
network = {
|
||||||
|
"currentTime": datetime.now(),
|
||||||
|
"out":{
|
||||||
|
"currentByte":psutil.net_io_counters().bytes_sent,
|
||||||
|
},
|
||||||
|
"in":{
|
||||||
|
"currentByte": psutil.net_io_counters().bytes_recv,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def getTimeDelta(a, b):
|
||||||
|
sec = (a - b).seconds
|
||||||
|
ms = (a - b).microseconds
|
||||||
|
return sec+(ms/100000.0)
|
||||||
|
|
||||||
|
|
||||||
|
def getCurrentStatus():
|
||||||
|
_disk = psutil.disk_usage("/")
|
||||||
|
_mem = psutil.virtual_memory()
|
||||||
|
_net = psutil.net_io_counters()
|
||||||
|
if 60 > (datetime.now() - network["currentTime"]).seconds > 0:
|
||||||
|
_outSpeed = (_net.bytes_sent - network["out"]["currentByte"])/getTimeDelta(datetime.now(),network["currentTime"])
|
||||||
|
else:
|
||||||
|
_outSpeed = 0
|
||||||
|
if 60 > (datetime.now() - network["currentTime"]).seconds > 0:
|
||||||
|
_inSpeed = (_net.bytes_recv - network["in"]["currentByte"])/getTimeDelta(datetime.now(),network["currentTime"])
|
||||||
|
else:
|
||||||
|
_inSpeed = 0
|
||||||
|
updateNetwork()
|
||||||
|
return {
|
||||||
|
"memTotal": parseSize(_mem.total),
|
||||||
|
"memUsed": parseSize(_mem.used),
|
||||||
|
"memUsage": _mem.percent,
|
||||||
|
"diskTotal": parseSize(_disk.total),
|
||||||
|
"diskUsed": parseSize(_disk.used),
|
||||||
|
"diskUsage": _disk.percent,
|
||||||
|
"cpu": psutil.cpu_percent(),
|
||||||
|
"outSpeed": parseSize(_outSpeed),
|
||||||
|
"inSpeed": parseSize(_inSpeed),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def reloadConfig():
|
def reloadConfig():
|
||||||
global config, _config_fp
|
global config, _config_fp
|
||||||
_config_fp = open("config.json", "r", encoding="utf8")
|
_config_fp = open("config.json", "r", encoding="utf8")
|
||||||
@ -46,7 +102,7 @@ def parseSize(size):
|
|||||||
else:
|
else:
|
||||||
return "{:.2f}MB".format(M)
|
return "{:.2f}MB".format(M)
|
||||||
else:
|
else:
|
||||||
return "{:.2f}MB".format(K)
|
return "{:.2f}KB".format(K)
|
||||||
|
|
||||||
|
|
||||||
def appendUploadStatus(obj):
|
def appendUploadStatus(obj):
|
||||||
|
24
WebMain.py
24
WebMain.py
@ -6,7 +6,6 @@ from flask import Flask, jsonify, request, redirect, render_template, Response
|
|||||||
import Common
|
import Common
|
||||||
import threading
|
import threading
|
||||||
from liveDownloader import run as RUN
|
from liveDownloader import run as RUN
|
||||||
import psutil
|
|
||||||
|
|
||||||
app = Flask("liveStatus")
|
app = Flask("liveStatus")
|
||||||
app.config['JSON_AS_ASCII'] = False
|
app.config['JSON_AS_ASCII'] = False
|
||||||
@ -17,7 +16,8 @@ CORS(app, supports_credentials=True)
|
|||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
return redirect("/static/index.html")
|
return render_template("index.html")
|
||||||
|
|
||||||
|
|
||||||
@app.route("/config", methods=["GET"])
|
@app.route("/config", methods=["GET"])
|
||||||
def readConfig():
|
def readConfig():
|
||||||
@ -90,7 +90,6 @@ def finishUpload():
|
|||||||
|
|
||||||
@app.route("/stats", methods=["GET"])
|
@app.route("/stats", methods=["GET"])
|
||||||
def getAllStats():
|
def getAllStats():
|
||||||
_disk = psutil.disk_usage("/")
|
|
||||||
return jsonify({"message":"ok","code":200,"status":0,"data":{
|
return jsonify({"message":"ok","code":200,"status":0,"data":{
|
||||||
"download":Common.downloadStatus,
|
"download":Common.downloadStatus,
|
||||||
"encode": Common.encodeStatus,
|
"encode": Common.encodeStatus,
|
||||||
@ -115,18 +114,8 @@ def getAllStats():
|
|||||||
|
|
||||||
@app.route("/stats/device", methods=["GET"])
|
@app.route("/stats/device", methods=["GET"])
|
||||||
def getDeviceStatus():
|
def getDeviceStatus():
|
||||||
_disk = psutil.disk_usage("/")
|
|
||||||
_mem = psutil.virtual_memory()
|
|
||||||
return jsonify({"message":"ok","code":200,"status":0,"data":{
|
return jsonify({"message":"ok","code":200,"status":0,"data":{
|
||||||
"status": {
|
"status": Common.getCurrentStatus(),
|
||||||
"memTotal": Common.parseSize(_mem.total),
|
|
||||||
"memUsed": Common.parseSize(_mem.used),
|
|
||||||
"memUsage": _mem.percent,
|
|
||||||
"diskTotal": Common.parseSize(_disk.total),
|
|
||||||
"diskUsed": Common.parseSize(_disk.used),
|
|
||||||
"diskUsage": _disk.percent,
|
|
||||||
"cpu": psutil.cpu_percent(),
|
|
||||||
},
|
|
||||||
}})
|
}})
|
||||||
|
|
||||||
|
|
||||||
@ -149,6 +138,7 @@ def getConfigStats():
|
|||||||
"forceNotBroadcasting": Common.forceNotBroadcasting,
|
"forceNotBroadcasting": Common.forceNotBroadcasting,
|
||||||
"forceNotDownload": Common.forceNotDownload,
|
"forceNotDownload": Common.forceNotDownload,
|
||||||
"forceNotUpload": Common.forceNotUpload,
|
"forceNotUpload": Common.forceNotUpload,
|
||||||
|
"forceNotEncode": Common.forceNotEncode,
|
||||||
}
|
}
|
||||||
}})
|
}})
|
||||||
|
|
||||||
@ -212,6 +202,6 @@ def SubThread():
|
|||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
|
|
||||||
p = threading.Thread(target = SubThread)
|
# p = threading.Thread(target=SubThread)
|
||||||
p.setDaemon(True)
|
# p.setDaemon(True)
|
||||||
p.start()
|
# p.start()
|
||||||
|
24
static/device.js
Normal file
24
static/device.js
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
function deviceUpdate(){
|
||||||
|
$.ajax(
|
||||||
|
"/stats/device",
|
||||||
|
{
|
||||||
|
success: function (res){
|
||||||
|
$("#memTotal").text(res.data.status.memTotal)
|
||||||
|
$("#memUsed").text(res.data.status.memUsed)
|
||||||
|
$("#memUsage").text(res.data.status.memUsage)
|
||||||
|
$("#diskTotal").text(res.data.status.diskTotal)
|
||||||
|
$("#diskUsed").text(res.data.status.diskUsed)
|
||||||
|
$("#diskUsage").text(res.data.status.diskUsage)
|
||||||
|
$("#cpu").text(res.data.status.cpu)
|
||||||
|
$("#memUsageP").val(res.data.status.memUsage)
|
||||||
|
$("#diskUsageP").val(res.data.status.diskUsage)
|
||||||
|
$("#cpuP").val(res.data.status.cpu)
|
||||||
|
$("#inSpeed").text(res.data.status.inSpeed)
|
||||||
|
$("#outSpeed").text(res.data.status.outSpeed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
deviceUpdate()
|
||||||
|
setInterval(deviceUpdate,2000)
|
@ -43,26 +43,6 @@ function taskUpdate(){
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
function deviceUpdate(){
|
|
||||||
$.ajax(
|
|
||||||
"/stats/device",
|
|
||||||
{
|
|
||||||
success: function (res){
|
|
||||||
$("#memTotal").text(res.data.status.memTotal)
|
|
||||||
$("#memUsed").text(res.data.status.memUsed)
|
|
||||||
$("#memUsage").text(res.data.status.memUsage)
|
|
||||||
$("#diskTotal").text(res.data.status.diskTotal)
|
|
||||||
$("#diskUsed").text(res.data.status.diskUsed)
|
|
||||||
$("#diskUsage").text(res.data.status.diskUsage)
|
|
||||||
$("#cpu").text(res.data.status.cpu)
|
|
||||||
$("#memUsageP").val(res.data.status.memUsage)
|
|
||||||
$("#diskUsageP").val(res.data.status.diskUsage)
|
|
||||||
$("#cpuP").val(res.data.status.cpu)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
taskUpdate()
|
taskUpdate()
|
||||||
deviceUpdate()
|
|
||||||
setInterval(taskUpdate,10000)
|
setInterval(taskUpdate,10000)
|
||||||
setInterval(deviceUpdate,5000)
|
|
24
templates/device.html
Normal file
24
templates/device.html
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<h1>机器状态</h1>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td>CPU使用率</td>
|
||||||
|
<td><progress id="cpuP" max="100" value="0"></progress></td>
|
||||||
|
<td><span id="cpu"></span>%</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>内存使用率</td>
|
||||||
|
<td><progress id="memUsageP" max="100" value="0"></progress></td>
|
||||||
|
<td><span id="memUsed"></span>/<span id="memTotal"></span>(<span id="memUsage"></span>%)</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>磁盘使用率</td>
|
||||||
|
<td><progress id="diskUsageP" max="100" value="0"></progress></td>
|
||||||
|
<td><span id="diskUsed"></span>/<span id="diskTotal"></span>(<span id="diskUsage"></span>%)</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>网络速率</td>
|
||||||
|
<td>↓ <span id="inSpeed"></span>/s</td>
|
||||||
|
<td>↑ <span id="outSpeed"></span>/s</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<script src="/static/device.js"></script>
|
@ -1,25 +1,24 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="zh_CN">
|
<html lang="zh_CN">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
|
||||||
<title>文件</title>
|
<title>文件</title>
|
||||||
<style>
|
{% include 'head.html' %}
|
||||||
td{
|
|
||||||
border: solid 1px lightgray;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>所有录像文件</h1>
|
<div>
|
||||||
<table>
|
<h1>所有录像文件</h1>
|
||||||
<tr>
|
<table>
|
||||||
<td>文件名</td><td>文件大小</td><td>链接</td>
|
<tr>
|
||||||
</tr>
|
<td>文件名</td><td>文件大小</td><td>链接</td>
|
||||||
{%for i in files %}
|
</tr>
|
||||||
<tr>
|
{%for i in files %}
|
||||||
<td>{{i.name}}</td><td>{{i.size}}</td><td><a href="/files/download/{{i.name}}">下载文件</a></td>
|
<tr>
|
||||||
</tr>
|
<td>{{i.name}}</td><td>{{i.size}}</td><td><a href="/files/download/{{i.name}}">下载文件</a></td>
|
||||||
{% endfor %}
|
</tr>
|
||||||
</table>
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
<hr/>
|
||||||
|
{% include 'device.html' %}
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
7
templates/head.html
Normal file
7
templates/head.html
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<meta charset="UTF-8">
|
||||||
|
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
|
||||||
|
<style>
|
||||||
|
td{
|
||||||
|
border: solid 1px lightgray;
|
||||||
|
}
|
||||||
|
</style>
|
@ -1,14 +1,8 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="zh_CN">
|
<html lang="zh_CN">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
|
||||||
<title>录播</title>
|
<title>录播</title>
|
||||||
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
|
{% include 'head.html' %}
|
||||||
<style type="text/css">
|
|
||||||
td {
|
|
||||||
border: solid 1px lightgrey;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div>
|
<div>
|
||||||
@ -76,25 +70,8 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<hr/>
|
<hr/>
|
||||||
<h1>机器状态</h1>
|
{% include 'device.html' %}
|
||||||
<table>
|
|
||||||
<tr>
|
|
||||||
<td>CPU使用率</td>
|
|
||||||
<td><progress id="cpuP" max="100" value="0"></progress></td>
|
|
||||||
<td><span id="cpu"></span>%</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>内存使用率</td>
|
|
||||||
<td><progress id="memUsageP" max="100" value="0"></progress></td>
|
|
||||||
<td><span id="memUsed"></span>/<span id="memTotal"></span>(<span id="memUsage"></span>%)</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>磁盘使用率</td>
|
|
||||||
<td><progress id="diskUsageP" max="100" value="0"></progress></td>
|
|
||||||
<td><span id="diskUsed"></span>/<span id="diskTotal"></span>(<span id="diskUsage"></span>%)</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
</div>
|
||||||
|
<script src="../static/index.js"></script>
|
||||||
</body>
|
</body>
|
||||||
<script src="index.js"></script>
|
|
||||||
</html>
|
</html>
|
Reference in New Issue
Block a user