Skip to content

Commit 1c15efe

Browse files
committed
增加下载文件报错的原因,修复统计问题,如果使用之前的版本,需要删除data文件夹,增加系统使用情况
1 parent 5f19914 commit 1c15efe

File tree

6 files changed

+46
-18
lines changed

6 files changed

+46
-18
lines changed

bmclapi_dashboard/static/js/index.min.js

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,6 +2079,12 @@ $I18N.addLangs("zh_cn", {
20792079
"dashboard.pro.download": "下载数",
20802080
"dashboard.pro.distincts": "独立访问",
20812081
"dashboard.pro.download_size": "下载量",
2082+
"dashboard.history.cpu": "1 分钟 CPU 负载",
2083+
"dashboard.history.memory": "1 分钟 内存使用情况",
2084+
"dashboard.history.connections": "1 分钟 连接数",
2085+
"dashboard.cpu": "CPU 负载",
2086+
"dashboard.memory": "内存使用",
2087+
"dashboard.connections": "连接数",
20822088
"menu.dashboard": "数据统计",
20832089
"menu.master": "主控面板",
20842090
"menu.master.rank": "排行榜",
@@ -2963,15 +2969,15 @@ app.$Menu.add("dashboard", new class {
29632969
app.createFlex(true).class("panel").minWidth(640).child(3).append(
29642970
app.createElement("div").append(
29652971
app.createElement("p").class("title").setI18N("dashboard.pro.download"),
2966-
app.createElement("p").class("value").setText("dashboard.storages"),
2972+
app.createElement("p").class("value"),
29672973
),
29682974
app.createElement("div").append(
29692975
app.createElement("p").class("title").setI18N("dashboard.pro.download_size"),
2970-
app.createElement("p").class("value").setText("dashboard.storages"),
2976+
app.createElement("p").class("value"),
29712977
),
29722978
app.createElement("div").append(
29732979
app.createElement("p").class("title").setI18N("dashboard.pro.distincts"),
2974-
app.createElement("p").class("value").setText("dashboard.storages"),
2980+
app.createElement("p").class("value"),
29752981
)
29762982
),
29772983
app.createFlex(true).minWidth(1280).childWidths(70, 30).append(
@@ -3031,15 +3037,24 @@ app.$Menu.add("dashboard", new class {
30313037
),
30323038
app.createFlex(true).minWidth(1280).childWidths(1 / 3 * 100.0, 1 / 3 * 100.0, 1 / 3 * 100.0).append(
30333039
app.createElement("div").class("panel").append(
3034-
app.createElement("p").class("title").setText("dashboard.history.cpu"),
3040+
app.createElement("div").class("title", "flex-space-between").append(
3041+
app.createElement("p").class("title-color").setI18N("dashboard.history.cpu"),
3042+
app.createElement("p").class("title-color").setI18N("dashboard.peer")
3043+
),
30353044
this._e_cpu
30363045
),
30373046
app.createElement("div").class("panel").append(
3038-
app.createElement("p").class("title").setText("dashboard.history.memory"),
3047+
app.createElement("div").class("title", "flex-space-between").append(
3048+
app.createElement("p").class("title-color").setI18N("dashboard.history.memory"),
3049+
app.createElement("p").class("title-color").setI18N("dashboard.peer")
3050+
),
30393051
this._e_memory
30403052
),
30413053
app.createElement("div").class("panel").append(
3042-
app.createElement("p").class("title").setText("dashboard.history.connection"),
3054+
app.createElement("div").class("title", "flex-space-between").append(
3055+
app.createElement("p").class("title-color").setI18N("dashboard.history.connections"),
3056+
app.createElement("p").class("title-color").setI18N("dashboard.peer")
3057+
),
30433058
this._e_connection
30443059
)
30453060
).addResize(() => {
@@ -3417,9 +3432,10 @@ app.$Menu.add("dashboard", new class {
34173432
top: 15,
34183433
bottom: 10,
34193434
right: 0,
3435+
left: 10,
34203436
show: false,
34213437
z: 0,
3422-
containLabel: false,
3438+
containLabel: true,
34233439
backgroundColor: "rgba(0,0,0,0)",
34243440
borderWidth: 1,
34253441
borderColor: "#ccc"
@@ -3460,12 +3476,12 @@ app.$Menu.add("dashboard", new class {
34603476
this.drawGEO()
34613477
})
34623478
}, 0, 360000)
3463-
/*this.detailSystemTimer = app.runTaskRepeat(() => {
3479+
this.detailSystemTimer = app.runTaskRepeat(() => {
34643480
$MainSocket.send("system_details").then((data) => {
34653481
this.detail_system = data
34663482
this.drawDetailSystem()
34673483
})
3468-
}, 0, 1000)*/
3484+
}, 0, 5000)
34693485
}
34703486
clearPro() {
34713487
this.globalTimer?.block()
@@ -3896,6 +3912,10 @@ app.$Menu.add("dashboard", new class {
38963912
}
38973913
]
38983914
})
3915+
console.log(this.pro[2].getChildren()[0].getChildren()[0].getChildren()[1])
3916+
this.pro[3].getChildren()[0].getChildren()[0].getChildren()[1].t18n({ peer: Math.max(...Object.values(this.detail_system.cpu), 0).toFixed(2) + "%" })
3917+
this.pro[3].getChildren()[1].getChildren()[0].getChildren()[1].t18n({ peer: this._format_bytes(Math.max(...Object.values(this.detail_system.memory), 0))})
3918+
this.pro[3].getChildren()[2].getChildren()[0].getChildren()[1].t18n({ peer: Math.max(...Object.values(this.detail_system.connections), 0)})
38993919
}
39003920
drawGlobals() {
39013921
var visits = (this.data_day_option <= 1 ? fillDateTimes(this.pro_stats.distinct_ip, this.data_day_option == 1 ? 7 : 1) : fillDates(this.pro_stats.distinct_ip))

core/cluster.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,15 @@ async def put(size, file: BMCLAPIFile):
219219
self.failed_files[file] += 1
220220
pbar.update(-size)
221221
raise PutQueueIgnoreError # raised ignore error, continue to next code.
222-
async def error(*responses: aiohttp.ClientResponse):
222+
async def error(*responses: aiohttp.ClientResponse, file: Optional[BMCLAPIFile] = None, hash: Optional[str] = None):
223223
msg = []
224224
history = list((ResponseRedirects(resp.status, str(resp.real_url)) for resp in responses))
225225
source = "主控" if len(history) == 1 else "节点"
226226
for history in history:
227227
msg.append(f"> {history.status} | {history.url}")
228228
history = '\n'.join(msg)
229229
logger.terror("cluster.error.download.failed", hash=file.hash, size=unit.format_bytes(file.size),
230-
source=source, host=responses[-1].host, status=responses[-1].status, history=history)
230+
source=source, host=responses[-1].host, status=responses[-1].status, history=history, reason=locale.t("cluster.error.download.failed.hash") if file is not None and hash is not None else locale.t("cluster.error.download.failed.default"))
231231
while not self.queues.empty() and storages.available:
232232
try:
233233
file = await self.queues.get()
@@ -249,7 +249,10 @@ async def error(*responses: aiohttp.ClientResponse):
249249
content: io.BytesIO = io.BytesIO()
250250
resp = None
251251
try:
252-
async with lock:
252+
if DOWNLOAD_CONFIGURATION:
253+
async with lock:
254+
resp = await session.get(file.path)
255+
else:
253256
resp = await session.get(file.path)
254257
while data := await resp.content.read(IO_BUFFER):
255258
if not data:
@@ -272,7 +275,7 @@ async def error(*responses: aiohttp.ClientResponse):
272275
await error(*resp.history, resp)
273276
await put(size, file)
274277
if file.hash != hash.hexdigest():
275-
await error(*resp.history, resp)
278+
await error(*resp.history, resp, file, hash.hexdigest())
276279
await put(size, file)
277280
r = await self._mount_file(file, content)
278281
if r[0] == -1:
@@ -1322,9 +1325,9 @@ async def message(self, channel, data: list[Any], callback=None):
13221325

13231326
async def init():
13241327
if CLUSTER_ID == "":
1325-
raise ClusterIdNotSet
1328+
raise ClusterIdNotSet("当前配置文件 Cluster ID 没有配置好")
13261329
if CLUSTER_SECERT == "":
1327-
raise ClusterSecretNotSet
1330+
raise ClusterSecretNotSet("当前配置文件 Cluster Secret 没有配置好")
13281331
global cluster
13291332
cluster = Cluster()
13301333
for storage in STORAGES:

core/const.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
DOWNLOAD_ACCESS_LOG: bool = True
5858
DOWNLOAD_RETRY_DELAY: int = 60
5959
DOWNLOAD_FILE: bool = False
60+
DOWNLOAD_CONFIGURATION: bool = True
6061
RESPONSE_DATE = "%a, %d %b %Y %H:%M:%S GMT"
6162
RESPONSE_COMPRESSION_IGNORE_SIZE_THRESHOLD: int = 16777216
6263
SKIP_FILE_CHECK: bool = False

core/statistics.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from tqdm import tqdm
1212

13-
from core import scheduler, utils
13+
from core import logger, scheduler, unit, utils
1414
from core import location
1515
from core.api import File, Storage
1616
from core.location import IPInfo
@@ -281,10 +281,12 @@ async def task():
281281
def exit():
282282
global running
283283
running = 0
284+
logger.info(f"正在保存 [{unit.format_number(queues.qsize())}] 统计中")
284285
while not queues.empty():
285286
cmd, params = queues.get()
286287
db.execute(cmd, params)
287288
db.commit()
289+
logger.success(f"成功保存统计")
288290
lock.release()
289291

290292
def get_utc_offset():

core/system.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def get_loads_detail():
4848
return {
4949
"cpu": {format_time(t + startup): v for t, v in get_filled(cpus.copy()).items()},
5050
"memory": {format_time(t + startup): v for t, v in get_filled(memories.copy()).items()},
51-
"connections": {format_time(t + startup): len(v) for t, v in get_filled_list(connections).items()},
51+
"connections": {format_time(t + startup): len(v) for t, v in get_filled_list(connections.copy()).items()},
5252
}
5353

5454

i18n/zh_cn.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
"cluster.tqdm.desc.download": "下载文件中",
2323
"cluster.debug.download_temp.downloading": "正在下载文件:$hash。",
2424
"cluster.debug.download_temp.downloaded": "成功下载文件:$hash。",
25-
"cluster.error.download.failed": "无法下载文件 $hash($size)($source $host $status),历史地址:\n$history",
25+
"cluster.error.download.failed.reason": "原文件校验码与下载文件校验码不符",
26+
"cluster.error.download.failed.default": "未知",
27+
"cluster.error.download.failed": "无法下载文件 $hash($size) 原因 [$reason] [$source $host $status] 历史地址:\n$history",
2628
"cluster.error.download.failed_to_upload": "在尝试上传文件时发生错误。",
2729
"cluster.info.download.finished": "成功下载所有文件。",
2830
"cluster.info.check_files.check_type": "当前文件检查模式:$type。",

0 commit comments

Comments
 (0)