コード例 #1
0
        /// <summary>
        /// GetMonitorData接口的同步版本,获取云产品的监控数据。传入产品的命名空间、对象维度描述和监控指标即可获得相应的监控数据。
        /// 接口调用频率限制为:20次/秒,1200次/分钟。
        /// 若您需要调用的指标、对象较多,可能存在因限频出现拉取失败的情况,建议尽量将请求按时间维度均摊。
        /// </summary>
        /// <param name="req">参考<see cref="GetMonitorDataRequest"/></param>
        /// <returns>参考<see cref="GetMonitorDataResponse"/>实例</returns>
        public GetMonitorDataResponse GetMonitorDataSync(GetMonitorDataRequest req)
        {
            JsonResponseModel <GetMonitorDataResponse> rsp = null;

            try
            {
                var strResp = this.InternalRequestSync(req, "GetMonitorData");
                rsp = JsonConvert.DeserializeObject <JsonResponseModel <GetMonitorDataResponse> >(strResp);
            }
            catch (JsonSerializationException e)
            {
                throw new TencentCloudSDKException(e.Message);
            }
            return(rsp.Response);
        }
コード例 #2
0
        private void GetData()
        {
            try
            {
                Credential cred = new Credential
                {
                    SecretId  = APIKey.SecretID,
                    SecretKey = APIKey.SecretKey
                };

                ClientProfile clientProfile = new ClientProfile();
                HttpProfile   httpProfile   = new HttpProfile();
                httpProfile.Endpoint      = ("monitor.tencentcloudapi.com");
                clientProfile.HttpProfile = httpProfile;

                MonitorClient         client = new MonitorClient(cred, IRegion, clientProfile);
                GetMonitorDataRequest req    = new GetMonitorDataRequest();
                req.Namespace  = "QCE/CVM";
                req.MetricName = Metric;
                Instance  instance1  = new Instance();
                Dimension dimension1 = new Dimension();
                dimension1.Name      = "InstanceId";
                dimension1.Value     = InstanceID;
                instance1.Dimensions = new Dimension[] { dimension1 };

                req.Instances = new Instance[] { instance1 };

                GetMonitorDataResponse resp = client.GetMonitorDataSync(req);

                dataPoints.Clear();
                for (int i1 = 0; i1 < resp.DataPoints[0].Timestamps.Length; i1++)
                {
                    MetricDataPoint i = new MetricDataPoint()
                    {
                        time = resp.DataPoints[0].Timestamps[i1], value = resp.DataPoints[0].Values[i1]
                    };
                    dataPoints.Enqueue(i);
                    if (dataPoints.Count > 10)
                    {
                        dataPoints.Dequeue();
                    }
                }
            }
            catch (Exception e)
            {
                SOLMain.WriteLogline("获取数据失败:" + e.Message, SOLMain.LogLevel.Error);
            }
        }
コード例 #3
0
        public static void GetMonitorData(string SecretID, string SecretKey, string Region, string Metric, string InstanceID)
        {
            try
            {
                Credential cred = new Credential
                {
                    SecretId  = SecretID,
                    SecretKey = SecretKey
                };

                ClientProfile clientProfile = new ClientProfile();
                HttpProfile   httpProfile   = new HttpProfile();
                httpProfile.Endpoint      = ("monitor.tencentcloudapi.com");
                clientProfile.HttpProfile = httpProfile;

                MonitorClient         client = new MonitorClient(cred, Region, clientProfile);
                GetMonitorDataRequest req    = new GetMonitorDataRequest();
                req.Namespace  = "QCE/CVM";
                req.MetricName = Metric;
                Instance  instance1  = new Instance();
                Dimension dimension1 = new Dimension();
                dimension1.Name      = "InstanceId";
                dimension1.Value     = InstanceID;
                instance1.Dimensions = new Dimension[] { dimension1 };

                req.Instances = new Instance[] { instance1 };

                GetMonitorDataResponse resp = client.GetMonitorDataSync(req);
                Console.WriteLine(AbstractModel.ToJsonString(resp));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            Console.Read();
        }