全部产品

监控数据访问指南

更新时间:2017-06-07 13:26:11   分享:   

本章内容为OpenAPI(或者云监控提供的SDK)查询FC监控服务指标数据的使用提供相关参数依据。

关于Project

FC监控服务指标项的数据都使用相同的Project名称:acs_fc。

使用JAVA SDK设置代码示例如下:

  1. QueryMetricRequest request = new QueryMetricRequest();
  2. request.setProject("acs_fc");

关于StartTime和EndTime

云监控的时间参数取值范围采用左开右闭的形式,即(StartTime, EndTime],处于边界StartTime的数据不会被获取,而处于边界EndTime的数据会被查询到。

另外,云监控数据保留时间为31天,设置的StartTime和EndTime的时间间距不能大于31天,并且不能够查询31天以前的数据。

其他时间参数信息详见云监控API接口说明

使用JAVA SDK设置代码示例如下:

  1. request.setStartTime("2017-04-26 08:00:00");
  2. request.setEndTime("2017-04-26 09:00:00");

关于Dimensions

FC监控服务根据函数计算资源结构和用户使用场景,将监控指标分为Region维度、Service维度和Function维度。不同的维度使用的Dimensions参数不同:

  • Region维度数据的Dimensions设置为
  1. {"region": "${your_region}"}
  • Service维度数据的Dimensions设置为
  1. {"region": "${your_region}", "serviceName": "${your_serviceName}"}
  • Function维度数据的Dimensions设置为
  1. {"region": "${your_region}", "serviceName": "${your_serviceName}", "functionName": "${your_functionName}"}

注意,Dimenisons是一个JSON字符串,FC监控指标的Dimensions只有一对Key-Value。使用JAVA SDK设置代码示例如下:

  1. request.setDimensions("{\"region\":\"your_region\"}");

关于Period

FC监控指标的聚合粒度均为60s。使用JAVA SDK设置代码示例如下:

  1. request.setPeriod("60");

关于Metric

使用JAVA SDK设置代码示例如下:

  1. request.setMetric("your_metric");

FC监控指标参考手册中详细介绍的各项指标项,对应的Metric名称如下表所示:

Metric 对应指标项名称
RegionTotalInvocations Region维度TotalInvocations
RegionBillableInvocations Region维度BillableInvocations
RegionThrottles Region维度Throttles
RegionClientErrors Region维度ClientErrors
RegionServerErrors Region维度ServerErrors
RegionBillableInvocationsRate Region维度BillableInvocations占比
RegionThrottlesRate Region维度Throttles占比
RegionClientErrorsRate Region维度ClientErrors占比
RegionServerErrorsRate Region维度ServerErrors占比
ServiceTotalInvocations Service维度TotalInvocations
ServiceBillableInvocations Service维度BillableInvocations
ServiceThrottles Service维度Throttles
ServiceClientErrors Service维度ClientErrors
ServiceServerErrors Service维度ServerErrors
ServiceBillableInvocationsRate Service维度BillableInvocations占比
ServiceThrottlesRate Service维度Throttles占比
ServiceClientErrorsRate Service维度ClientErrors占比
ServiceServerErrorsRate Service维度ServerErrors占比
FunctionTotalInvocations Function维度TotalInvocations
FunctionBillableInvocations Function维度BillableInvocations
FunctionThrottles Function维度Throttles
FunctionClientErrors Function维度ClientErrors
FunctionServerErrors Function维度ServerErrors
FunctionBillableInvocationsRate Function维度BillableInvocations占比
FunctionThrottlesRate Function维度Throttles占比
FunctionClientErrorsRate Function维度ClientErrors占比
FunctionServerErrorsRate Function维度ServerErrors占比
FunctionAvgDuration Function维度平均Duration

使用示例

pom.xml示例:

  1. ...
  2. <dependencies>
  3. <dependency>
  4. <groupId>com.aliyun</groupId>
  5. <artifactId>aliyun-java-sdk-core</artifactId>
  6. <version>3.1.0</version>
  7. </dependency>
  8. <dependency>
  9. <groupId>com.aliyun</groupId>
  10. <artifactId>aliyun-java-sdk-cms</artifactId>
  11. <version>5.0.1</version>
  12. </dependency>
  13. </dependencies>
  14. ...

代码示例:

  1. import com.alibaba.fastjson.JSONObject;
  2. import com.aliyuncs.DefaultAcsClient;
  3. import com.aliyuncs.IAcsClient;
  4. import com.aliyuncs.cms.model.v20170301.QueryMetricListRequest;
  5. import com.aliyuncs.cms.model.v20170301.QueryMetricListResponse;
  6. import com.aliyuncs.exceptions.ClientException;
  7. import com.aliyuncs.exceptions.ServerException;
  8. import com.aliyuncs.http.FormatType;
  9. import com.aliyuncs.profile.DefaultProfile;
  10. import com.aliyuncs.profile.IClientProfile;
  11. public class MonitorService {
  12. public static void main(String[] args) {
  13. IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", "<your_access_key_id>", "<your_access_key_secret>");
  14. IAcsClient client = new DefaultAcsClient(profile);
  15. QueryMetricListRequest request = new QueryMetricListRequest();
  16. request.setProject("acs_fc");
  17. request.setPeriod("60");
  18. request.setStartTime("2017-04-26 16:20:00");
  19. request.setEndTime("2017-04-26 16:30:00");
  20. request.setAcceptFormat(FormatType.JSON);
  21. try {
  22. // Region维度
  23. JSONObject dim = new JSONObject();
  24. request.setMetric("RegionTotalInvocations"); // 选择metric
  25. dim.put("region", "<your_region>"); // 如: cn-shanghai
  26. request.setDimensions(dim.toJSONString());
  27. QueryMetricListResponse response = client.getAcsResponse(request);
  28. System.out.println(response.getCode());
  29. System.out.println(response.getMessage());
  30. System.out.println(response.getRequestId());
  31. System.out.println(response.getDatapoints());
  32. // Service维度
  33. dim = new JSONObject();
  34. request.setMetric("ServiceTotalInvocations"); // 选择metric
  35. dim.put("region", "<your_region>");
  36. dim.put("serviceName", "<your_service_name>");
  37. request.setDimensions(dim.toJSONString());
  38. response = client.getAcsResponse(request);
  39. System.out.println(response.getCode());
  40. System.out.println(response.getMessage());
  41. System.out.println(response.getRequestId());
  42. System.out.println(response.getDatapoints());
  43. // Function维度
  44. dim = new JSONObject();
  45. request.setMetric("FunctionTotalInvocations"); // 选择metric
  46. dim.put("region", "<your_region>");
  47. dim.put("serviceName", "<your_service_name>");
  48. dim.put("functionName", "<your_function_name>");
  49. request.setDimensions(dim.toJSONString());
  50. response = client.getAcsResponse(request);
  51. System.out.println(response.getCode());
  52. System.out.println(response.getMessage());
  53. System.out.println(response.getRequestId());
  54. System.out.println(response.getDatapoints());
  55. } catch (ServerException e) {
  56. e.printStackTrace();
  57. } catch (ClientException e) {
  58. e.printStackTrace();
  59. }
  60. }
  61. }
本文导读目录
本文导读目录
以上内容是否对您有帮助?