Skip to content

Commit 46d1ea9

Browse files
committed
删除无用的统计数据,需要删除data文件夹
1 parent f54aa29 commit 46d1ea9

File tree

4 files changed

+167
-12
lines changed

4 files changed

+167
-12
lines changed

bmclapi_dashboard/static/js/index.min.js

Lines changed: 138 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2787,8 +2787,8 @@ app.$Menu.add("dashboard", new class {
27872787
this._be_qps = app.createEcharts().style("min-height: 162px;")
27882788
this._pe_qps = app.createEcharts().style("min-height: 162px;")
27892789
this._e_geo = app.createEcharts().style("min-height: 416px;")
2790-
this._e_cpu = app.createEcharts().style("min-height: 162px;")
2791-
this._e_memory = app.createEcharts().style("min-height: 162px;")
2790+
this._e_cpu = app.createEcharts().style("min-height: 162px;").setFormatter((n) => n + "%")
2791+
this._e_memory = app.createEcharts().style("min-height: 162px;").setFormatter((n) => this._format_bytes(n))
27922792
this._e_connection = app.createEcharts().style("min-height: 162px;")
27932793
this._e_ua = app.createEcharts().setType(EchartType.LABEL).style("min-height: 140px")
27942794
this._e_status = app.createEcharts().setType(EchartType.LABEL).style("min-height: 140px")
@@ -3049,6 +3049,9 @@ app.$Menu.add("dashboard", new class {
30493049
this._e_status.resize()
30503050
this._e_geo.resize()
30513051
this.pgeorank.update(false)
3052+
this._e_cpu.resize()
3053+
this._e_memory.resize()
3054+
this._e_connection.resize()
30523055
})
30533056
];
30543057
this.initGlobals()
@@ -3278,7 +3281,7 @@ app.$Menu.add("dashboard", new class {
32783281
global: false,
32793282
colorStops: [{ offset: 0, color: app.getThemeVar("echarts-main-line-color") }, { offset: 1, color: app.getThemeVar("echarts-dark-color") }]
32803283
},
3281-
type: " solid"
3284+
type: "solid"
32823285
},
32833286
itemStyle: { borderRadius: [2, 2, 0, 0] },
32843287
z: 3,
@@ -3382,6 +3385,72 @@ app.$Menu.add("dashboard", new class {
33823385
data: []
33833386
}]
33843387
})
3388+
for (let val of [
3389+
["cpu", this._e_cpu, ],
3390+
["memory", this._e_memory],
3391+
["connection", this._e_connection]
3392+
]) {
3393+
val[1].setOption({
3394+
color: app.getThemeVar("main-color"),
3395+
yAxis: [
3396+
{
3397+
type: "value",
3398+
show: true,
3399+
max: val[0] == "cpu" ? 100 : 1
3400+
}
3401+
],
3402+
tooltip: {
3403+
trigger: "axis",
3404+
},
3405+
xAxis: [
3406+
{
3407+
type: "category",
3408+
show: false,
3409+
}
3410+
],
3411+
stateAnimation: {
3412+
duration: 300,
3413+
easing: "cubicOut"
3414+
},
3415+
grid: [
3416+
{
3417+
top: 15,
3418+
bottom: 10,
3419+
right: 0,
3420+
show: false,
3421+
z: 0,
3422+
containLabel: false,
3423+
backgroundColor: "rgba(0,0,0,0)",
3424+
borderWidth: 1,
3425+
borderColor: "#ccc"
3426+
}
3427+
],
3428+
series: [
3429+
{
3430+
name: $I18N.t("dashboard.distincts"),
3431+
type: "line",
3432+
symbol: "none",
3433+
data: [],
3434+
smooth: true,
3435+
lineStyle: {
3436+
width: 3,
3437+
color: {
3438+
type: "linear",
3439+
x: 0,
3440+
y: 0,
3441+
x2: 0,
3442+
y2: 1,
3443+
global: false,
3444+
colorStops: [{ offset: 0, color: app.getThemeVar("echarts-main-line-color") }, { offset: 1, color: app.getThemeVar("echarts-dark-color") }]
3445+
},
3446+
type: "solid"
3447+
},
3448+
itemStyle: { borderRadius: [2, 2, 0, 0] },
3449+
z: 3,
3450+
}
3451+
]
3452+
})
3453+
}
33853454
this.setRank_UA();
33863455
this.setRank_Status();
33873456
this.globalTimer = app.runTaskRepeat(() => {
@@ -3391,9 +3460,16 @@ app.$Menu.add("dashboard", new class {
33913460
this.drawGEO()
33923461
})
33933462
}, 0, 360000)
3463+
/*this.detailSystemTimer = app.runTaskRepeat(() => {
3464+
$MainSocket.send("system_details").then((data) => {
3465+
this.detail_system = data
3466+
this.drawDetailSystem()
3467+
})
3468+
}, 0, 1000)*/
33943469
}
33953470
clearPro() {
33963471
this.globalTimer?.block()
3472+
this.detailSystemTimer?.block()
33973473
this._e_visits.clear()
33983474
this._e_ua.clear()
33993475
this.pgeorank.setData()
@@ -3761,7 +3837,65 @@ app.$Menu.add("dashboard", new class {
37613837
this.basic[0].getChildren()[0].getChildren()[1].getChildren()[0].getChildren()[3].getChildren()[1].setText(this.system.cpu.toFixed(2) + "%")
37623838
}
37633839
drawDetailSystem() {
3764-
3840+
this._e_cpu.setOption({
3841+
color: app.getThemeVar("main-color"),
3842+
yAxis: {
3843+
max: Math.max(...Object.values(this.detail_system.cpu), 100)
3844+
},
3845+
xAxis: {
3846+
data: Object.keys(this.detail_system.cpu)
3847+
},
3848+
series: [
3849+
{
3850+
name: $I18N.t("dashboard.cpu"),
3851+
data: Object.values(this.detail_system.cpu),
3852+
type: 'line',
3853+
smooth: true,
3854+
}
3855+
]
3856+
})
3857+
let memories = Object.values(this.detail_system.memory).filter(v => v != 0)
3858+
let max = memories.reduce((sum, i) => sum + i, 0)
3859+
let avg = max / memories.length
3860+
this._e_memory.setOption({
3861+
color: app.getThemeVar("main-color"),
3862+
yAxis: {
3863+
max: Math.max((avg >= max / 2 ? max : avg * 2) / 1024, 1) * 1024,
3864+
axisLabel: {
3865+
formatter: (value) => {
3866+
return this._format_bytes(value)
3867+
}
3868+
}
3869+
},
3870+
xAxis: {
3871+
data: Object.keys(this.detail_system.memory)
3872+
},
3873+
series: [
3874+
{
3875+
name: $I18N.t("dashboard.memory"),
3876+
data: Object.values(this.detail_system.memory),
3877+
type: 'line',
3878+
smooth: true,
3879+
}
3880+
]
3881+
})
3882+
this._e_connection.setOption({
3883+
color: app.getThemeVar("main-color"),
3884+
yAxis: {
3885+
max: Math.max(...Object.values(this.detail_system.connections).map(v => parseInt(v / 100)), 1) * 100
3886+
},
3887+
xAxis: {
3888+
data: Object.keys(this.detail_system.connections)
3889+
},
3890+
series: [
3891+
{
3892+
name: $I18N.t("dashboard.connections"),
3893+
data: Object.values(this.detail_system.connections),
3894+
type: 'line',
3895+
smooth: true,
3896+
}
3897+
]
3898+
})
37653899
}
37663900
drawGlobals() {
37673901
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/dashboard.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ async def process(type: str, data: Any):
123123
k: v for k, v in web.statistics.get_all_qps().items() if k > c - 300
124124
}
125125
return {
126-
utils.format_time(i): (sum((raw_data.get(i + j, 0) for j in range(5))))
126+
utils.format_time(i + -time.timezone): (sum((raw_data.get(i + j, 0) for j in range(5))))
127127
for i in range(c - 300, c, 5)
128128
}
129129
if type == "status":

core/statistics.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ def init():
120120
*(status.value for status in Status)
121121
):
122122
addColumns("access_storage", field, "unsigned bigint not null default 0")
123-
addColumns("access_storage", "status", "blob not null")
124123

125124
execute("create table if not exists access_globals(hour unsigned bigint not null, addresses blob not null, useragents bigint not null)")
126125
for q in queryAllData(f"select hour, name, type, hit, bytes, cache_hit, cache_bytes, sync_hit, sync_bytes FROM access_storage"):
@@ -168,7 +167,7 @@ def hit(storage: Storage, file: File, length: int, ip: str, ua: str, status: Sta
168167
if (storage.get_name() not in storages or storages[storage.get_name()] != hour) and not exists("select hour from access_storage where hour = ? and name = ? and type = ?",
169168
hour, storage.get_name(), storage.get_type()
170169
):
171-
add_execute("insert into access_storage(hour, name, type, status) values (?,?,?,?)", hour, storage.get_name(), storage.get_type(), b'')
170+
add_execute("insert into access_storage(hour, name, type) values (?,?,?)", hour, storage.get_name(), storage.get_type())
172171
storages[storage.get_name()] = hour
173172
cur_storage = None
174173
data_storages = get_data_storage()

core/system.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import os
2+
import time
23

34
import psutil
45

56
from core import logger, scheduler
6-
from core.utils import get_uptime
7+
from core.utils import get_uptime, format_time
8+
from core.env import env
79

810
process: psutil.Process = psutil.Process(os.getpid())
911
cpus: dict[float, float] = {}
@@ -42,14 +44,34 @@ def get_cpus():
4244

4345
def get_loads_detail():
4446
global cpus, memories, connections
45-
offset: float = float(os.getenv("STARTUP") or 0)
47+
startup: float = env["STARTUP"] + -time.timezone
4648
return {
47-
"cpu": {t + offset: v for t, v in cpus.items()},
48-
"memory": {t + offset: v for t, v in memories.items()},
49-
"connections": {t + offset: len(v) for t, v in connections.items()},
49+
"cpu": {format_time(t + startup): v for t, v in get_filled(cpus.copy()).items()},
50+
"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()},
5052
}
5153

5254

55+
def get_filled(data: dict[float, float]):
56+
key = min(list(data.keys()) or [0])
57+
for _ in range(60 - len(data)):
58+
key -= 1
59+
data[key] = 0
60+
data = dict(sorted(data.items()))
61+
for _ in list(data.keys())[60:]:
62+
data.pop(_)
63+
return data
64+
65+
def get_filled_list(data: dict[float, list]):
66+
key = min(list(data.keys()) or [0])
67+
for _ in range(60 - len(data)):
68+
key -= 1
69+
data[key] = []
70+
data = dict(sorted(data.items()))
71+
for _ in list(data.keys())[60:]:
72+
data.pop(_)
73+
return data
74+
5375
def get_used_memory() -> int:
5476
info = process.memory_full_info()
5577
return info.uss

0 commit comments

Comments
 (0)