更改内存硬盘单位自适应
This commit is contained in:
@@ -1,11 +1,13 @@
|
|||||||
import os
|
import os
|
||||||
|
import platform
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import psutil
|
|
||||||
import platform
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
import psutil
|
||||||
from flask import Blueprint, render_template, jsonify
|
from flask import Blueprint, render_template, jsonify
|
||||||
|
|
||||||
from applications.common.utils.rights import authorize
|
from applications.common.utils.rights import authorize
|
||||||
|
|
||||||
bp = Blueprint('adminMonitor', __name__, url_prefix='/monitor')
|
bp = Blueprint('adminMonitor', __name__, url_prefix='/monitor')
|
||||||
@@ -29,9 +31,9 @@ def main():
|
|||||||
memory_information = psutil.virtual_memory()
|
memory_information = psutil.virtual_memory()
|
||||||
# 内存使用率
|
# 内存使用率
|
||||||
memory_usage = memory_information.percent
|
memory_usage = memory_information.percent
|
||||||
memory_used = str(round(memory_information.used / 1024 / 1024))
|
memory_used: int = memory_information.used
|
||||||
memory_total = str(round(memory_information.total / 1024 / 1024))
|
memory_total: int = memory_information.total
|
||||||
memory_free = str(round(memory_information.free / 1024 / 1024))
|
memory_free: int = memory_information.free
|
||||||
# 磁盘信息
|
# 磁盘信息
|
||||||
|
|
||||||
disk_partitions_list = []
|
disk_partitions_list = []
|
||||||
@@ -43,9 +45,9 @@ def main():
|
|||||||
disk_partitions_dict = {
|
disk_partitions_dict = {
|
||||||
'device': i.device,
|
'device': i.device,
|
||||||
'fstype': i.fstype,
|
'fstype': i.fstype,
|
||||||
'total': str(round(a.total / 1024 / 1024)),
|
'total': a.total,
|
||||||
'used': str(round(a.used / 1024 / 1024)),
|
'used': a.used,
|
||||||
'free': str(round(a.free / 1024 / 1024)),
|
'free': a.free,
|
||||||
'percent': a.percent
|
'percent': a.percent
|
||||||
}
|
}
|
||||||
disk_partitions_list.append(disk_partitions_dict)
|
disk_partitions_list.append(disk_partitions_dict)
|
||||||
@@ -58,7 +60,8 @@ def main():
|
|||||||
|
|
||||||
# 当前时间
|
# 当前时间
|
||||||
time_now = time.strftime('%H:%M:%S ', time.localtime(time.time()))
|
time_now = time.strftime('%H:%M:%S ', time.localtime(time.time()))
|
||||||
return render_template('system/monitor.html',
|
return render_template(
|
||||||
|
'system/monitor.html',
|
||||||
hostname=hostname,
|
hostname=hostname,
|
||||||
system_version=system_version,
|
system_version=system_version,
|
||||||
python_version=python_version,
|
python_version=python_version,
|
||||||
@@ -72,7 +75,6 @@ def main():
|
|||||||
up_time_format=up_time_format,
|
up_time_format=up_time_format,
|
||||||
disk_partitions_list=disk_partitions_list,
|
disk_partitions_list=disk_partitions_list,
|
||||||
time_now=time_now
|
time_now=time_now
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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 %}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
{% from 'system/common/memory.html' import memory_format %}
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
@@ -54,19 +55,19 @@
|
|||||||
<div class="layui-col-md6 layui-col-sm6 layui-col-xs6">
|
<div class="layui-col-md6 layui-col-sm6 layui-col-xs6">
|
||||||
<div class="pear-card2">
|
<div class="pear-card2">
|
||||||
<div class="title">空闲内存</div>
|
<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>
|
</div>
|
||||||
<div class="layui-col-md6 layui-col-sm6 layui-col-xs6">
|
<div class="layui-col-md6 layui-col-sm6 layui-col-xs6">
|
||||||
<div class="pear-card2">
|
<div class="pear-card2">
|
||||||
<div class="title">最大内存</div>
|
<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>
|
</div>
|
||||||
<div class="layui-col-md6 layui-col-sm6 layui-col-xs6">
|
<div class="layui-col-md6 layui-col-sm6 layui-col-xs6">
|
||||||
<div class="pear-card2">
|
<div class="pear-card2">
|
||||||
<div class="title">已用内存</div>
|
<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>
|
</div>
|
||||||
<div class="layui-col-md6 layui-col-sm6 layui-col-xs6">
|
<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-header">磁盘信息</div>
|
||||||
<div class="layui-card-body">
|
<div class="layui-card-body">
|
||||||
<ul class="pear-card-status">
|
<ul class="pear-card-status">
|
||||||
{% for i in disk_partitions_list %}
|
{% for disk in disk_partitions_list %}
|
||||||
<li>
|
<li>
|
||||||
<p>{{ i.device }}</p>
|
<p>{{ disk.device }}</p>
|
||||||
<p>{{ i.fstype }}</p>
|
<p>{{ disk.fstype }}</p>
|
||||||
磁盘大小 <span>{{ i.total }}M</span>
|
磁盘大小: <span>{{ memory_format(disk.total) }}</span>
|
||||||
空闲大小 <span>{{ i.free }}M</span>
|
空闲大小: <span>{{ memory_format(disk.free) }}</span>
|
||||||
<br/>
|
<br/>
|
||||||
<br/>
|
<br/>
|
||||||
已经使用 <span>{{ i.used }}M</span>
|
已经使用: <span>{{ memory_format(disk.used) }}</span>
|
||||||
使用概率 <span>{{ i.percent }}%</span>
|
使用率: <span>{{ disk.percent }}%</span>
|
||||||
<br/>
|
<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>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
Reference in New Issue
Block a user