-
Notifications
You must be signed in to change notification settings - Fork 0
/
_update_monitor_value.py
93 lines (69 loc) · 2.46 KB
/
_update_monitor_value.py
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from sys_monitor._get_sys_information import get_sys_info
from sys_monitor.utils._db_sqlite import SqliteDB
def _hard_info_parse(hard_info):
fields, values = [], []
# get cpu info
cpu_info = hard_info.get("cpu_info")
for field, value in cpu_info.items():
fields.append(field)
values.append(value)
# get mem info
mem_info = hard_info.get("mem_info")
for field, value in mem_info.items():
fields.append(field)
values.append(value)
# get disk info
disk_info = hard_info.get("disk_info")
fields.append("disk_info")
values.append(str(disk_info).replace("'", '"'))
# get unit info
unit_info = hard_info.get("unit")
fields.append("unit")
values.append(unit_info)
return fields, values
def _sys_status_parse(cpu_status, mem_status, disk_status, net_status):
fields, values = [], []
# get cpu info
for field, value in cpu_status.items():
fields.append(field)
values.append(value)
# get memory info
for field, value in mem_status.items():
fields.append(field)
values.append(value)
# get net i/o info
for field, value in net_status.items():
fields.append(field)
values.append(value)
# get disk info
fields.append("disk_io")
values.append(str(disk_status).replace("'", '"'))
return fields, values
def update_monitor_value_sqlite(db_file):
"""
update tables in sqlite.
:param db_file: sqlite db file
:return:
"""
# get system status and hardware info
run_time, hard_info, cpu_status, mem_status, disk_status, net_status = get_sys_info()
# init sqlite handler
sqlite_handler = SqliteDB(db_file)
# get target table
t_hs_sys_monitor = sqlite_handler.get_table("t_hs_sys_monitor")
# # drop this table temp
# t_hs_hard_info = sqlite_handler.get_table("t_hs_hard_info")
# # insert into hardware info table
# fields, values = _hard_info_parse(hard_info)
# fields.insert(0, "time")
# values.insert(0, run_time)
# t_hs_hard_info.insert(fields, values)
# insert into system status table
fields, values = _sys_status_parse(cpu_status, mem_status, disk_status, net_status)
fields.insert(0, "time")
values.insert(0, run_time)
t_hs_sys_monitor.insert(fields, values)
return "finish"
if __name__ == '__main__':
# update_monitor_value_sqlite("D:/systemonitor/example.db")
update_monitor_value_sqlite("D:/systemonitor/example_new.db")