monitoring.py
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from app.models import *
from app.util.component.ApiTemplate import ApiTemplate
import json
import os
class Api(ApiTemplate):
api_name = "远程监控"
def process(self):
# 返回结果
res = {}
res["data"] = {}
try:
base_dir = os.getcwd()
# 监控文件
monitor_filepath = os.path.join(base_dir, 'file', 'monitor_log.txt')
monitor_file = open(monitor_filepath, "r")
log = monitor_file.read()
monitor_file.close()
res["data"]=json.loads(log)
res["result"] = True
except Exception as e:
raise e
return res
api_doc = {
"tags": ["监控接口"],
"parameters": [
],
"responses": {
200: {
"schema": {
"properties": {
}
}
}
}
}
def format_value(self, value):
# 1024*1024*1024
if value > 1_073_741_824:
value = "{}GB".format(format(value/1_073_741_824, '.1f'))
elif value > 1024**2:
value = "{}MB".format(format(value / 1_048_576, '.1f'))
elif value > 1024:
# 1024*1024
value = "{}KB".format(format(value / 1024.0, '.1f'))
else:
value = "{}B".format(format(value, '.1f'))
return value
def Mb_format_value(self,value):
if value > 1024:
value = "{}GB".format(format(value/1024, '.1f'))
else:
value = "{}MB".format(format(value, '.1f'))
return value