Exemple #1
0
        /// <summary>
        /// 批量查询监控数据
        /// </summary>
        public async Task <BatchListMetricDataResponse> BatchListMetricDataAsync(BatchListMetricDataRequest batchListMetricDataRequest)
        {
            Dictionary <string, string> urlParam = new Dictionary <string, string>();
            string              urlPath          = HttpUtils.AddUrlPath("/V1.0/{project_id}/batch-query-metric-data", urlParam);
            SdkRequest          request          = HttpUtils.InitSdkRequest(urlPath, "application/json;charset=UTF-8", batchListMetricDataRequest);
            HttpResponseMessage response         = await DoHttpRequestAsync("POST", request);

            return(JsonUtils.DeSerialize <BatchListMetricDataResponse>(response));
        }
        /// <summary>
        /// 批量查询指定时间范围内指定指标的指定粒度的监控数据,目前最多支持10指标的批量查询。
        /// </summary>
        /// <param name="cesV1Client"></param>
        private static void BatchListMetricData(CesClient cesClient)
        {
            BatchListMetricDataRequest batchShowMetricDataRequest = new BatchListMetricDataRequest()
            {
                Body = new BatchListMetricDataRequestBody()
                {
                    Metrics = new List <MetricInfo>()
                    {
                        new MetricInfo()
                        {
                            Namespace  = "SYS.ECS",
                            Dimensions = new List <MetricsDimension>()
                            {
                                new MetricsDimension()
                                {
                                    Name  = "instance_id",
                                    Value = "1639371e-066f-4782-924c-40bd2db3ba07"
                                }
                            },
                            MetricName = "cpu_util"
                        }
                    },
                    From   = 1587014357000,
                    To     = 1587017957000,
                    Period = "300",
                    Filter = "average"
                }
            };

            try
            {
                BatchListMetricDataResponse batchListMetricDataResponse =
                    cesClient.BatchListMetricData(batchShowMetricDataRequest);
                foreach (var batchMetricData in batchListMetricDataResponse.Metrics)
                {
                    foreach (var datapoint in batchMetricData.Datapoints)
                    {
                        Console.WriteLine(datapoint.ToString());
                    }
                }
            }
            catch (RequestTimeoutException requestTimeoutException)
            {
                Console.WriteLine(requestTimeoutException.ErrorMessage);
            }
            catch (ServiceResponseException clientRequestException)
            {
                Console.WriteLine(clientRequestException.HttpStatusCode);
                Console.WriteLine(clientRequestException.ErrorCode);
                Console.WriteLine(clientRequestException.ErrorMsg);
            }
            catch (ConnectionException connectionException)
            {
                Console.WriteLine(connectionException.ErrorMessage);
            }
        }