开发者社区> 问答> 正文

函数计算怎么 监控数据访问


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



关于Project


FC监控服务指标项的数据都使用相同的Project名称:acs_fc。
使用JAVA SDK设置代码示例如下:
  1. [backcolor=transparent]QueryMetricRequest[backcolor=transparent] request [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]new[backcolor=transparent] [backcolor=transparent]QueryMetricRequest[backcolor=transparent]();
  2. [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设置代码示例如下:
  1. [backcolor=transparent]request[backcolor=transparent].[backcolor=transparent]setStartTime[backcolor=transparent]([backcolor=transparent]"2017-04-26 08:00:00"[backcolor=transparent]);
  2. [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参数不同:
  • Region维度数据的Dimensions设置为
  1. [backcolor=transparent]{[backcolor=transparent]"region"[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]"${your_region}"[backcolor=transparent]}
  • Service维度数据的Dimensions设置为
  1. [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设置为
  1. [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设置代码示例如下:
  1. [backcolor=transparent]request[backcolor=transparent].[backcolor=transparent]setDimensions[backcolor=transparent]([backcolor=transparent]"{\"region\":\"your_region\"}"[backcolor=transparent]);


关于Period


FC监控指标的聚合粒度均为60s。使用JAVA SDK设置代码示例如下:
  1. [backcolor=transparent]request[backcolor=transparent].[backcolor=transparent]setPeriod[backcolor=transparent]([backcolor=transparent]"60"[backcolor=transparent]);


关于Metric


使用JAVA SDK设置代码示例如下:
  1. [backcolor=transparent]request[backcolor=transparent].[backcolor=transparent]setMetric[backcolor=transparent]([backcolor=transparent]"your_metric"[backcolor=transparent]);

FC监控指标参考手册中详细介绍的各项指标项,对应的Metric名称如下表所示:
Metric对应指标项名称
RegionTotalInvocationsRegion维度TotalInvocations
RegionBillableInvocationsRegion维度BillableInvocations
RegionThrottlesRegion维度Throttles
RegionClientErrorsRegion维度ClientErrors
RegionServerErrorsRegion维度ServerErrors
RegionBillableInvocationsRateRegion维度BillableInvocations占比
RegionThrottlesRateRegion维度Throttles占比
RegionClientErrorsRateRegion维度ClientErrors占比
RegionServerErrorsRateRegion维度ServerErrors占比
ServiceTotalInvocationsService维度TotalInvocations
ServiceBillableInvocationsService维度BillableInvocations
ServiceThrottlesService维度Throttles
ServiceClientErrorsService维度ClientErrors
ServiceServerErrorsService维度ServerErrors
ServiceBillableInvocationsRateService维度BillableInvocations占比
ServiceThrottlesRateService维度Throttles占比
ServiceClientErrorsRateService维度ClientErrors占比
ServiceServerErrorsRateService维度ServerErrors占比
FunctionTotalInvocationsFunction维度TotalInvocations
FunctionBillableInvocationsFunction维度BillableInvocations
FunctionThrottlesFunction维度Throttles
FunctionClientErrorsFunction维度ClientErrors
FunctionServerErrorsFunction维度ServerErrors
FunctionBillableInvocationsRateFunction维度BillableInvocations占比
FunctionThrottlesRateFunction维度Throttles占比
FunctionClientErrorsRateFunction维度ClientErrors占比
FunctionServerErrorsRateFunction维度ServerErrors占比
FunctionAvgDurationFunction维度平均Duration


使用示例


pom.xml示例:
  1. [backcolor=transparent]...
  2. [backcolor=transparent]    [backcolor=transparent]<dependencies>
  3. [backcolor=transparent]        [backcolor=transparent]<dependency>
  4. [backcolor=transparent]            [backcolor=transparent]<groupId>[backcolor=transparent]com[backcolor=transparent].[backcolor=transparent]aliyun[backcolor=transparent]</[backcolor=transparent]groupId[backcolor=transparent]>
  5. [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]>
  6. [backcolor=transparent]            [backcolor=transparent]<version>[backcolor=transparent]3.1[backcolor=transparent].[backcolor=transparent]0[backcolor=transparent]</[backcolor=transparent]version[backcolor=transparent]>
  7. [backcolor=transparent]        [backcolor=transparent]</[backcolor=transparent]dependency[backcolor=transparent]>
  8. [backcolor=transparent]        [backcolor=transparent]<dependency>
  9. [backcolor=transparent]            [backcolor=transparent]<groupId>[backcolor=transparent]com[backcolor=transparent].[backcolor=transparent]aliyun[backcolor=transparent]</[backcolor=transparent]groupId[backcolor=transparent]>
  10. [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]>
  11. [backcolor=transparent]            [backcolor=transparent]<version>[backcolor=transparent]5.0[backcolor=transparent].[backcolor=transparent]1[backcolor=transparent]</[backcolor=transparent]version[backcolor=transparent]>
  12. [backcolor=transparent]        [backcolor=transparent]</[backcolor=transparent]dependency[backcolor=transparent]>
  13. [backcolor=transparent]    [backcolor=transparent]</[backcolor=transparent]dependencies[backcolor=transparent]>
  14. [backcolor=transparent]...

代码示例:
  1. [backcolor=transparent]import[backcolor=transparent] com[backcolor=transparent].[backcolor=transparent]alibaba[backcolor=transparent].[backcolor=transparent]fastjson[backcolor=transparent].[backcolor=transparent]JSONObject[backcolor=transparent];
  2. [backcolor=transparent]import[backcolor=transparent] com[backcolor=transparent].[backcolor=transparent]aliyuncs[backcolor=transparent].[backcolor=transparent]DefaultAcsClient[backcolor=transparent];
  3. [backcolor=transparent]import[backcolor=transparent] com[backcolor=transparent].[backcolor=transparent]aliyuncs[backcolor=transparent].[backcolor=transparent]IAcsClient[backcolor=transparent];
  4. [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];
  5. [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];
  6. [backcolor=transparent]import[backcolor=transparent] com[backcolor=transparent].[backcolor=transparent]aliyuncs[backcolor=transparent].[backcolor=transparent]exceptions[backcolor=transparent].[backcolor=transparent]ClientException[backcolor=transparent];
  7. [backcolor=transparent]import[backcolor=transparent] com[backcolor=transparent].[backcolor=transparent]aliyuncs[backcolor=transparent].[backcolor=transparent]exceptions[backcolor=transparent].[backcolor=transparent]ServerException[backcolor=transparent];
  8. [backcolor=transparent]import[backcolor=transparent] com[backcolor=transparent].[backcolor=transparent]aliyuncs[backcolor=transparent].[backcolor=transparent]http[backcolor=transparent].[backcolor=transparent]FormatType[backcolor=transparent];
  9. [backcolor=transparent]import[backcolor=transparent] com[backcolor=transparent].[backcolor=transparent]aliyuncs[backcolor=transparent].[backcolor=transparent]profile[backcolor=transparent].[backcolor=transparent]DefaultProfile[backcolor=transparent];
  10. [backcolor=transparent]import[backcolor=transparent] com[backcolor=transparent].[backcolor=transparent]aliyuncs[backcolor=transparent].[backcolor=transparent]profile[backcolor=transparent].[backcolor=transparent]IClientProfile[backcolor=transparent];
  11. [backcolor=transparent]public[backcolor=transparent] [backcolor=transparent]class[backcolor=transparent] [backcolor=transparent]MonitorService[backcolor=transparent] [backcolor=transparent]{
  12. [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]{
  13. [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]);
  14. [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]);
  15. [backcolor=transparent]        [backcolor=transparent]QueryMetricListRequest[backcolor=transparent] request [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]new[backcolor=transparent] [backcolor=transparent]QueryMetricListRequest[backcolor=transparent]();
  16. [backcolor=transparent]        request[backcolor=transparent].[backcolor=transparent]setProject[backcolor=transparent]([backcolor=transparent]"acs_fc"[backcolor=transparent]);
  17. [backcolor=transparent]        request[backcolor=transparent].[backcolor=transparent]setPeriod[backcolor=transparent]([backcolor=transparent]"60"[backcolor=transparent]);
  18. [backcolor=transparent]        request[backcolor=transparent].[backcolor=transparent]setStartTime[backcolor=transparent]([backcolor=transparent]"2017-04-26 16:20:00"[backcolor=transparent]);
  19. [backcolor=transparent]        request[backcolor=transparent].[backcolor=transparent]setEndTime[backcolor=transparent]([backcolor=transparent]"2017-04-26 16:30:00"[backcolor=transparent]);
  20. [backcolor=transparent]        request[backcolor=transparent].[backcolor=transparent]setAcceptFormat[backcolor=transparent]([backcolor=transparent]FormatType[backcolor=transparent].[backcolor=transparent]JSON[backcolor=transparent]);
  21. [backcolor=transparent]        [backcolor=transparent]try[backcolor=transparent] [backcolor=transparent]{
  22. [backcolor=transparent]            [backcolor=transparent]// Region维度
  23. [backcolor=transparent]            [backcolor=transparent]JSONObject[backcolor=transparent] dim [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]new[backcolor=transparent] [backcolor=transparent]JSONObject[backcolor=transparent]();
  24. [backcolor=transparent]            request[backcolor=transparent].[backcolor=transparent]setMetric[backcolor=transparent]([backcolor=transparent]"RegionTotalInvocations"[backcolor=transparent]);[backcolor=transparent]  [backcolor=transparent]// 选择metric
  25. [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
  26. [backcolor=transparent]            request[backcolor=transparent].[backcolor=transparent]setDimensions[backcolor=transparent]([backcolor=transparent]dim[backcolor=transparent].[backcolor=transparent]toJSONString[backcolor=transparent]());
  27. [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]);
  28. [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]());
  29. [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]());
  30. [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]());
  31. [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]());
  32. [backcolor=transparent]            [backcolor=transparent]// Service维度
  33. [backcolor=transparent]            dim [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]new[backcolor=transparent] [backcolor=transparent]JSONObject[backcolor=transparent]();
  34. [backcolor=transparent]            request[backcolor=transparent].[backcolor=transparent]setMetric[backcolor=transparent]([backcolor=transparent]"ServiceTotalInvocations"[backcolor=transparent]);[backcolor=transparent]  [backcolor=transparent]// 选择metric
  35. [backcolor=transparent]            dim[backcolor=transparent].[backcolor=transparent]put[backcolor=transparent]([backcolor=transparent]"region"[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]"<your_region>"[backcolor=transparent]);
  36. [backcolor=transparent]            dim[backcolor=transparent].[backcolor=transparent]put[backcolor=transparent]([backcolor=transparent]"serviceName"[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]"<your_service_name>"[backcolor=transparent]);
  37. [backcolor=transparent]            request[backcolor=transparent].[backcolor=transparent]setDimensions[backcolor=transparent]([backcolor=transparent]dim[backcolor=transparent].[backcolor=transparent]toJSONString[backcolor=transparent]());
  38. [backcolor=transparent]            response [backcolor=transparent]=[backcolor=transparent] client[backcolor=transparent].[backcolor=transparent]getAcsResponse[backcolor=transparent]([backcolor=transparent]request[backcolor=transparent]);
  39. [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]());
  40. [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]());
  41. [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]());
  42. [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]());
  43. [backcolor=transparent]            [backcolor=transparent]// Function维度
  44. [backcolor=transparent]            dim [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]new[backcolor=transparent] [backcolor=transparent]JSONObject[backcolor=transparent]();
  45. [backcolor=transparent]            request[backcolor=transparent].[backcolor=transparent]setMetric[backcolor=transparent]([backcolor=transparent]"FunctionTotalInvocations"[backcolor=transparent]);[backcolor=transparent]  [backcolor=transparent]// 选择metric
  46. [backcolor=transparent]            dim[backcolor=transparent].[backcolor=transparent]put[backcolor=transparent]([backcolor=transparent]"region"[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]"<your_region>"[backcolor=transparent]);
  47. [backcolor=transparent]            dim[backcolor=transparent].[backcolor=transparent]put[backcolor=transparent]([backcolor=transparent]"serviceName"[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]"<your_service_name>"[backcolor=transparent]);
  48. [backcolor=transparent]            dim[backcolor=transparent].[backcolor=transparent]put[backcolor=transparent]([backcolor=transparent]"functionName"[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]"<your_function_name>"[backcolor=transparent]);
  49. [backcolor=transparent]            request[backcolor=transparent].[backcolor=transparent]setDimensions[backcolor=transparent]([backcolor=transparent]dim[backcolor=transparent].[backcolor=transparent]toJSONString[backcolor=transparent]());
  50. [backcolor=transparent]            response [backcolor=transparent]=[backcolor=transparent] client[backcolor=transparent].[backcolor=transparent]getAcsResponse[backcolor=transparent]([backcolor=transparent]request[backcolor=transparent]);
  51. [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]());
  52. [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]());
  53. [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]());
  54. [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]());
  55. [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]{
  56. [backcolor=transparent]            e[backcolor=transparent].[backcolor=transparent]printStackTrace[backcolor=transparent]();
  57. [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]{
  58. [backcolor=transparent]            e[backcolor=transparent].[backcolor=transparent]printStackTrace[backcolor=transparent]();
  59. [backcolor=transparent]        [backcolor=transparent]}
  60. [backcolor=transparent]    [backcolor=transparent]}
  61. [backcolor=transparent]}

展开
收起
boxti 2017-10-19 16:07:09 1868 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
Hologres Serverless之路:揭秘弹性计算组 立即下载
Serverless开发平台: 让研发效能再提升 立即下载
Serverless 引领云上研发新范式 立即下载