本章内容为OpenAPI(或者云监控提供的SDK)查询FC监控服务指标数据的使用提供相关参数依据。
关于Project
FC监控服务指标项的数据都使用相同的Project名称:acs_fc。
使用JAVA SDK设置代码示例如下:
- [backcolor=transparent]QueryMetricRequest[backcolor=transparent] request [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]new[backcolor=transparent] [backcolor=transparent]QueryMetricRequest[backcolor=transparent]();
- [backcolor=transparent]request[backcolor=transparent].[backcolor=transparent]setProject[backcolor=transparent]([backcolor=transparent]"acs_fc"[backcolor=transparent]);
关于StartTime和EndTime
云监控的时间参数取值范围采用左开右闭的形式,即(StartTime, EndTime],处于边界StartTime的数据不会被获取,而处于边界EndTime的数据会被查询到。
另外,云监控数据保留时间为31天,设置的StartTime和EndTime的时间间距不能大于31天,并且不能够查询31天以前的数据。
其他时间参数信息详见
云监控API接口说明。
使用JAVA SDK设置代码示例如下:
- [backcolor=transparent]request[backcolor=transparent].[backcolor=transparent]setStartTime[backcolor=transparent]([backcolor=transparent]"2017-04-26 08:00:00"[backcolor=transparent]);
- [backcolor=transparent]request[backcolor=transparent].[backcolor=transparent]setEndTime[backcolor=transparent]([backcolor=transparent]"2017-04-26 09:00:00"[backcolor=transparent]);
关于Dimensions
FC监控服务根据函数计算资源结构和用户使用场景,将监控指标分为Region维度、Service维度和Function维度。不同的维度使用的Dimensions参数不同:
- [backcolor=transparent]{[backcolor=transparent]"region"[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]"${your_region}"[backcolor=transparent]}
- Service维度数据的Dimensions设置为
- [backcolor=transparent]{[backcolor=transparent]"region"[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]"${your_region}"[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]"serviceName"[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]"${your_serviceName}"[backcolor=transparent]}
- Function维度数据的Dimensions设置为
- [backcolor=transparent]{[backcolor=transparent]"region"[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]"${your_region}"[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]"serviceName"[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]"${your_serviceName}"[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]"functionName"[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]"${your_functionName}"[backcolor=transparent]}
注意,Dimenisons是一个JSON字符串,FC监控指标的Dimensions只有一对Key-Value。使用JAVA SDK设置代码示例如下:
- [backcolor=transparent]request[backcolor=transparent].[backcolor=transparent]setDimensions[backcolor=transparent]([backcolor=transparent]"{\"region\":\"your_region\"}"[backcolor=transparent]);
关于Period
FC监控指标的聚合粒度均为60s。使用JAVA SDK设置代码示例如下:
- [backcolor=transparent]request[backcolor=transparent].[backcolor=transparent]setPeriod[backcolor=transparent]([backcolor=transparent]"60"[backcolor=transparent]);
关于Metric
使用JAVA SDK设置代码示例如下:
- [backcolor=transparent]request[backcolor=transparent].[backcolor=transparent]setMetric[backcolor=transparent]([backcolor=transparent]"your_metric"[backcolor=transparent]);
FC监控指标参考手册中详细介绍的各项指标项,对应的Metric名称如下表所示:
使用示例
pom.xml示例:
- [backcolor=transparent]...
- [backcolor=transparent] [backcolor=transparent]<dependencies>
- [backcolor=transparent] [backcolor=transparent]<dependency>
- [backcolor=transparent] [backcolor=transparent]<groupId>[backcolor=transparent]com[backcolor=transparent].[backcolor=transparent]aliyun[backcolor=transparent]</[backcolor=transparent]groupId[backcolor=transparent]>
- [backcolor=transparent] [backcolor=transparent]<artifactId>[backcolor=transparent]aliyun[backcolor=transparent]-[backcolor=transparent]java[backcolor=transparent]-[backcolor=transparent]sdk[backcolor=transparent]-[backcolor=transparent]core[backcolor=transparent]</[backcolor=transparent]artifactId[backcolor=transparent]>
- [backcolor=transparent] [backcolor=transparent]<version>[backcolor=transparent]3.1[backcolor=transparent].[backcolor=transparent]0[backcolor=transparent]</[backcolor=transparent]version[backcolor=transparent]>
- [backcolor=transparent] [backcolor=transparent]</[backcolor=transparent]dependency[backcolor=transparent]>
- [backcolor=transparent] [backcolor=transparent]<dependency>
- [backcolor=transparent] [backcolor=transparent]<groupId>[backcolor=transparent]com[backcolor=transparent].[backcolor=transparent]aliyun[backcolor=transparent]</[backcolor=transparent]groupId[backcolor=transparent]>
- [backcolor=transparent] [backcolor=transparent]<artifactId>[backcolor=transparent]aliyun[backcolor=transparent]-[backcolor=transparent]java[backcolor=transparent]-[backcolor=transparent]sdk[backcolor=transparent]-[backcolor=transparent]cms[backcolor=transparent]</[backcolor=transparent]artifactId[backcolor=transparent]>
- [backcolor=transparent] [backcolor=transparent]<version>[backcolor=transparent]5.0[backcolor=transparent].[backcolor=transparent]1[backcolor=transparent]</[backcolor=transparent]version[backcolor=transparent]>
- [backcolor=transparent] [backcolor=transparent]</[backcolor=transparent]dependency[backcolor=transparent]>
- [backcolor=transparent] [backcolor=transparent]</[backcolor=transparent]dependencies[backcolor=transparent]>
- [backcolor=transparent]...
代码示例:
- [backcolor=transparent]import[backcolor=transparent] com[backcolor=transparent].[backcolor=transparent]alibaba[backcolor=transparent].[backcolor=transparent]fastjson[backcolor=transparent].[backcolor=transparent]JSONObject[backcolor=transparent];
- [backcolor=transparent]import[backcolor=transparent] com[backcolor=transparent].[backcolor=transparent]aliyuncs[backcolor=transparent].[backcolor=transparent]DefaultAcsClient[backcolor=transparent];
- [backcolor=transparent]import[backcolor=transparent] com[backcolor=transparent].[backcolor=transparent]aliyuncs[backcolor=transparent].[backcolor=transparent]IAcsClient[backcolor=transparent];
- [backcolor=transparent]import[backcolor=transparent] com[backcolor=transparent].[backcolor=transparent]aliyuncs[backcolor=transparent].[backcolor=transparent]cms[backcolor=transparent].[backcolor=transparent]model[backcolor=transparent].[backcolor=transparent]v20170301[backcolor=transparent].[backcolor=transparent]QueryMetricListRequest[backcolor=transparent];
- [backcolor=transparent]import[backcolor=transparent] com[backcolor=transparent].[backcolor=transparent]aliyuncs[backcolor=transparent].[backcolor=transparent]cms[backcolor=transparent].[backcolor=transparent]model[backcolor=transparent].[backcolor=transparent]v20170301[backcolor=transparent].[backcolor=transparent]QueryMetricListResponse[backcolor=transparent];
- [backcolor=transparent]import[backcolor=transparent] com[backcolor=transparent].[backcolor=transparent]aliyuncs[backcolor=transparent].[backcolor=transparent]exceptions[backcolor=transparent].[backcolor=transparent]ClientException[backcolor=transparent];
- [backcolor=transparent]import[backcolor=transparent] com[backcolor=transparent].[backcolor=transparent]aliyuncs[backcolor=transparent].[backcolor=transparent]exceptions[backcolor=transparent].[backcolor=transparent]ServerException[backcolor=transparent];
- [backcolor=transparent]import[backcolor=transparent] com[backcolor=transparent].[backcolor=transparent]aliyuncs[backcolor=transparent].[backcolor=transparent]http[backcolor=transparent].[backcolor=transparent]FormatType[backcolor=transparent];
- [backcolor=transparent]import[backcolor=transparent] com[backcolor=transparent].[backcolor=transparent]aliyuncs[backcolor=transparent].[backcolor=transparent]profile[backcolor=transparent].[backcolor=transparent]DefaultProfile[backcolor=transparent];
- [backcolor=transparent]import[backcolor=transparent] com[backcolor=transparent].[backcolor=transparent]aliyuncs[backcolor=transparent].[backcolor=transparent]profile[backcolor=transparent].[backcolor=transparent]IClientProfile[backcolor=transparent];
- [backcolor=transparent]public[backcolor=transparent] [backcolor=transparent]class[backcolor=transparent] [backcolor=transparent]MonitorService[backcolor=transparent] [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent]public[backcolor=transparent] [backcolor=transparent]static[backcolor=transparent] [backcolor=transparent]void[backcolor=transparent] main[backcolor=transparent]([backcolor=transparent]String[backcolor=transparent][][backcolor=transparent] args[backcolor=transparent])[backcolor=transparent] [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent]IClientProfile[backcolor=transparent] profile [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]DefaultProfile[backcolor=transparent].[backcolor=transparent]getProfile[backcolor=transparent]([backcolor=transparent]"cn-hangzhou"[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]"<your_access_key_id>"[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]"<your_access_key_secret>"[backcolor=transparent]);
- [backcolor=transparent] [backcolor=transparent]IAcsClient[backcolor=transparent] client [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]new[backcolor=transparent] [backcolor=transparent]DefaultAcsClient[backcolor=transparent]([backcolor=transparent]profile[backcolor=transparent]);
- [backcolor=transparent] [backcolor=transparent]QueryMetricListRequest[backcolor=transparent] request [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]new[backcolor=transparent] [backcolor=transparent]QueryMetricListRequest[backcolor=transparent]();
- [backcolor=transparent] request[backcolor=transparent].[backcolor=transparent]setProject[backcolor=transparent]([backcolor=transparent]"acs_fc"[backcolor=transparent]);
- [backcolor=transparent] request[backcolor=transparent].[backcolor=transparent]setPeriod[backcolor=transparent]([backcolor=transparent]"60"[backcolor=transparent]);
- [backcolor=transparent] request[backcolor=transparent].[backcolor=transparent]setStartTime[backcolor=transparent]([backcolor=transparent]"2017-04-26 16:20:00"[backcolor=transparent]);
- [backcolor=transparent] request[backcolor=transparent].[backcolor=transparent]setEndTime[backcolor=transparent]([backcolor=transparent]"2017-04-26 16:30:00"[backcolor=transparent]);
- [backcolor=transparent] request[backcolor=transparent].[backcolor=transparent]setAcceptFormat[backcolor=transparent]([backcolor=transparent]FormatType[backcolor=transparent].[backcolor=transparent]JSON[backcolor=transparent]);
- [backcolor=transparent] [backcolor=transparent]try[backcolor=transparent] [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent]// Region维度
- [backcolor=transparent] [backcolor=transparent]JSONObject[backcolor=transparent] dim [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]new[backcolor=transparent] [backcolor=transparent]JSONObject[backcolor=transparent]();
- [backcolor=transparent] request[backcolor=transparent].[backcolor=transparent]setMetric[backcolor=transparent]([backcolor=transparent]"RegionTotalInvocations"[backcolor=transparent]);[backcolor=transparent] [backcolor=transparent]// 选择metric
- [backcolor=transparent] dim[backcolor=transparent].[backcolor=transparent]put[backcolor=transparent]([backcolor=transparent]"region"[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]"<your_region>"[backcolor=transparent]);[backcolor=transparent] [backcolor=transparent]// 如: cn-shanghai
- [backcolor=transparent] request[backcolor=transparent].[backcolor=transparent]setDimensions[backcolor=transparent]([backcolor=transparent]dim[backcolor=transparent].[backcolor=transparent]toJSONString[backcolor=transparent]());
- [backcolor=transparent] [backcolor=transparent]QueryMetricListResponse[backcolor=transparent] response [backcolor=transparent]=[backcolor=transparent] client[backcolor=transparent].[backcolor=transparent]getAcsResponse[backcolor=transparent]([backcolor=transparent]request[backcolor=transparent]);
- [backcolor=transparent] [backcolor=transparent]System[backcolor=transparent].[backcolor=transparent]out[backcolor=transparent].[backcolor=transparent]println[backcolor=transparent]([backcolor=transparent]response[backcolor=transparent].[backcolor=transparent]getCode[backcolor=transparent]());
- [backcolor=transparent] [backcolor=transparent]System[backcolor=transparent].[backcolor=transparent]out[backcolor=transparent].[backcolor=transparent]println[backcolor=transparent]([backcolor=transparent]response[backcolor=transparent].[backcolor=transparent]getMessage[backcolor=transparent]());
- [backcolor=transparent] [backcolor=transparent]System[backcolor=transparent].[backcolor=transparent]out[backcolor=transparent].[backcolor=transparent]println[backcolor=transparent]([backcolor=transparent]response[backcolor=transparent].[backcolor=transparent]getRequestId[backcolor=transparent]());
- [backcolor=transparent] [backcolor=transparent]System[backcolor=transparent].[backcolor=transparent]out[backcolor=transparent].[backcolor=transparent]println[backcolor=transparent]([backcolor=transparent]response[backcolor=transparent].[backcolor=transparent]getDatapoints[backcolor=transparent]());
- [backcolor=transparent] [backcolor=transparent]// Service维度
- [backcolor=transparent] dim [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]new[backcolor=transparent] [backcolor=transparent]JSONObject[backcolor=transparent]();
- [backcolor=transparent] request[backcolor=transparent].[backcolor=transparent]setMetric[backcolor=transparent]([backcolor=transparent]"ServiceTotalInvocations"[backcolor=transparent]);[backcolor=transparent] [backcolor=transparent]// 选择metric
- [backcolor=transparent] dim[backcolor=transparent].[backcolor=transparent]put[backcolor=transparent]([backcolor=transparent]"region"[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]"<your_region>"[backcolor=transparent]);
- [backcolor=transparent] dim[backcolor=transparent].[backcolor=transparent]put[backcolor=transparent]([backcolor=transparent]"serviceName"[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]"<your_service_name>"[backcolor=transparent]);
- [backcolor=transparent] request[backcolor=transparent].[backcolor=transparent]setDimensions[backcolor=transparent]([backcolor=transparent]dim[backcolor=transparent].[backcolor=transparent]toJSONString[backcolor=transparent]());
- [backcolor=transparent] response [backcolor=transparent]=[backcolor=transparent] client[backcolor=transparent].[backcolor=transparent]getAcsResponse[backcolor=transparent]([backcolor=transparent]request[backcolor=transparent]);
- [backcolor=transparent] [backcolor=transparent]System[backcolor=transparent].[backcolor=transparent]out[backcolor=transparent].[backcolor=transparent]println[backcolor=transparent]([backcolor=transparent]response[backcolor=transparent].[backcolor=transparent]getCode[backcolor=transparent]());
- [backcolor=transparent] [backcolor=transparent]System[backcolor=transparent].[backcolor=transparent]out[backcolor=transparent].[backcolor=transparent]println[backcolor=transparent]([backcolor=transparent]response[backcolor=transparent].[backcolor=transparent]getMessage[backcolor=transparent]());
- [backcolor=transparent] [backcolor=transparent]System[backcolor=transparent].[backcolor=transparent]out[backcolor=transparent].[backcolor=transparent]println[backcolor=transparent]([backcolor=transparent]response[backcolor=transparent].[backcolor=transparent]getRequestId[backcolor=transparent]());
- [backcolor=transparent] [backcolor=transparent]System[backcolor=transparent].[backcolor=transparent]out[backcolor=transparent].[backcolor=transparent]println[backcolor=transparent]([backcolor=transparent]response[backcolor=transparent].[backcolor=transparent]getDatapoints[backcolor=transparent]());
- [backcolor=transparent] [backcolor=transparent]// Function维度
- [backcolor=transparent] dim [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]new[backcolor=transparent] [backcolor=transparent]JSONObject[backcolor=transparent]();
- [backcolor=transparent] request[backcolor=transparent].[backcolor=transparent]setMetric[backcolor=transparent]([backcolor=transparent]"FunctionTotalInvocations"[backcolor=transparent]);[backcolor=transparent] [backcolor=transparent]// 选择metric
- [backcolor=transparent] dim[backcolor=transparent].[backcolor=transparent]put[backcolor=transparent]([backcolor=transparent]"region"[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]"<your_region>"[backcolor=transparent]);
- [backcolor=transparent] dim[backcolor=transparent].[backcolor=transparent]put[backcolor=transparent]([backcolor=transparent]"serviceName"[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]"<your_service_name>"[backcolor=transparent]);
- [backcolor=transparent] dim[backcolor=transparent].[backcolor=transparent]put[backcolor=transparent]([backcolor=transparent]"functionName"[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]"<your_function_name>"[backcolor=transparent]);
- [backcolor=transparent] request[backcolor=transparent].[backcolor=transparent]setDimensions[backcolor=transparent]([backcolor=transparent]dim[backcolor=transparent].[backcolor=transparent]toJSONString[backcolor=transparent]());
- [backcolor=transparent] response [backcolor=transparent]=[backcolor=transparent] client[backcolor=transparent].[backcolor=transparent]getAcsResponse[backcolor=transparent]([backcolor=transparent]request[backcolor=transparent]);
- [backcolor=transparent] [backcolor=transparent]System[backcolor=transparent].[backcolor=transparent]out[backcolor=transparent].[backcolor=transparent]println[backcolor=transparent]([backcolor=transparent]response[backcolor=transparent].[backcolor=transparent]getCode[backcolor=transparent]());
- [backcolor=transparent] [backcolor=transparent]System[backcolor=transparent].[backcolor=transparent]out[backcolor=transparent].[backcolor=transparent]println[backcolor=transparent]([backcolor=transparent]response[backcolor=transparent].[backcolor=transparent]getMessage[backcolor=transparent]());
- [backcolor=transparent] [backcolor=transparent]System[backcolor=transparent].[backcolor=transparent]out[backcolor=transparent].[backcolor=transparent]println[backcolor=transparent]([backcolor=transparent]response[backcolor=transparent].[backcolor=transparent]getRequestId[backcolor=transparent]());
- [backcolor=transparent] [backcolor=transparent]System[backcolor=transparent].[backcolor=transparent]out[backcolor=transparent].[backcolor=transparent]println[backcolor=transparent]([backcolor=transparent]response[backcolor=transparent].[backcolor=transparent]getDatapoints[backcolor=transparent]());
- [backcolor=transparent] [backcolor=transparent]}[backcolor=transparent] [backcolor=transparent]catch[backcolor=transparent] [backcolor=transparent]([backcolor=transparent]ServerException[backcolor=transparent] e[backcolor=transparent])[backcolor=transparent] [backcolor=transparent]{
- [backcolor=transparent] e[backcolor=transparent].[backcolor=transparent]printStackTrace[backcolor=transparent]();
- [backcolor=transparent] [backcolor=transparent]}[backcolor=transparent] [backcolor=transparent]catch[backcolor=transparent] [backcolor=transparent]([backcolor=transparent]ClientException[backcolor=transparent] e[backcolor=transparent])[backcolor=transparent] [backcolor=transparent]{
- [backcolor=transparent] e[backcolor=transparent].[backcolor=transparent]printStackTrace[backcolor=transparent]();
- [backcolor=transparent] [backcolor=transparent]}
- [backcolor=transparent] [backcolor=transparent]}
- [backcolor=transparent]}