pzx-web-api/app/api/v1/api.py

82 lines
2.4 KiB
Python
Raw Normal View History

2023-08-10 12:27:18 +08:00
import socket
2023-08-10 12:40:31 +08:00
import os
2023-08-10 12:27:18 +08:00
import platform
import psutil
from apiflask import APIBlueprint
api = APIBlueprint('api', __name__)
@api.get('/hello')
def hello():
2023-08-10 12:43:19 +08:00
result_one = f'我是您的专属接口提供服务器: {os.environ["HOSTNAME"]}'
2023-08-10 12:27:18 +08:00
result_two = f'我的机器参数如下'
2023-08-10 13:01:49 +08:00
result_three = f'操作系统:{platform.system()}'
2023-08-10 12:27:18 +08:00
text = """
<style type="text/css">
* {
padding: 0;
margin: 0;
}
div {
padding: 4px 48px;
}
a {
color: black;
cursor: pointer;
text-decoration: none
}
a:hover {
text-decoration: None;
}
body {
background: #fff;
font-family:
"Century Gothic", "Microsoft yahei";
color: #333;
font-size: 18px;
}
h1 {
font-size: 100px;
font-weight: normal;
margin-bottom: 12px;
}
p {
line-height: 1.6em;
font-size: 42px
}
</style>
<div style="padding: 24px 48px;">
<p>
<a href="" target="_Blank">您好PZX 大人</a>
<br />
<span style="font-size:30px">
<a href=""> """ + result_one + """</a>
</span>
<br />
<span style="font-size:25px">
<a href=""> """ + result_two + """</a>
</span>
<br />
<span style="font-size:20px">
<a href=""> """ + result_three + """</a>
<br />
2023-08-10 13:01:49 +08:00
<a href=""> """ + f'CPU 核数:{psutil.cpu_count()},目前 CPU 占用率: {psutil.cpu_percent()}' + """</a>
2023-08-10 12:27:18 +08:00
<br />
2023-08-10 13:02:47 +08:00
<a href=""> """ + f'总内存 {round(psutil.virtual_memory().total / 1024 / 1024, 2)} MB使用中内存{round(psutil.virtual_memory().used / 1024 / 1024, 2)} MB' + """</a>
2023-08-10 13:01:49 +08:00
<br />
<a href=""> """ + f'磁盘总空间 {round(psutil.disk_usage("/").total / 1024 / 1024 / 1024, 2)} G磁盘使用情况{round(psutil.disk_usage("/").used / 1024 / 1024 / 1024, 2)} G' + """</a>
2023-08-10 12:27:18 +08:00
</span>
</p>
</div>
"""
return text