diff --git a/flask-consul/requirements.txt b/flask-consul/requirements.txt index 1d43e56..d5bc1ea 100644 --- a/flask-consul/requirements.txt +++ b/flask-consul/requirements.txt @@ -24,9 +24,10 @@ alibabacloud_rds20140815==2.1.2 alibabacloud_r_kvstore20150101==2.20.7 alibabacloud_bssopenapi20171214==2.0.6 aliyun-python-sdk-cms==7.0.32 -tencentcloud-sdk-python-common==3.0.770 -tencentcloud-sdk-python-cvm==3.0.770 -tencentcloud-sdk-python-cdb==3.0.770 -tencentcloud-sdk-python-dcdb==3.0.770 -tencentcloud-sdk-python-billing==3.0.770 -tencentcloud-sdk-python-monitor==3.0.770 +tencentcloud-sdk-python-common==3.0.779 +tencentcloud-sdk-python-cvm==3.0.779 +tencentcloud-sdk-python-cdb==3.0.779 +tencentcloud-sdk-python-dcdb==3.0.779 +tencentcloud-sdk-python-billing==3.0.779 +tencentcloud-sdk-python-monitor==3.0.779 +tencentcloud-sdk-python-redis==3.0.779 diff --git a/flask-consul/units/cloud/sync_rds.py b/flask-consul/units/cloud/sync_rds.py index 488e1bf..e6edbe4 100644 --- a/flask-consul/units/cloud/sync_rds.py +++ b/flask-consul/units/cloud/sync_rds.py @@ -25,7 +25,7 @@ def w2consul(vendor,account,region,rds_dict): for k,v in rds_dict.items(): iid = k #对consul中关机的rds做标记。 - if v['status'] in ['SHUTDOWN']: + if v['status'] in ['SHUTDOWN','非运行中']: off = off + 1 tags = ['OFF',v['itype'],v['ver'], region] stat = 'off' diff --git a/flask-consul/units/cloud/sync_redis.py b/flask-consul/units/cloud/sync_redis.py index 5f6a506..3821403 100644 --- a/flask-consul/units/cloud/sync_redis.py +++ b/flask-consul/units/cloud/sync_redis.py @@ -25,7 +25,7 @@ def w2consul(vendor,account,region,redis_dict): for k,v in redis_dict.items(): iid = k #对consul中关机的redis做标记。 - if v['status'] in ['SHUTDOWN','Unavailable','Inactive','Released']: + if v['status'] in ['SHUTDOWN','Unavailable','Inactive','Released','非运行中']: off = off + 1 tags = ['OFF', v['itype'], v['ver'], region] stat = 'off' diff --git a/flask-consul/units/cloud/tencent_cloud.py b/flask-consul/units/cloud/tencent_cloud.py index 277712e..1662830 100644 --- a/flask-consul/units/cloud/tencent_cloud.py +++ b/flask-consul/units/cloud/tencent_cloud.py @@ -10,6 +10,7 @@ import sys,datetime,hashlib from units import consul_kv from units.cloud import sync_ecs from units.cloud import sync_rds +from units.cloud import sync_redis from units.cloud import notify def exp(account,collect_days,notify_days,notify_amount): @@ -214,3 +215,52 @@ def rds(account,region): except Exception as e: data = {'count':'无','update':f'失败','status':50000,'msg':str(e)} consul_kv.put_kv(f'ConsulManager/record/jobs/tencent_cloud/{account}/rds/{region}', data) + +def redis(account,region): + from tencentcloud.redis.v20180412 import redis_client, models + ak,sk = consul_kv.get_aksk('tencent_cloud',account) + now = datetime.datetime.now().strftime('%m.%d/%H:%M') + group_dict = consul_kv.get_value(f'ConsulManager/assets/tencent_cloud/group/{account}') + try: + cred = credential.Credential(ak, sk) + httpProfile = HttpProfile() + httpProfile.endpoint = "redis.tencentcloudapi.com" + + clientProfile = ClientProfile() + clientProfile.httpProfile = httpProfile + client = redis_client.RedisClient(cred, region, clientProfile) + req = models.DescribeInstancesRequest() + params = {"Limit": 1000} + req.from_json_string(json.dumps(params)) + resp = client.DescribeInstances(req) + redis_list = resp.InstanceSet + total = resp.TotalCount + redis_dict = {i.InstanceId:{'name':i.InstanceName, + 'domain':i.WanIp, + 'ip':i.WanIp, + 'port':i.Port, + 'region':region, + 'group':group_dict.get(str(i.ProjectId),'无'), + 'status': '运行中' if i.Status == 2 else '非运行中', + 'itype':{6:'主从',7:'集群',8:'主从',9:'集群'}.get(i.Type,i.Type), + 'ver':i.CurrentRedisVersion, + 'exp': '按量' if i.DeadlineTime == "0000-00-00 00:00:00" else i.DeadlineTime.split(' ')[0], + 'mem':f"{i.Size}MB", + } for i in redis_list} + count = len(redis_dict) + off,on = sync_redis.w2consul('tencent_cloud',account,region,redis_dict) + data = {'count':count,'update':now,'status':20000,'on':on,'off':off,'msg':f'redis同步成功!总数:{count},开机:{on},关机:{off}'} + consul_kv.put_kv(f'ConsulManager/record/jobs/tencent_cloud/{account}/redis/{region}', data) + print('【JOB】===>', 'tencent_cloud_redis', account,region, data, flush=True) + except TencentCloudSDKException as err: + print(err, flush=True) + data = consul_kv.get_value(f'ConsulManager/record/jobs/tencent_cloud/{account}/redis/{region}') + if data == {}: + data = {'count':'无','update':f'失败','status':50000,'msg':str(err)} + else: + data['update'] = f'失败' + data['msg'] = str(err) + consul_kv.put_kv(f'ConsulManager/record/jobs/tencent_cloud/{account}/redis/{region}', data) + except Exception as e: + data = {'count':'无','update':f'失败','status':50000,'msg':str(e)} + consul_kv.put_kv(f'ConsulManager/record/jobs/tencent_cloud/{account}/redis/{region}', data) diff --git a/flask-consul/units/consul_kv.py b/flask-consul/units/consul_kv.py index f7661cc..4e28cd0 100644 --- a/flask-consul/units/consul_kv.py +++ b/flask-consul/units/consul_kv.py @@ -81,7 +81,7 @@ def get_services_meta(services_name): return {'code': 50000, 'data': f'{response.status_code}:{response.text}'} def get_services_list_by_region(services_name,region): - region = f'and "{region}" in Tags' + region = f'and "{region}" in Tags and "ON" in Tags' url = f'{consul_url}/agent/services?filter=Service == "{services_name}" {region}' response = requests.get(url, headers=headers) if response.status_code == 200: diff --git a/flask-consul/units/prom/redis_tencent.py b/flask-consul/units/prom/redis_tencent.py index 68dc600..0ab2074 100644 --- a/flask-consul/units/prom/redis_tencent.py +++ b/flask-consul/units/prom/redis_tencent.py @@ -27,17 +27,20 @@ def exporter(vendor,account,region): for i in metric_name_dict.keys(): for rediss in redis_list_10: starttime = (datetime.now() + timedelta(minutes=-1)).strftime('%Y-%m-%dT%H:%M:%S+08:00') - ins_list = [{"Dimensions":[{"Name":"InstanceId","Value":x}]} for x in rediss] + ins_list = [{"Dimensions":[{"Name":"instanceid","Value":x}]} for x in rediss] params = {"Namespace":"QCE/REDIS_MEM","MetricName":i,"Period":60,"StartTime":starttime,"Instances":ins_list} req.from_json_string(json.dumps(params)) resp = client.GetMonitorData(req) metric_list = resp.DataPoints for metrics in metric_list: - iid = metrics.Dimensions[0].Value - value = metrics.Values[-1] - ts = metrics.Timestamps[-1]*1000 - prom_metric_name = metric_name_dict[i][0].split()[2] - metric_name_dict[i].append(f'{prom_metric_name}{{iid="{iid}"}} {float(value)} {ts}') + try: + iid = metrics.Dimensions[0].Value + value = metrics.Values[-1] + ts = metrics.Timestamps[-1]*1000 + prom_metric_name = metric_name_dict[i][0].split()[2] + metric_name_dict[i].append(f'{prom_metric_name}{{iid="{iid}"}} {float(value)} {ts}') + except Exception as e: + print("【redis_tencent:prom-metrics-ERROR】",str(e),flush=True) prom_metric_list = [] for x in metric_name_dict.values(): prom_metric_list = prom_metric_list + x diff --git a/flask-consul/views/prom/cloud_metrics.py b/flask-consul/views/prom/cloud_metrics.py index dfdfa8d..2e6407f 100644 --- a/flask-consul/views/prom/cloud_metrics.py +++ b/flask-consul/views/prom/cloud_metrics.py @@ -2,7 +2,7 @@ from flask import Blueprint,Response from flask_restful import reqparse, Resource, Api from config import vendors,regions from units import token_auth,consul_kv -from units.prom import mysql_huawei,mysql_ali,mysql_tencent,redis_huawei,redis_ali +from units.prom import mysql_huawei,mysql_ali,mysql_tencent,redis_huawei,redis_ali,redis_tencent import json blueprint = Blueprint('cloud_metrics',__name__) api = Api(blueprint) @@ -23,8 +23,8 @@ class RedisExporter(Resource): prom_metric_list = redis_huawei.exporter(vendor,account,region) elif vendor == 'alicloud': prom_metric_list = redis_ali.exporter(vendor,account,region) - #elif vendor == 'tencent_cloud': - #prom_metric_list = mysql_tencent.exporter(vendor,account,region) + elif vendor == 'tencent_cloud': + prom_metric_list = redis_tencent.exporter(vendor,account,region) return Response('\n'.join(prom_metric_list).encode('utf-8'),mimetype="text/plain") api.add_resource(RdsExporter, '/api/cloud_mysql_metrics///') api.add_resource(RedisExporter, '/api/cloud_redis_metrics///') diff --git a/vue-consul/src/main.js b/vue-consul/src/main.js index 766feb1..2bbd153 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.0-alpha' +Vue.prototype.VER = 'v0.11.0' new Vue({ el: '#app', diff --git a/vue-consul/src/views/blackbox/index.vue b/vue-consul/src/views/blackbox/index.vue index ca1dbcc..e3869ae 100644 --- a/vue-consul/src/views/blackbox/index.vue +++ b/vue-consul/src/views/blackbox/index.vue @@ -16,7 +16,7 @@ - + @@ -37,7 +37,7 @@ :show-file-list="false" :multiple="false" > - + 导入 diff --git a/vue-consul/src/views/consul/instances.vue b/vue-consul/src/views/consul/instances.vue index bed43cf..549b5ee 100644 --- a/vue-consul/src/views/consul/instances.vue +++ b/vue-consul/src/views/consul/instances.vue @@ -5,7 +5,7 @@ - + diff --git a/vue-consul/src/views/consul/services.vue b/vue-consul/src/views/consul/services.vue index d05cf47..7df6d3d 100644 --- a/vue-consul/src/views/consul/services.vue +++ b/vue-consul/src/views/consul/services.vue @@ -41,20 +41,20 @@ diff --git a/vue-consul/src/views/dashboard/index.vue b/vue-consul/src/views/dashboard/index.vue index a30662c..07d954f 100644 --- a/vue-consul/src/views/dashboard/index.vue +++ b/vue-consul/src/views/dashboard/index.vue @@ -4,6 +4,17 @@ StarsL.cn + + +

v0.11.0

+

新增:Redis监控接入:支持同步华为云、阿里云、腾讯云的Redis信息到Consul并接入到Prometheus监控!(支持自定义IP端口)

+

新增:自建Redis管理界面,支持增删改查、批量导入导出,自动同步到Consul并接入到Prometheus监控!

+

新增:由于Redis_Exporter无法监控到云REDIS的CPU、内存等信息的使用情况,所以ConsulManager开发了Exporter功能,配置到Prometheus即可直接从云厂商采集到这些指标!【直接在Prometheus配置菜单即可生成配置。】

+

新增:从Consul同步RDS到Prometheus的配置生成界面,可生成Prometheus的配置。

+

优化了开关机资源写入consul的标签及Prometheus同步的逻辑,您需要重新生成ECS的Prometheus配置。

+

修复:导入按钮上移的BUG。

+
+

v0.10.2

diff --git a/vue-consul/src/views/jms/index.vue b/vue-consul/src/views/jms/index.vue index 15bc3ca..d8336dc 100644 --- a/vue-consul/src/views/jms/index.vue +++ b/vue-consul/src/views/jms/index.vue @@ -9,7 +9,7 @@ - + 接入JumpServer diff --git a/vue-consul/src/views/node-exporter/exp.vue b/vue-consul/src/views/node-exporter/exp.vue index 0d4c665..b59590d 100644 --- a/vue-consul/src/views/node-exporter/exp.vue +++ b/vue-consul/src/views/node-exporter/exp.vue @@ -7,11 +7,11 @@ - + 配置余额与到期通知 - + 查看余额 diff --git a/vue-consul/src/views/node-exporter/jobs.vue b/vue-consul/src/views/node-exporter/jobs.vue index bfe5d20..13f95cf 100644 --- a/vue-consul/src/views/node-exporter/jobs.vue +++ b/vue-consul/src/views/node-exporter/jobs.vue @@ -14,7 +14,7 @@ - + @@ -24,7 +24,7 @@ 编辑云资源
- +
diff --git a/vue-consul/src/views/node-exporter/lists.vue b/vue-consul/src/views/node-exporter/lists.vue index 35a3b13..43acb53 100644 --- a/vue-consul/src/views/node-exporter/lists.vue +++ b/vue-consul/src/views/node-exporter/lists.vue @@ -4,7 +4,7 @@ - +
diff --git a/vue-consul/src/views/node-exporter/self.vue b/vue-consul/src/views/node-exporter/self.vue index 34cc8f6..a3daa65 100644 --- a/vue-consul/src/views/node-exporter/self.vue +++ b/vue-consul/src/views/node-exporter/self.vue @@ -13,7 +13,7 @@ - + @@ -34,7 +34,7 @@ :show-file-list="false" :multiple="false" > - + 导入 diff --git a/vue-consul/src/views/rds/lists.vue b/vue-consul/src/views/rds/lists.vue index 25b960c..6d4022a 100644 --- a/vue-consul/src/views/rds/lists.vue +++ b/vue-consul/src/views/rds/lists.vue @@ -4,7 +4,7 @@ - +
diff --git a/vue-consul/src/views/rds/self.vue b/vue-consul/src/views/rds/self.vue index 905dc33..bb30384 100644 --- a/vue-consul/src/views/rds/self.vue +++ b/vue-consul/src/views/rds/self.vue @@ -13,7 +13,7 @@ - + @@ -34,7 +34,7 @@ :show-file-list="false" :multiple="false" > - + 导入 diff --git a/vue-consul/src/views/redis/lists.vue b/vue-consul/src/views/redis/lists.vue index 52c5331..0a01dcd 100644 --- a/vue-consul/src/views/redis/lists.vue +++ b/vue-consul/src/views/redis/lists.vue @@ -4,7 +4,7 @@ - +
diff --git a/vue-consul/src/views/redis/self.vue b/vue-consul/src/views/redis/self.vue index 69a4f9f..ffb9ecb 100644 --- a/vue-consul/src/views/redis/self.vue +++ b/vue-consul/src/views/redis/self.vue @@ -13,7 +13,7 @@ - + @@ -34,7 +34,7 @@ :show-file-list="false" :multiple="false" > - + 导入