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