edit-icon download-icon

Metrics data

Last Updated: Aug 17, 2018

This section describes how to use the Alibaba Cloud OpenAPI or the CloudMonitor SDK to query Function Compute (FC) metrics from CloudMonitor Service (CMS).

Project

FC metrics data is available for querying under CMS project: acs_fc.

Sample Java code using CMS SDK:

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

StartTime and EndTime

CloudMonitor metrics data time range is specified by (StartTime, EndTime] inputs where StartTime timestamp is exclusive and EndTime timestamp is inclusive.

CloudMonitor data retention is 31 days. The interval between StartTime and EndTime cannot exceed 31 days, and data earlier than 31 days cannot be queried.

For more detailed parameters information, see CloudMonitor Interface introduction.

Sample Java code using CMS SDK:

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

Dimensions

FC metrics are dimensioned into region, service, and function.

  • Set Dimensions as the following to access regional dimension metrics data:
  1. {"region": "${your_region}"}
  • Set Dimensions as the following to access service-dimension metric data:
  1. {"region": "${your_region}", "serviceName": "${your_serviceName}"}
  • Set Dimensions as the following to access function-dimension metric data:
  1. {"region": "${your_region}", "serviceName": "${your_serviceName}", "functionName": "${your_functionName}"}

Note: “Dimensions” parameter is a JSON string and has only one Key-Value pair for FC.

Sample Java code using CMS SDK:

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

Period

FC metrics are aggregated in 60s period.Sample Java code using CMS SDK:

  1. request.setPeriod("60");

Metric

Sample Java code using CMS SDK:

  1. request.setMetric("your_metric");

The following table lists all the supported metric keys.

Metric Metric name
RegionTotalInvocations Region total invocations
RegionBillableInvocations Region-dimension billable invocations
RegionThrottles Region-dimension throttles
RegionClientErrors Region-dimension client errors
RegionServerErrors Region-dimension server errors
RegionBillableInvocationsRate Percentage of region-dimension billable invocations
RegionThrottlesRate Percentage of region-dimension throttles
RegionClientErrorsRate Percentage of region-dimension client errors
RegionServerErrorsRate Percentage of region-dimension server errors
ServiceTotalInvocations Service-dimension total invocations
ServiceBillableInvocations Service-dimension billable invocations
ServiceThrottles Service-dimension throttles
ServiceClientErrors Service-dimension client errors
ServiceServerErrors Service-dimension server errors
ServiceBillableInvocationsRate Percentage of service-dimension billable invocations
ServiceThrottlesRate Percentage of service-dimension throttles
ServiceClientErrorsRate Percentage of service-dimension client errors
ServiceServerErrorsRate Percentage of service-dimension server errors
FunctionTotalInvocations Function-dimension total invocations
FunctionBillableInvocations Function-dimension billable invocations
FunctionFunctionErrors Function-dimension function errors
FunctionThrottles Function-dimension throttles
FunctionFunctionErrorsRate Percentage of function-dimension function errors
FunctionClientErrors Function-dimension client errors
FunctionServerErrors Function-dimension server errors
FunctionBillableInvocationsRate Percentage of function-dimension billable invocations
FunctionThrottlesRate Percentage of function-dimension throttles
FunctionClientErrorsRate Percentage of function-dimension client errors
FunctionServerErrorsRate Percentage of function-dimension server errors
FunctionAvgDuration Function-dimension average duration
FunctionMaxMemoryUsage Function-dimension maximum memory usage

Example

Adding CMS SDK using Maven 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. ...

Sample code:

  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 dimension
  23. JSONObject dim = new JSONObject();
  24. request.setMetric("RegionTotalInvocations"); // Select the 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 dimension
  33. dim = new JSONObject();
  34. request.setMetric("ServiceTotalInvocations"); // Select the 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 dimension
  44. dim = new JSONObject();
  45. request.setMetric("FunctionTotalInvocations"); // Select the 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. }
Thank you! We've received your feedback.