提交 d0e68a64cf1ac3a6d2710295c80a55a4fa277cb4

作者 nheweijun
1 个父辈 3ca7fe5e

2022.02.17 整合监控模块

@@ -13,3 +13,5 @@ kazoo==2.8.0 @@ -13,3 +13,5 @@ kazoo==2.8.0
13 paramiko==2.8.0 13 paramiko==2.8.0
14 requests==2.26.0 14 requests==2.26.0
15 schedule==1.1.0 15 schedule==1.1.0
  16 +gmssl==3.2.1
  17 +pycryptodome==3.13.0
@@ -129,46 +129,5 @@ def create_app(): @@ -129,46 +129,5 @@ def create_app():
129 # 不检测https 129 # 不检测https
130 os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1' 130 os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'
131 131
132 - # start_schedule()  
133 - return app  
134 -  
135 -  
136 -def create_schedule():  
137 - monitor = Flask(__name__)  
138 - monitor.config['SQLALCHEMY_DATABASE_URI'] = configure.SQLALCHEMY_DATABASE_URI  
139 - monitor.config['echo'] = True  
140 - monitor.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True  
141 - monitor.config['JSON_AS_ASCII'] = False  
142 - monitor.config['SECRET_KEY'] = configure.SECRET_KEY  
143 -  
144 - # allows cookies and credentials to be submitted across domains  
145 - monitor.config['CORS_SUPPORTS_CREDENTIALS'] = true  
146 - monitor.config['CORS_ORIGINS '] = "*"  
147 -  
148 - # swagger设置  
149 - swagger_config = Swagger.DEFAULT_CONFIG  
150 - Swagger(monitor, config=swagger_config)  
151 -  
152 - # 创建数据库  
153 - db.init_app(monitor)  
154 - # db.create_all(app=monitor)  
155 -  
156 - # 跨域设置  
157 - CORS(monitor)  
158 -  
159 - # 日志  
160 - logging.basicConfig(level=configure.log_level)  
161 - log_file = os.path.join(os.path.dirname(os.path.dirname(  
162 - os.path.realpath(__file__))), "logs", "monitor_log.txt")  
163 - handler = logging.FileHandler(  
164 - log_file, encoding='UTF-8') # 设置日志字符集和存储路径名字  
165 - logging_format = logging.Formatter(  
166 - '[%(levelname)s] %(asctime)s %(message)s')  
167 - handler.setFormatter(logging_format)  
168 - monitor.logger.addHandler(handler)  
169 -  
170 - # 不检测https  
171 - os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'  
172 start_schedule() 132 start_schedule()
173 -  
174 - return monitor 133 + return app
@@ -61,7 +61,7 @@ def pull_metric(): @@ -61,7 +61,7 @@ def pull_metric():
61 # 获取数据并汇聚为1min的数据入库 61 # 获取数据并汇聚为1min的数据入库
62 # 结束 62 # 结束
63 except Exception as e: 63 except Exception as e:
64 - sys_session.rollback() 64 + #sys_session.rollback()
65 StructurePrint().print(e.__str__()+":" + traceback.format_exc(), "error") 65 StructurePrint().print(e.__str__()+":" + traceback.format_exc(), "error")
66 finally: 66 finally:
67 if sys_session: 67 if sys_session:
@@ -7,8 +7,8 @@ SQLALCHEMY_DATABASE_URI = "postgresql://postgres:chinadci@172.26.60.101:5432/dma @@ -7,8 +7,8 @@ SQLALCHEMY_DATABASE_URI = "postgresql://postgres:chinadci@172.26.60.101:5432/dma
7 7
8 8
9 # 指定精华表所在位置(必须为空间库),设置为None则存放在各自的实体库中 9 # 指定精华表所在位置(必须为空间库),设置为None则存放在各自的实体库中
10 -#VACUATE_DB_URI = None  
11 -VACUATE_DB_URI = SQLALCHEMY_DATABASE_URI 10 +VACUATE_DB_URI = None
  11 +#VACUATE_DB_URI = SQLALCHEMY_DATABASE_URI
12 12
13 #DMap引擎 13 #DMap引擎
14 dmap_engine = "http://172.26.99.160:8820" 14 dmap_engine = "http://172.26.99.160:8820"
1 Listen 81 1 Listen 81
2 <VirtualHost *:81> 2 <VirtualHost *:81>
3 ServerName 172.26.60.101 3 ServerName 172.26.60.101
4 - WSGIDaemonProcess yourapplication processes=4 threads=16 4 + WSGIDaemonProcess yourapplication processes=1 threads=16
5 WSGIScriptAlias / /usr/src/app/run.wsgi 5 WSGIScriptAlias / /usr/src/app/run.wsgi
6 WSGIPassAuthorization On 6 WSGIPassAuthorization On
7 7
@@ -12,16 +12,3 @@ Listen 81 @@ -12,16 +12,3 @@ Listen 81
12 Require all granted 12 Require all granted
13 </Directory> 13 </Directory>
14 </VirtualHost> 14 </VirtualHost>
15 -Listen 82  
16 -<VirtualHost *:82>  
17 - ServerName 172.26.60.101  
18 - WSGIDaemonProcess monitormanager processes=1 threads=8  
19 - WSGIScriptAlias / /usr/src/app/monitor.wsgi  
20 - WSGIPassAuthorization On  
21 - <Directory /usr/src/app/>  
22 - WSGIProcessGroup monitormanager  
23 - WSGIApplicationGroup %{GLOBAL}  
24 - WSGIScriptReloading On  
25 - Require all granted  
26 - </Directory>  
27 -</VirtualHost>  
1 -import sys  
2 -import os  
3 -file_path = os.path.dirname(os.path.realpath(__file__))  
4 -sys.path.insert(0, file_path)  
5 -from run_monitor import monitor as application  
@@ -31,23 +31,15 @@ port2=$2 @@ -31,23 +31,15 @@ port2=$2
31 echo "端口2设置为$2 ..." 31 echo "端口2设置为$2 ..."
32 fi 32 fi
33 33
34 -port3=""  
35 -if [ ! -n "$3" ] ;then  
36 -port3="8841"  
37 -echo "未设置端口3,使用默认8841端口..."  
38 -else  
39 -port3=$3  
40 -echo "端口3设置为$3 ..."  
41 -fi  
42 34
43 #启动容器 35 #启动容器
44 echo "正在启动容器..." 36 echo "正在启动容器..."
45 37
46 -set="--restart=always -e ALLOW_IP_RANGE=0.0.0.0/0 -p $port1:80 -p $port2:81 -p $port3:82" 38 +set="--restart=always -e ALLOW_IP_RANGE=0.0.0.0/0 -p $port1:80 -p $port2:81 "
47 codeMap="-v ${curPath}:/usr/src/app -v ${curPath}/html:/var/www/html" 39 codeMap="-v ${curPath}:/usr/src/app -v ${curPath}/html:/var/www/html"
48 apacheMap="-v ${curPath}/apache2.conf:/etc/apache2/apache2.conf -v ${curPath}/dmapmanager.conf:/etc/apache2/sites-enabled/dmapmanager.conf -v ${curPath}/envvars:/etc/apache2/envvars" 40 apacheMap="-v ${curPath}/apache2.conf:/etc/apache2/apache2.conf -v ${curPath}/dmapmanager.conf:/etc/apache2/sites-enabled/dmapmanager.conf -v ${curPath}/envvars:/etc/apache2/envvars"
49 41
50 docker run -it -d --name ${container_name} ${set} ${codeMap} ${apacheMap} dci/dmapmanager:4.1 42 docker run -it -d --name ${container_name} ${set} ${codeMap} ${apacheMap} dci/dmapmanager:4.1
51 sleep 5 43 sleep 5
52 curl localhost:$port2/release 44 curl localhost:$port2/release
53 -curl localhost:$port3 45 +#curl localhost:$port3
@@ -7,4 +7,3 @@ os.environ['AUTHLIB_INSECURE_TRANSPORT'] = '1' @@ -7,4 +7,3 @@ os.environ['AUTHLIB_INSECURE_TRANSPORT'] = '1'
7 app: Flask = create_app() 7 app: Flask = create_app()
8 if __name__ == '__main__': 8 if __name__ == '__main__':
9 app.run(host="0.0.0.0", port="8841", threaded=True, debug=True) 9 app.run(host="0.0.0.0", port="8841", threaded=True, debug=True)
10 - # app.run(host="0.0.0.0", port="8840", threaded=True)  
1 -# coding=utf-8  
2 -from flask import Flask  
3 -from app import create_schedule  
4 -import os  
5 -os.environ['AUTHLIB_INSECURE_TRANSPORT'] = '1'  
6 -monitor:Flask=create_schedule()  
7 -if __name__ == '__main__':  
8 - monitor.run(host="0.0.0.0", port="8840", threaded=True, debug=True)  
9 - # app.run(host="0.0.0.0", port="8840", threaded=True)  
1 -# coding=utf-8  
2 -#author: 4N  
3 -#createtime: 2021/7/15  
4 -#email: nheweijun@sina.com  
5 -  
6 -from osgeo import gdal,osr,ogr  
7 -from osgeo.gdal import *  
8 -from osgeo.ogr import *  
9 -  
10 -import os  
11 -import json  
12 -  
13 -  
14 -def getInfo( path):  
15 - # driver: Driver = ogr.GetDriverByName("OpenFileGDB")  
16 - # ds: DataSource = driver.Open(path, 0)  
17 - #  
18 - #  
19 - # layer:Layer = ds.GetLayerByName("LM51130251998341HAJ00_B2")  
20 - #  
21 - # count = layer.GetFeatureCount()  
22 - #  
23 - # dd:Feature = layer.GetNextFeature()  
24 - # dd.  
25 - #  
26 - # for i in range(dd.GetFieldCount()):  
27 - # print(dd.GetField(i))  
28 - # ff = dd.GetField(1)  
29 - image: Dataset = gdal.Open(path)  
30 -  
31 - geo = image.GetGeoTransform()  
32 -  
33 - # print(image.GetSpatialRef())  
34 -  
35 - origin: osr.SpatialReference = osr.SpatialReference()  
36 - origin.ImportFromWkt(image.GetProjection())  
37 -  
38 - authority_code = origin.GetAuthorityCode(None)  
39 -  
40 - band_count = image.RasterCount  
41 - band: Band = image.GetRasterBand(1)  
42 -  
43 - count = band.GetOverviewCount()  
44 - nodatavalue = band.GetNoDataValue()  
45 -  
46 - left_top = (geo[0], geo[3])  
47 - right_buttom = (geo[0] + geo[1] * image.RasterXSize, geo[3] + geo[5] * image.RasterYSize)  
48 -  
49 - origin_extent = [left_top[0], right_buttom[1], right_buttom[0], left_top[1]]  
50 -  
51 - info = {"band_count": band_count,  
52 - "overview_count": count,  
53 - "xy_size": [image.RasterXSize, image.RasterYSize],  
54 - "origin_extent": origin_extent,  
55 - "null_value": nodatavalue,  
56 - "crs_wkt": image.GetProjection(),  
57 - "crs": authority_code,  
58 - "crs_proj4": origin.ExportToProj4(),  
59 - "size": os.path.getsize(path),  
60 - "path": path,  
61 - "cell_x_size": geo[1],  
62 - "cell_y_size": geo[5]}  
63 -  
64 - del image  
65 - return json.dumps(info)  
66 -  
67 -if __name__ == '__main__':  
68 - data_path = r"E:\Data\矢量数据\广州\广州\dataset.gdb"  
69 -  
70 - driver: Driver = ogr.GetDriverByName("OpenFileGDB")  
71 - ds: DataSource = driver.Open(data_path, 0)  
72 - layer : Layer = ds.GetLayer(0)  
73 -  
74 -  
75 - print(layer.GetMetadata())  
76 - print(layer.GetDescription())  
77 - print(layer.GetStyleTable())  
78 -  
79 - print(ds.GetStyleTable())  
80 -  
81 -  
82 -  
83 -  
注册登录 后发表评论