正在显示
3 个修改的文件
包含
51 行增加
和
14 行删除
... | ... | @@ -185,7 +185,7 @@ class DataManager(BlueprintApi): |
185 | 185 | @bp.route("/init", methods=["GET"]) |
186 | 186 | def init(): |
187 | 187 | username = 'admin' |
188 | - password = 'admin' | |
188 | + password = SM3.encode('DMap@123') | |
189 | 189 | if not User.query.filter_by(username=username).one_or_none(): |
190 | 190 | user = User(username=username, password=password, role='admin', |
191 | 191 | phone='', company='', position='', email='', |
... | ... | @@ -197,12 +197,13 @@ class DataManager(BlueprintApi): |
197 | 197 | return "创建默认用户成功" |
198 | 198 | else: |
199 | 199 | return "默认用户已存在" |
200 | - | |
200 | + | |
201 | 201 | @staticmethod |
202 | - @bp.route("/test", methods=["GET"]) | |
203 | - def test(): | |
204 | - result = 'c78ca1de8139e62c99d4c4d2050ddd16' | |
205 | - result = AESHelper.encode('dataman2') | |
206 | - # result=DES.decode('U2FsdGVkX199Ncuh7+0/HVmonwM9Uz7SYnmF73wtW7c=') | |
207 | - result2 = AESHelper.decode(result) | |
208 | - return result2 | |
202 | + @bp.route("/translate", methods=["GET"]) | |
203 | + def translate(): | |
204 | + password = ['esri@123','admin','DMap@123','passwd'] | |
205 | + result = {} | |
206 | + for p in password: | |
207 | + new_pwd = SM3.encode(p) | |
208 | + result[p] = new_pwd | |
209 | + return result | |
\ No newline at end of file | ... | ... |
... | ... | @@ -5,8 +5,9 @@ |
5 | 5 | |
6 | 6 | # import schedule |
7 | 7 | from flask import json |
8 | +from sqlalchemy import true | |
8 | 9 | from .models import MonitorHost, MonitorInfo |
9 | -import datetime | |
10 | +from datetime import datetime, timedelta | |
10 | 11 | import math |
11 | 12 | import uuid |
12 | 13 | import schedule |
... | ... | @@ -30,7 +31,6 @@ def pull_metric(): |
30 | 31 | 0, configure.SQLALCHEMY_DATABASE_URI) |
31 | 32 | |
32 | 33 | # 拉取服务器信息 |
33 | - | |
34 | 34 | hosts = sys_session.query( |
35 | 35 | MonitorHost.host) |
36 | 36 | for host in hosts: |
... | ... | @@ -61,7 +61,39 @@ def pull_metric(): |
61 | 61 | # 获取数据并汇聚为1min的数据入库 |
62 | 62 | # 结束 |
63 | 63 | except Exception as e: |
64 | - sys_session.rollback() | |
64 | + # sys_session.rollback() | |
65 | + StructurePrint().print(e.__str__()+":" + traceback.format_exc(), "error") | |
66 | + finally: | |
67 | + if sys_session: | |
68 | + try: | |
69 | + sys_session.close() | |
70 | + except Exception as e: | |
71 | + StructurePrint().print(e.__str__()+":" + traceback.format_exc(), "error") | |
72 | + if sys_ds: | |
73 | + try: | |
74 | + sys_ds.Destroy() | |
75 | + except Exception as e: | |
76 | + StructurePrint().print(e.__str__()+":" + traceback.format_exc(), "error") | |
77 | + | |
78 | + | |
79 | +#每天清理7天前的数据 | |
80 | +def monitor_vacuuming(): | |
81 | + try: | |
82 | + current_date = datetime.now() | |
83 | + last_7_date = current_date+timedelta(days=-7) | |
84 | + current_hour = current_date.hour | |
85 | + if current_hour == 0: | |
86 | + sys_session = PGUtil.get_db_session( | |
87 | + configure.SQLALCHEMY_DATABASE_URI) | |
88 | + sys_ds = PGUtil.open_pg_data_source( | |
89 | + 0, configure.SQLALCHEMY_DATABASE_URI) | |
90 | + info_orm = sys_session.query(MonitorInfo).filter( | |
91 | + MonitorInfo.time_stamp < last_7_date) | |
92 | + count = info_orm.count() | |
93 | + info_orm.delete() | |
94 | + sys_session.commit() | |
95 | + StructurePrint().print("MonitorInfo清理%d条监控数据" % count, "info") | |
96 | + except Exception as e: | |
65 | 97 | StructurePrint().print(e.__str__()+":" + traceback.format_exc(), "error") |
66 | 98 | finally: |
67 | 99 | if sys_session: |
... | ... | @@ -77,10 +109,13 @@ def pull_metric(): |
77 | 109 | |
78 | 110 | |
79 | 111 | def start_schedule(): |
80 | - # # 1分钟巡检一次 | |
112 | + | |
81 | 113 | try: |
82 | 114 | StructurePrint().print("start_schedule") |
115 | + # 1分钟巡检一次 | |
83 | 116 | schedule.every(1).minutes.do(pull_metric) |
117 | + # 每天00:00清理数据 | |
118 | + schedule.every().day.at('00:00').do(monitor_vacuuming) | |
84 | 119 | stop_run_continuously = run_continuously() |
85 | 120 | except Exception as e: |
86 | 121 | StructurePrint().print("start_schedule:"+e.__str__() + |
... | ... | @@ -130,7 +165,7 @@ def get_sample_data(orginal, name, host): |
130 | 165 | |
131 | 166 | |
132 | 167 | def get_data(stamp, host, metrics_name, cur_data): |
133 | - time_stamp = datetime.datetime.strptime( | |
168 | + time_stamp = datetime.strptime( | |
134 | 169 | cur_data['timestamp'], "%Y-%m-%d %H:%M:%S") |
135 | 170 | date_stamp = time_stamp.strftime("%Y-%m-%d") |
136 | 171 | guid = uuid.uuid1().__str__() | ... | ... |
请
注册
或
登录
后发表评论