02:云监控
1.1 云监控
1、云监控相关接口
#! /usr/bin/env python # -*- coding: utf-8 -*- from tencentcloud.common import credential from tencentcloud.common.profile.client_profile import ClientProfile from tencentcloud.common.profile.http_profile import HttpProfile from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException from tencentcloud.monitor.v20180724 import monitor_client, models from day04.settings import secretKey,secretId # 导入腾讯云账户secretId,secretKey值 # 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey def instantiates_auth_obj(): cred = credential.Credential(secretId=secretId, secretKey=secretKey) return cred # 查询指定地域可用区列表(查询北京地域所有主机信息 InstanceId机器唯一ID) def basic_point(Region): try: cred = instantiates_auth_obj() httpProfile = HttpProfile() httpProfile.endpoint = "monitor.tencentcloudapi.com" clientProfile = ClientProfile() clientProfile.httpProfile = httpProfile client = monitor_client.MonitorClient(cred, Region, clientProfile) req = models.DescribeBaseMetricsRequest() params = '{"Namespace":"QCE/CVM"}' req.from_json_string(params) resp = client.DescribeBaseMetrics(req) ret = resp.to_json_string() return ret except TencentCloudSDKException as err: print(err) return {} print basic_point(Region="ap-beijing") # '''1、外网网卡''' ''' WanInpkg:外网平均每秒入包量 WanIntraffic:外网平均每秒入流量 WanOutpkg:外网平均每秒出包量 WanOuttraffic:外网平均每秒出流量 ''' # '''2、内网网卡''' ''' lanInpkg:内网网卡的平均每秒入包量 lanIntraffic:内网网卡的平均每秒入流量 lanOutpkg:内网网卡的平均每秒出包量 lanOuttraffic:内网网卡的平均每秒出流量 ''' # '''3、内存''' ''' MemUsage:用户实际使用的内存量与总内存量之比 MemUsed:使用的内存量 TcpCurrEstab:处于 ESTABLISHED 状态的 TCP 连接数量 ''' # '''4、CPU''' ''' CPULoadAvg:1分钟内CPU平均负载 CPUUsage:CPU利用率是通过CVM子机内部监控组件采集上报 DcCPUUsage:运行期间实时占用的CPU百分比 DcMemUsage:使用的内存占总内存比率 '''
#! /usr/bin/env python # -*- coding: utf-8 -*- from tencentcloud.common import credential from tencentcloud.common.profile.client_profile import ClientProfile from tencentcloud.common.profile.http_profile import HttpProfile from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException from tencentcloud.monitor.v20180724 import monitor_client, models from day04.settings import secretKey,secretId # 导入腾讯云账户secretId,secretKey值 import json import time # 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey def instantiates_auth_obj(): cred = credential.Credential(secretId=secretId, secretKey=secretKey) return cred # 查询指定地域可用区列表(查询北京地域所有主机信息 InstanceId机器唯一ID) def basic_point(Value, data, Region): ''' :param Value: nstanceId机器唯一ID :param data: 请求时参数 :param Region: 地域名称 ''' try: cred = instantiates_auth_obj() httpProfile = HttpProfile() httpProfile.endpoint = "monitor.tencentcloudapi.com" clientProfile = ClientProfile() clientProfile.httpProfile = httpProfile client = monitor_client.MonitorClient(cred, Region , clientProfile) req = models.GetMonitorDataRequest() params = json.dumps(data) req.from_json_string(params) resp = client.GetMonitorData(req) ret= json.loads(resp.to_json_string()) return ret except TencentCloudSDKException as err: print(err) return {} data = { "Namespace": "QCE/CVM", # 命名空间,每个云产品会有一个命名空间 "MetricName": "WanIntraffic", # 指标名称 "StartTime": "2019-03-25 00:00:00", # 起始时间 "EndTime": "2019-03-27 17:15:00", # 结束时间,默认为当前时间 "Period": 300, "Instances": [{ "Dimensions": [{ "Name": "InstanceId", # 实例对象的维度组合(固定这个即可) "Value": "ins-3n9jqe9x" # 机器实例id }] }] } # 查询ins-3n9jqe9主机实例,外网平均每秒入流量 r = basic_point(Value="ins-3n9jqe9x", data=data, Region="ap-beijing") r2 = r['DataPoints'][0]['Values'] print r d = { "Period": 300, "RequestId": "2a34a534-194f-49bd-9a74-4134a4ad1d77", "StartTime": "2019-03-27 00:00:00", "EndTime": "2019-03-27 17:15:00", "DataPoints": [{ "Timestamps": [1553616000, 1553616300, 1553616600], "Values": [0.047, 0.039, 0.047], "Dimensions": [{ "Name": "InstanceId", "Value": "ins-3n9jqe9x" }] }], "MetricName": "AccOuttraffic" }
111111111111112222222222222222222
作者:学无止境
出处:https://www.cnblogs.com/xiaonq
生活不只是眼前的苟且,还有诗和远方。