关机的主机也会同步到consul,并加上tag标识。

pull/27/head
StarsL.cn 2022-07-18 00:00:44 +08:00
parent 70b8e62bf9
commit 7aa10e223d
2 changed files with 55 additions and 52 deletions

View File

@ -24,17 +24,15 @@ def w2consul(vendor,account,region,ecs_dict):
off,on = 0,0
for k,v in ecs_dict.items():
iid = k
#去除consul中关机的ecs
#对consul中关机的ecs做标记。
if v['status'] in ['SHUTOFF','Stopped','STOPPED']:
off = off + 1
if k in consul_ecs_iid_list:
dereg = requests.put(f'{delurl}/{iid}', headers=headers)
if dereg.status_code == 200:
print({"code": 20000,"data": f"{account}-删除成功!"}, flush=True)
else:
print({"code": 50000,"data": f'{dereg.status_code}:{dereg.text}'}, flush=True)
tags = ['shutoff', region]
stat = 'off'
else:
on = on + 1
tags = [v['ostype'],region]
stat = 'on'
custom_ecs = consul_kv.get_value(f'ConsulManager/assets/sync_ecs_custom/{iid}')
port = custom_ecs.get('port')
ip = custom_ecs.get('ip')
@ -48,7 +46,7 @@ def w2consul(vendor,account,region,ecs_dict):
'name': service_name,
'Address': ip,
'port': port,
'tags': [v['ostype'],region],
'tags': tags,
'Meta': {
'iid': iid,
'name': v['name'],
@ -60,7 +58,8 @@ def w2consul(vendor,account,region,ecs_dict):
'os': v['ostype'],
'cpu': v['cpu'],
'mem': v['mem'],
'exp': v['exp']
'exp': v['exp'],
'stat': stat
},
"check": {
"tcp": f"{ip}:{port}",

View File

@ -39,12 +39,16 @@ class Jms(Resource):
count_group = consul_kv.get_value(f'ConsulManager/record/jobs/{vendor}/{account}/group')['count']
services_meta = consul_kv.get_services_meta(f'{vendor}_{account}_ecs').get('ecs_list',[])
count_ecs = len(services_meta)
count_cpu,count_mem,count_win,count_linux = 0,0,0,0
count_off,count_on,count_cpu,count_mem,count_win,count_linux = 0,0,0,0,0,0
for i in services_meta:
if i['os'] == linux:
count_linux = count_linux + 1
elif i['os'] == windows:
count_win = count_win + 1
if i.get('stat') == off:
count_off = count_off + 1
else:
count_on = count_on + 1
cpu = int(i['cpu'].replace('',''))
count_cpu = count_cpu + cpu
mem = int(i['cpu'].replace('GB',''))