!105 更改内存硬盘单位自适应

Merge pull request !105 from Huo-WenBo/master
This commit is contained in:
不胜舟
2023-07-25 03:54:29 +00:00
committed by Gitee
3 changed files with 51 additions and 35 deletions
+26 -24
View File
@@ -1,11 +1,13 @@
import os
import platform
import re
import sys
import time
import psutil
import platform
from datetime import datetime
import psutil
from flask import Blueprint, render_template, jsonify
from applications.common.utils.rights import authorize
bp = Blueprint('adminMonitor', __name__, url_prefix='/monitor')
@@ -29,9 +31,9 @@ def main():
memory_information = psutil.virtual_memory()
# 内存使用率
memory_usage = memory_information.percent
memory_used = str(round(memory_information.used / 1024 / 1024))
memory_total = str(round(memory_information.total / 1024 / 1024))
memory_free = str(round(memory_information.free / 1024 / 1024))
memory_used: int = memory_information.used
memory_total: int = memory_information.total
memory_free: int = memory_information.free
# 磁盘信息
disk_partitions_list = []
@@ -43,9 +45,9 @@ def main():
disk_partitions_dict = {
'device': i.device,
'fstype': i.fstype,
'total': str(round(a.total / 1024 / 1024)),
'used': str(round(a.used / 1024 / 1024)),
'free': str(round(a.free / 1024 / 1024)),
'total': a.total,
'used': a.used,
'free': a.free,
'percent': a.percent
}
disk_partitions_list.append(disk_partitions_dict)
@@ -58,22 +60,22 @@ def main():
# 当前时间
time_now = time.strftime('%H:%M:%S ', time.localtime(time.time()))
return render_template('system/monitor.html',
hostname=hostname,
system_version=system_version,
python_version=python_version,
cpus_percent=cpus_percent,
memory_usage=memory_usage,
cpu_count=cpu_count,
memory_used=memory_used,
memory_total=memory_total,
memory_free=memory_free,
boot_time=boot_time,
up_time_format=up_time_format,
disk_partitions_list=disk_partitions_list,
time_now=time_now
)
return render_template(
'system/monitor.html',
hostname=hostname,
system_version=system_version,
python_version=python_version,
cpus_percent=cpus_percent,
memory_usage=memory_usage,
cpu_count=cpu_count,
memory_used=memory_used,
memory_total=memory_total,
memory_free=memory_free,
boot_time=boot_time,
up_time_format=up_time_format,
disk_partitions_list=disk_partitions_list,
time_now=time_now
)
# 图表 api
+13
View File
@@ -0,0 +1,13 @@
{% macro memory_format(memory) %}
{%- if memory > 1024 ** 4 * 2 -%}
{{- (memory / 1024 ** 4) | round(2) -}}TB
{% elif memory > 1024 ** 3 * 2 %}
{{- (memory / 1024 ** 3) | round(2) -}}GB
{% elif memory > 1024 ** 2 * 2 %}
{{- (memory / 1024 ** 2) | round(2) -}}MB
{% elif memory > 1024 ** 1 * 2 %}
{{- (memory / 1024 ** 1) | round(2) -}}KB
{% else %}
{{- memory -}}B
{% endif %}
{% endmacro %}
+12 -11
View File
@@ -1,3 +1,4 @@
{% from 'system/common/memory.html' import memory_format %}
<!DOCTYPE html>
<html>
<head>
@@ -54,19 +55,19 @@
<div class="layui-col-md6 layui-col-sm6 layui-col-xs6">
<div class="pear-card2">
<div class="title">空闲内存</div>
<div class="count pear-text">{{ memory_free }}M</div>
<div class="count pear-text">{{ memory_format(memory_free) }}</div>
</div>
</div>
<div class="layui-col-md6 layui-col-sm6 layui-col-xs6">
<div class="pear-card2">
<div class="title">最大内存</div>
<div class="count pear-text">{{ memory_total }}M</div>
<div class="count pear-text">{{ memory_format(memory_total) }}</div>
</div>
</div>
<div class="layui-col-md6 layui-col-sm6 layui-col-xs6">
<div class="pear-card2">
<div class="title">已用内存</div>
<div class="count pear-text">{{ memory_used }}M</div>
<div class="count pear-text">{{ memory_format(memory_used) }}</div>
</div>
</div>
<div class="layui-col-md6 layui-col-sm6 layui-col-xs6">
@@ -96,18 +97,18 @@
<div class="layui-card-header">磁盘信息</div>
<div class="layui-card-body">
<ul class="pear-card-status">
{% for i in disk_partitions_list %}
{% for disk in disk_partitions_list %}
<li>
<p>{{ i.device }}</p>
<p>{{ i.fstype }}</p>
磁盘大小&nbsp;<span>{{ i.total }}M</span>&nbsp;&nbsp;
空闲大小&nbsp;<span>{{ i.free }}M</span>&nbsp;&nbsp;
<p>{{ disk.device }}</p>
<p>{{ disk.fstype }}</p>
磁盘大小: <span>{{ memory_format(disk.total) }}</span>&nbsp;&nbsp;
空闲大小: <span>{{ memory_format(disk.free) }}</span>&nbsp;&nbsp;
<br/>
<br/>
已经使用&nbsp;<span>{{ i.used }}M</span>&nbsp;&nbsp;
使用概率&nbsp;<span>{{ i.percent }}%</span>
已经使用: <span>{{ memory_format(disk.used) }}</span>&nbsp;&nbsp;
使用率: <span>{{ disk.percent }}%</span>
<br/>
<a href="javascript:;" data-id="1" class="pear-btn pear-btn-xs pear-btn-primary pear-reply">详情</a>
<a href="javascript:0" data-id="1" class="pear-btn pear-btn-xs pear-btn-primary pear-reply">详情</a>
</li>
{% endfor %}
</ul>