示例#1
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);
            }
        }
示例#2
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();
        }