diff --git a/applications/view/system/monitor.py b/applications/view/system/monitor.py index c4c1264496e3e7636743a4a6e67655b133a0acbc..972d49cfd677e17a555ce9c3f5ff903e8f08e6bf 100644 --- a/applications/view/system/monitor.py +++ b/applications/view/system/monitor.py @@ -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 diff --git a/templates/system/common/memory.html b/templates/system/common/memory.html new file mode 100644 index 0000000000000000000000000000000000000000..d7a0821e0e930ca4dd36894b95883d90673ef859 --- /dev/null +++ b/templates/system/common/memory.html @@ -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 %} \ No newline at end of file diff --git a/templates/system/monitor.html b/templates/system/monitor.html index 6ea17e9e2fff41dfba9d0edc5648e1ff263fe0a3..4643bd77340830f410f878692bdb4c216bd86296 100644 --- a/templates/system/monitor.html +++ b/templates/system/monitor.html @@ -1,3 +1,4 @@ +{% from 'system/common/memory.html' import memory_format %}
@@ -54,19 +55,19 @@{{ i.device }}
-{{ i.fstype }}
- 磁盘大小 {{ i.total }}M - 空闲大小 {{ i.free }}M +{{ disk.device }}
+{{ disk.fstype }}
+ 磁盘大小: {{ memory_format(disk.total) }} + 空闲大小: {{ memory_format(disk.free) }}