容量单位及小数
This commit is contained in:
parent
04b9f39fb9
commit
14d9c2d76a
@ -16,8 +16,8 @@ def _get_disk_info(path):
|
||||
return {
|
||||
'exist': True,
|
||||
'percent': disk_info.percent,
|
||||
'free': disk_info.free / (1024 ** 2),
|
||||
'total': disk_info.total / (1024 ** 2)
|
||||
'free': _better_size_unit(disk_info.free),
|
||||
'total': _better_size_unit(disk_info.total)
|
||||
}
|
||||
else:
|
||||
return {
|
||||
@ -27,6 +27,27 @@ def _get_disk_info(path):
|
||||
'total': 0
|
||||
}
|
||||
|
||||
|
||||
def _better_size_unit(bytes: int) -> str:
|
||||
if bytes > 8*1024:
|
||||
kbytes = bytes / 1024
|
||||
if kbytes > 8*1024:
|
||||
mbytes = kbytes / 1024
|
||||
if mbytes > 4*1024:
|
||||
gbytes = mbytes / 1024
|
||||
if gbytes > 4*1024:
|
||||
tbytes = gbytes / 1024
|
||||
return "{:.2f}TB".format(tbytes)
|
||||
else:
|
||||
return "{:.2f}GB".format(gbytes)
|
||||
else:
|
||||
return "{:.2f}MB".format(mbytes)
|
||||
else:
|
||||
return "{:.1f}KB".format(kbytes)
|
||||
else:
|
||||
return "{}B".format(bytes)
|
||||
|
||||
|
||||
@blueprint.get("/")
|
||||
def collect_basic_status():
|
||||
return jsonify({
|
||||
|
@ -17,3 +17,4 @@ SQLAlchemy==1.4.35
|
||||
Werkzeug==2.1.1
|
||||
wheel==0.37.1
|
||||
zipp==3.8.0
|
||||
psutil==5.9.0
|
@ -128,7 +128,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td>使用率 {{ collector.basic.disk.bili.percent }}%</td>
|
||||
<td :class="{warning: !collector.basic.disk.bili.exist}">{{ collector.basic.disk.bili.free }}M / {{ collector.basic.disk.bili.total }}M</td>
|
||||
<td :class="{warning: !collector.basic.disk.bili.exist}">{{ collector.basic.disk.bili.free }} / {{ collector.basic.disk.bili.total }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>西瓜视频录播目录</td>
|
||||
@ -136,7 +136,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td>使用率 {{ collector.basic.disk.bili.percent }}%</td>
|
||||
<td :class="{warning: !collector.basic.disk.xigua.exist}">{{ collector.basic.disk.xigua.free }}M / {{ collector.basic.disk.xigua.total }}M</td>
|
||||
<td :class="{warning: !collector.basic.disk.xigua.exist}">{{ collector.basic.disk.xigua.free }} / {{ collector.basic.disk.xigua.total }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@ -161,14 +161,14 @@
|
||||
bili: {
|
||||
exist: false,
|
||||
percent: 0,
|
||||
free: 0,
|
||||
total: 0
|
||||
free: "",
|
||||
total: ""
|
||||
},
|
||||
xigua: {
|
||||
exist: false,
|
||||
percent: 0,
|
||||
free: 0,
|
||||
total: 0
|
||||
free: "",
|
||||
total: ""
|
||||
}
|
||||
}
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user