diff --git a/flask-consul/units/blackbox_manager.py b/flask-consul/units/blackbox_manager.py index 432895b..58a682e 100644 --- a/flask-consul/units/blackbox_manager.py +++ b/flask-consul/units/blackbox_manager.py @@ -1,5 +1,6 @@ -import requests,json,consul_kv +import requests,json,consul_kv,re from config import consul_token,consul_url +from units.config_log import * headers = {'X-Consul-Token': consul_token} init_module_list = ['http_2xx','http_4xx','tcp_connect','icmp','http200igssl','httpNoRedirect4ssl','http_5xx','http_post_2xx','ssh_banner'] @@ -24,6 +25,7 @@ def get_all_list(module,company,project,env): return {'code': 20000,'all_list':all_list,'module_list':module_list, 'company_list':company_list,'project_list':project_list,'env_list':env_list} else: + logger.error(f"{response.status_code}:{response.text}") return {'code': 50000, 'data': f'{response.status_code}:{response.text}'} def get_service(): @@ -42,10 +44,12 @@ def get_service(): return {'code': 20000,'all_list':all_list,'module_list':module_list, 'company_list':company_list,'project_list':project_list,'env_list':env_list} else: + logger.error(f"{response.status_code}:{response.text}") return {'code': 50000, 'data': f'{response.status_code}:{response.text}'} def add_service(module,company,project,env,name,instance): - sid = f"{module}/{company}/{project}/{env}@{name}" + sid = f"{module}/{company}/{project}/{env}@{name}".strip() + sid = re.sub('[[ \]`~!\\\#$^&*=|"{}\':;?\t\n]','_',sid) if '//' in sid or sid.startswith('/') or sid.endswith('/'): return {"code": 50000, "data": f"服务ID【{sid}】首尾不能包含'/',并且不能包含两个连续的'/'"} data = { @@ -58,14 +62,18 @@ def add_service(module,company,project,env,name,instance): if reg.status_code == 200: return {"code": 20000, "data": f"【{sid}】增加成功!"} else: + logger.error(f"{reg.status_code}【{sid}】{reg.text}") return {"code": 50000, "data": f"{reg.status_code}【{sid}】{reg.text}"} def del_service(module,company,project,env,name): - sid = f"{module}/{company}/{project}/{env}@{name}" + sid = f"{module}/{company}/{project}/{env}@{name}".strip() + sid = re.sub('[[ \]`~!\\\#$^&*=|"{}\':;?\t\n]','_',sid) reg = requests.put(f'{consul_url}/agent/service/deregister/{sid}', headers=headers) if reg.status_code == 200: + logger.debug(f"【{sid}】删除成功!") return {"code": 20000, "data": f"【{sid}】删除成功!"} else: + logger.error(f"{reg.status_code}【{sid}】{reg.text}") return {"code": 50000, "data": f"{reg.status_code}【{sid}】{reg.text}"} def get_rules(): diff --git a/flask-consul/units/consul_manager.py b/flask-consul/units/consul_manager.py index d3cba45..2bb09b9 100644 --- a/flask-consul/units/consul_manager.py +++ b/flask-consul/units/consul_manager.py @@ -1,6 +1,4 @@ -import requests,json -import sys -sys.path.append("..") +import requests,json,re from config import consul_token,consul_url from units.config_log import * @@ -22,6 +20,7 @@ def get_hosts(): 'free':f'{round(info["Disk"]["free"]/1024**3)}GB','used':f'{round(info["Disk"]["used"]/1024**3)}GB','usedPercent':f'{pdisk}%'} return {'code': 20000,'host':host,'cpu':cpu,'memory':memory,'disk':disk, 'pmem':pmem, 'pdisk':pdisk} else: + logger.error(f"{response.status_code}:{response.text}") return {'code': 50000, 'data': f'{response.status_code}:{response.text}'} def get_services(): url = f'{consul_url}/internal/ui/services' @@ -40,6 +39,7 @@ def get_services_nameonly(): info.pop('consul') return {'code': 20000,'services_name':list(info.keys())} else: + logger.error(f"{response.status_code}:{response.text}") return {'code': 50000, 'data': f'{response.status_code}:{response.text}'} def get_instances(service_name): url = f'{consul_url}/health/service/{service_name}' @@ -68,17 +68,21 @@ def get_instances(service_name): instances_list.append(instance_dict) return {'code': 20000,'instances':instances_list} else: + logger.error(f"{response.status_code}:{response.text}") return {'code': 50000, 'data': f'{response.status_code}:{response.text}'} -def del_instance(service_id): - reg = requests.put(f'{consul_url}/agent/service/deregister/{service_id}', headers=headers) +def del_instance(sid): + reg = requests.put(f'{consul_url}/agent/service/deregister/{sid}', headers=headers) if reg.status_code == 200: - return {"code": 20000, "data": f"【{service_id}】删除成功!"} + logger.debug(f"【{sid}】删除成功!") + return {"code": 20000, "data": f"【{sid}】删除成功!"} else: - return {"code": 50000, "data": f"{reg.status_code}【{service_id}】{reg.text}"} + logger.error(f"{reg.status_code}【{sid}】{reg.text}") + return {"code": 50000, "data": f"{reg.status_code}【{sid}】{reg.text}"} def add_instance(instance_dict): - sid = instance_dict['ID'] + sid = instance_dict['ID'].strip() + sid = re.sub('[[ \]`~!\\\#$^&*=|"{}\':;?\t\n]','_',sid) if '//' in sid or sid.startswith('/') or sid.endswith('/'): return {"code": 50000, "data": f"服务ID【{sid}】首尾不能包含'/',并且不能包含两个连续的'/'"} isMeta = instance_dict['metaInfo']['isMeta'] @@ -119,5 +123,6 @@ def add_instance(instance_dict): if reg.status_code == 200: return {"code": 20000, "data": f"【{sid}】增加成功!"} else: + logger.error(f"{reg.status_code}【{sid}】{reg.text}") return {"code": 50000, "data": f"{reg.status_code}【{sid}】{reg.text}"} diff --git a/flask-consul/units/selfnode_manager.py b/flask-consul/units/selfnode_manager.py index 2bdeb53..221ed54 100644 --- a/flask-consul/units/selfnode_manager.py +++ b/flask-consul/units/selfnode_manager.py @@ -1,6 +1,6 @@ -import requests,json -import sys -sys.path.append("..") +import requests,json,re +#import sys +#sys.path.append("..") from config import consul_token,consul_url from units.config_log import * @@ -23,6 +23,7 @@ def get_all_list(vendor,account,region,group): return {'code': 20000,'all_list':all_list,'vendor_list':vendor_list, 'account_list':account_list,'region_list':region_list,'group_list':group_list} else: + logger.error(f"{response.status_code}:{response.text}") return {'code': 50000, 'data': f'{response.status_code}:{response.text}'} def get_service(): @@ -37,12 +38,14 @@ def get_service(): return {'code': 20000,'all_list':all_list,'vendor_list':vendor_list, 'account_list':account_list,'region_list':region_list,'group_list':group_list} else: + logger.error(f"{response.status_code}:{response.text}") return {'code': 50000, 'data': f'{response.status_code}:{response.text}'} def add_service(vendor,account,region,group,name,ip,port,os): if port is None or name is None: return {"code": 50000, "data": f"名称或IP不能为空!"} - sid = f"{vendor}/{account}/{region}/{group}@{name}" + sid = f"{vendor}/{account}/{region}/{group}@{name}".strip() + sid = re.sub('[[ \]`~!\\\#$^&*=|"{}\':;?\t\n]','_',sid) instance = f'{ip}:{port}' if '//' in sid or sid.startswith('/') or sid.endswith('/'): return {"code": 50000, "data": f"服务ID【{sid}】首尾不能包含'/',并且不能包含两个连续的'/'"} @@ -60,14 +63,17 @@ def add_service(vendor,account,region,group,name,ip,port,os): if reg.status_code == 200: return {"code": 20000, "data": f"【{sid}】增加成功!"} else: + logger.error(f"{reg.status_code}【{sid}】{reg.text}") return {"code": 50000, "data": f"{reg.status_code}【{sid}】{reg.text}"} def del_service(vendor,account,region,group,name): - sid = f"{vendor}/{account}/{region}/{group}@{name}" + sid = f"{vendor}/{account}/{region}/{group}@{name}".strip() + sid = re.sub('[[ \]`~!\\\#$^&*=|"{}\':;?\t\n]','_',sid) reg = requests.put(f'{consul_url}/agent/service/deregister/{sid}', headers=headers) if reg.status_code == 200: + logger.debug(f"【{sid}】删除成功!") return {"code": 20000, "data": f"【{sid}】删除成功!"} else: - logger.info(f"{reg.status_code}【{sid}】{reg.text}") + logger.error(f"{reg.status_code}【{sid}】{reg.text}") return {"code": 50000, "data": f"{reg.status_code}【{sid}】{reg.text}"} diff --git a/flask-consul/units/selfrds_manager.py b/flask-consul/units/selfrds_manager.py index 9f1a5ac..026e43a 100644 --- a/flask-consul/units/selfrds_manager.py +++ b/flask-consul/units/selfrds_manager.py @@ -1,6 +1,4 @@ -import requests,json -import sys -sys.path.append("..") +import requests,json,re from config import consul_token,consul_url from units.config_log import * headers = {'X-Consul-Token': consul_token} @@ -22,6 +20,7 @@ def get_all_list(vendor,account,region,group): return {'code': 20000,'all_list':all_list,'vendor_list':vendor_list, 'account_list':account_list,'region_list':region_list,'group_list':group_list} else: + logger.error(f"{response.status_code}:{response.text}") return {'code': 50000, 'data': f'{response.status_code}:{response.text}'} def get_service(): @@ -36,14 +35,17 @@ def get_service(): return {'code': 20000,'all_list':all_list,'vendor_list':vendor_list, 'account_list':account_list,'region_list':region_list,'group_list':group_list} else: + logger.error(f"{response.status_code}:{response.text}") return {'code': 50000, 'data': f'{response.status_code}:{response.text}'} def add_service(vendor,account,region,group,name,ip,port,os): if port is None or name is None: return {"code": 50000, "data": f"名称或IP不能为空!"} - sid = f"{vendor}/{account}/{region}/{group}@{name}" + sid = f"{vendor}/{account}/{region}/{group}@{name}".strip() + #sid = eval(repr(sid).replace('\\t','').replace('\\n','')) + sid = re.sub('[[ \]`~!\\\#$^&*=|"{}\':;?\t\n]','_',sid)+'@rds' instance = f'{ip}:{port}' - if '//' in sid or sid.startswith('/') or sid.endswith('/'): + if '//' in sid or sid.startswith('/'): return {"code": 50000, "data": f"服务ID【{sid}】首尾不能包含'/',并且不能包含两个连续的'/'"} data = { "id": sid, @@ -59,14 +61,17 @@ def add_service(vendor,account,region,group,name,ip,port,os): if reg.status_code == 200: return {"code": 20000, "data": f"【{sid}】增加成功!"} else: + logger.error(f"{reg.status_code}【{sid}】{reg.text}") return {"code": 50000, "data": f"{reg.status_code}【{sid}】{reg.text}"} def del_service(vendor,account,region,group,name): - sid = f"{vendor}/{account}/{region}/{group}@{name}" + sid = f"{vendor}/{account}/{region}/{group}@{name}".strip() + sid = re.sub('[[ \]`~!\\\#$^&*=|"{}\':;?\t\n]','_',sid)+'@rds' reg = requests.put(f'{consul_url}/agent/service/deregister/{sid}', headers=headers) if reg.status_code == 200: + logger.debug(f"【{sid}】删除成功!") return {"code": 20000, "data": f"【{sid}】删除成功!"} else: - logger.info(f"{reg.status_code}【{sid}】{reg.text}") + logger.error(f"{reg.status_code}【{sid}】{reg.text}") return {"code": 50000, "data": f"{reg.status_code}【{sid}】{reg.text}"} diff --git a/flask-consul/units/selfredis_manager.py b/flask-consul/units/selfredis_manager.py index 32a4fb7..302f570 100644 --- a/flask-consul/units/selfredis_manager.py +++ b/flask-consul/units/selfredis_manager.py @@ -1,6 +1,4 @@ -import requests,json -import sys -sys.path.append("..") +import requests,json,re from config import consul_token,consul_url from units.config_log import * headers = {'X-Consul-Token': consul_token} @@ -22,6 +20,7 @@ def get_all_list(vendor,account,region,group): return {'code': 20000,'all_list':all_list,'vendor_list':vendor_list, 'account_list':account_list,'region_list':region_list,'group_list':group_list} else: + logger.error(f"{response.status_code}:{response.text}") return {'code': 50000, 'data': f'{response.status_code}:{response.text}'} def get_service(): @@ -36,14 +35,16 @@ def get_service(): return {'code': 20000,'all_list':all_list,'vendor_list':vendor_list, 'account_list':account_list,'region_list':region_list,'group_list':group_list} else: + logger.error(f"{response.status_code}:{response.text}") return {'code': 50000, 'data': f'{response.status_code}:{response.text}'} def add_service(vendor,account,region,group,name,ip,port,os): if port is None or name is None: return {"code": 50000, "data": f"名称或IP不能为空!"} - sid = f"{vendor}/{account}/{region}/{group}@{name}" + sid = f"{vendor}/{account}/{region}/{group}@{name}".strip() + sid = re.sub('[[ \]`~!\\\#$^&*=|"{}\':;?\t\n]','_',sid)+'@redis' instance = f'{ip}:{port}' - if '//' in sid or sid.startswith('/') or sid.endswith('/'): + if '//' in sid or sid.startswith('/'): return {"code": 50000, "data": f"服务ID【{sid}】首尾不能包含'/',并且不能包含两个连续的'/'"} data = { "id": sid, @@ -59,13 +60,16 @@ def add_service(vendor,account,region,group,name,ip,port,os): if reg.status_code == 200: return {"code": 20000, "data": f"【{sid}】增加成功!"} else: + logger.error(f"{reg.status_code}【{sid}】{reg.text}") return {"code": 50000, "data": f"{reg.status_code}【{sid}】{reg.text}"} def del_service(vendor,account,region,group,name): - sid = f"{vendor}/{account}/{region}/{group}@{name}" + sid = f"{vendor}/{account}/{region}/{group}@{name}".strip() + sid = re.sub('[[ \]`~!\\\#$^&*=|"{}\':;?\t\n]','_',sid)+'@redis' reg = requests.put(f'{consul_url}/agent/service/deregister/{sid}', headers=headers) if reg.status_code == 200: + logger.debug(f"【{sid}】删除成功!") return {"code": 20000, "data": f"【{sid}】删除成功!"} else: - logger.info(f"{reg.status_code}【{sid}】{reg.text}") + logger.error(f"{reg.status_code}【{sid}】{reg.text}") return {"code": 50000, "data": f"{reg.status_code}【{sid}】{reg.text}"} diff --git a/flask-consul/units/upload.py b/flask-consul/units/upload.py index a376706..b31bad3 100644 --- a/flask-consul/units/upload.py +++ b/flask-consul/units/upload.py @@ -35,7 +35,7 @@ def importconsul(row,imptype): elif imptype == 'selfrds': vendor,account,region,group,name,instance,os = row logger.info(row) - sid = f"{vendor}/{account}/{region}/{group}@{name}" + sid = f"{vendor}/{account}/{region}/{group}@{name}@rds" ip = instance.split(':')[0] port = instance.split(':')[1] data = { @@ -51,7 +51,7 @@ def importconsul(row,imptype): elif imptype == 'selfredis': vendor,account,region,group,name,instance,os = row logger.info(row) - sid = f"{vendor}/{account}/{region}/{group}@{name}" + sid = f"{vendor}/{account}/{region}/{group}@{name}@redis" ip = instance.split(':')[0] port = instance.split(':')[1] data = { @@ -96,7 +96,7 @@ def read_execl(file_contents,imptype): j = i.strip() j = '_' if j == '' else j if i != row[5]: - j = re.sub('[[ \]`~!\\\#$^/&*=|"{}\':;?]','_',j) + j = re.sub('[[ \]`~!\\\#$^/&*=|"{}\':;?\t\n]','_',j) nrow.append(j) imp = importconsul(nrow,imptype) if imp['code'] == 50000: diff --git a/vue-consul/src/main.js b/vue-consul/src/main.js index 6678263..e6389d5 100644 --- a/vue-consul/src/main.js +++ b/vue-consul/src/main.js @@ -46,7 +46,7 @@ Object.keys(filters).forEach(key => { }) Vue.config.productionTip = false -Vue.prototype.VER = 'v0.11.2' +Vue.prototype.VER = 'v0.12.0' new Vue({ el: '#app', diff --git a/vue-consul/src/views/dashboard/index.vue b/vue-consul/src/views/dashboard/index.vue index 444fb1b..fadcdb1 100644 --- a/vue-consul/src/views/dashboard/index.vue +++ b/vue-consul/src/views/dashboard/index.vue @@ -7,6 +7,24 @@ 🚀StarsL.cn + + +

v0.12.0

+

修复:自建ECS/RDS/Redis:增加同SID(前5个字段相同)的实例导致,之前增加的同SID实例被替换掉的问题。

+

修复:站点与接口监控、自建ECS/RDS/Redis:实例字段中有特殊字符会无法删除的问题。

+

       以上2个改动可能会引起上述菜单功能兼容性问题:如果出现更新或删除自定义实例失败,请执行以下操作:

+
    +
  • 在相应的实例管理页面,使用导出功能导出实例列表。
  • +
  • 进入Consul管理-实例管理菜单,选择相应的服务组,全选删除所有的实例。
  • +
  • 再返回相应的实例管理页面,重新执行导入操作。
  • +
+

优化:Mysqld Exporter Grafana Dashboard,兼容自建MySQL与云RDS,都能正常展示CPU、内存、磁盘等部分Mysqld_Exporter不提供的指标:

+
    +
  • 自建Mysql:从node-exporter中获取以上信息,通过instance的IP部分进行关联。
  • +
  • 云DRS:从ConsulManager-MySQL中获取,会根据实例ID进行关联。(数据来自云监控,从ConsulManager的Prometheus配置生成菜单中可生成配置。)
  • +
+
+

v0.11.1

@@ -237,4 +255,7 @@ export default { line-height: 46px; } } +li { + margin: 20px 0; +}