正在显示
3 个修改的文件
包含
52 行增加
和
14 行删除
@@ -185,7 +185,7 @@ class DataManager(BlueprintApi): | @@ -185,7 +185,7 @@ class DataManager(BlueprintApi): | ||
185 | @bp.route("/init", methods=["GET"]) | 185 | @bp.route("/init", methods=["GET"]) |
186 | def init(): | 186 | def init(): |
187 | username = 'admin' | 187 | username = 'admin' |
188 | - password = 'admin' | 188 | + password = SM3.encode('DMap@123') |
189 | if not User.query.filter_by(username=username).one_or_none(): | 189 | if not User.query.filter_by(username=username).one_or_none(): |
190 | user = User(username=username, password=password, role='admin', | 190 | user = User(username=username, password=password, role='admin', |
191 | phone='', company='', position='', email='', | 191 | phone='', company='', position='', email='', |
@@ -197,12 +197,13 @@ class DataManager(BlueprintApi): | @@ -197,12 +197,13 @@ class DataManager(BlueprintApi): | ||
197 | return "创建默认用户成功" | 197 | return "创建默认用户成功" |
198 | else: | 198 | else: |
199 | return "默认用户已存在" | 199 | return "默认用户已存在" |
200 | - | 200 | + |
201 | @staticmethod | 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 |
@@ -5,8 +5,9 @@ | @@ -5,8 +5,9 @@ | ||
5 | 5 | ||
6 | # import schedule | 6 | # import schedule |
7 | from flask import json | 7 | from flask import json |
8 | +from sqlalchemy import true | ||
8 | from .models import MonitorHost, MonitorInfo | 9 | from .models import MonitorHost, MonitorInfo |
9 | -import datetime | 10 | +from datetime import datetime, timedelta |
10 | import math | 11 | import math |
11 | import uuid | 12 | import uuid |
12 | import schedule | 13 | import schedule |
@@ -30,7 +31,6 @@ def pull_metric(): | @@ -30,7 +31,6 @@ def pull_metric(): | ||
30 | 0, configure.SQLALCHEMY_DATABASE_URI) | 31 | 0, configure.SQLALCHEMY_DATABASE_URI) |
31 | 32 | ||
32 | # 拉取服务器信息 | 33 | # 拉取服务器信息 |
33 | - | ||
34 | hosts = sys_session.query( | 34 | hosts = sys_session.query( |
35 | MonitorHost.host) | 35 | MonitorHost.host) |
36 | for host in hosts: | 36 | for host in hosts: |
@@ -61,7 +61,40 @@ def pull_metric(): | @@ -61,7 +61,40 @@ def pull_metric(): | ||
61 | # 获取数据并汇聚为1min的数据入库 | 61 | # 获取数据并汇聚为1min的数据入库 |
62 | # 结束 | 62 | # 结束 |
63 | except Exception as e: | 63 | except Exception as e: |
64 | - #sys_session.rollback() | 64 | + |
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: | ||
97 | + | ||
65 | StructurePrint().print(e.__str__()+":" + traceback.format_exc(), "error") | 98 | StructurePrint().print(e.__str__()+":" + traceback.format_exc(), "error") |
66 | finally: | 99 | finally: |
67 | if sys_session: | 100 | if sys_session: |
@@ -77,10 +110,13 @@ def pull_metric(): | @@ -77,10 +110,13 @@ def pull_metric(): | ||
77 | 110 | ||
78 | 111 | ||
79 | def start_schedule(): | 112 | def start_schedule(): |
80 | - # # 1分钟巡检一次 | 113 | + |
81 | try: | 114 | try: |
82 | StructurePrint().print("start_schedule") | 115 | StructurePrint().print("start_schedule") |
116 | + # 1分钟巡检一次 | ||
83 | schedule.every(1).minutes.do(pull_metric) | 117 | schedule.every(1).minutes.do(pull_metric) |
118 | + # 每天00:00清理数据 | ||
119 | + schedule.every().day.at('00:00').do(monitor_vacuuming) | ||
84 | stop_run_continuously = run_continuously() | 120 | stop_run_continuously = run_continuously() |
85 | except Exception as e: | 121 | except Exception as e: |
86 | StructurePrint().print("start_schedule:"+e.__str__() + | 122 | StructurePrint().print("start_schedule:"+e.__str__() + |
@@ -130,7 +166,7 @@ def get_sample_data(orginal, name, host): | @@ -130,7 +166,7 @@ def get_sample_data(orginal, name, host): | ||
130 | 166 | ||
131 | 167 | ||
132 | def get_data(stamp, host, metrics_name, cur_data): | 168 | def get_data(stamp, host, metrics_name, cur_data): |
133 | - time_stamp = datetime.datetime.strptime( | 169 | + time_stamp = datetime.strptime( |
134 | cur_data['timestamp'], "%Y-%m-%d %H:%M:%S") | 170 | cur_data['timestamp'], "%Y-%m-%d %H:%M:%S") |
135 | date_stamp = time_stamp.strftime("%Y-%m-%d") | 171 | date_stamp = time_stamp.strftime("%Y-%m-%d") |
136 | guid = uuid.uuid1().__str__() | 172 | guid = uuid.uuid1().__str__() |
请
注册
或
登录
后发表评论