云监控产品介绍:点击查看。
应用环境的每次发布单(一批容器实例),对应一个云监控分组;
发布单生成的每个容器,对应一个云监控实例;
例如,这个无状态应用,正式环境下作了一个发布,部署了两个容器。
对应的云监控分组名称为:k8s-c6fd41efd9df74f50a8e7804fcb73c27a-jck-namespace-6974-Deployment-jck-deployment-yacs-6974-1874-46250。该环境下的两个pod容器,分别对应了该分组下的两个云监控实例。
ListAppCmsGroups
入参:环境id 应用id;
返回:分组名称列表;
SDK版本 :2.0.5及以上;
注:聚石塔OpenAPI与阿里云api不同,是另外一个sdk。
延伸阅读:聚石塔OpenAPI使用说明。
根据分组名称查询云监控分组:DescribeMonitorGroups;
根据分组查询云监控实例ID:DescribeMonitorGroupInstances。
查询具体的监控指标:DescribeMetricList。
可以查询分组维度(多个实例聚合的)或实例维度(单个实例的),由dimensions参数指定。
具体支持的指标如下:预设监控项参考。
搜索 acs_kubernetes 找到容器服务对应的指标,由metricName参数指定。
查询分组下具体一个实例的cpu使用率指标。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <span class = "lake-preview-line" style= "color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" ><span class = "lake-preview-line-number lake-lm-pad-level-1" style= "color: rgb(191, 191, 191); margin: 0px 8px 0px 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" ></span><span class = "lake-preview-codeblock-content" style= "color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" > //dimensions参数中指定分组或分组+实例,这里指定的是分组+实例,查询具体某个实例的数据 </span></span><span class = "lake-preview-line" style= "color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" ><span class = "lake-preview-line-number lake-lm-pad-level-1" style= "color: rgb(191, 191, 191); margin: 0px 8px 0px 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" ></span><span class = "lake-preview-codeblock-content" style= "color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" >Map<String,String> dimensionMap = new TreeMap<>(); </span></span><span class = "lake-preview-line" style= "color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" ><span class = "lake-preview-line-number lake-lm-pad-level-1" style= "color: rgb(191, 191, 191); margin: 0px 8px 0px 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" ></span><span class = "lake-preview-codeblock-content" style= "color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" >dimensionMap.put( "groupId" , "23679660" ); </span></span><span class = "lake-preview-line" style= "color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" ><span class = "lake-preview-line-number lake-lm-pad-level-1" style= "color: rgb(191, 191, 191); margin: 0px 8px 0px 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" ></span><span class = "lake-preview-codeblock-content" style= "color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" > //如果想指定分组维度,则不需要传podId,下面这行注释掉就可以 </span></span><span class = "lake-preview-line" style= "color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" ><span class = "lake-preview-line-number lake-lm-pad-level-1" style= "color: rgb(191, 191, 191); margin: 0px 8px 0px 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" ></span><span class = "lake-preview-codeblock-content" style= "color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" >dimensionMap.put( "podId" , "5d9f1865-525c-11ea-a0a2-9a669ca3de1b" ); </span></span><span class = "lake-preview-line" style= "color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" ><span class = "lake-preview-line-number lake-lm-pad-level-1" style= "color: rgb(191, 191, 191); margin: 0px 8px 0px 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" ></span><span class = "lake-preview-codeblock-content" style= "color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" >List<Map<String,String>> list = new ArrayList<>(); </span></span><span class = "lake-preview-line" style= "color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" ><span class = "lake-preview-line-number lake-lm-pad-level-1" style= "color: rgb(191, 191, 191); margin: 0px 8px 0px 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" ></span><span class = "lake-preview-codeblock-content" style= "color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" >list.add(dimensionMap); </span></span><span class = "lake-preview-line" style= "color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" ><span class = "lake-preview-line-number lake-lm-pad-level-1" style= "color: rgb(191, 191, 191); margin: 0px 8px 0px 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" ></span><span class = "lake-preview-codeblock-content" style= "color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" > </span></span><span class = "lake-preview-line" style= "color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" ><span class = "lake-preview-line-number lake-lm-pad-level-1" style= "color: rgb(191, 191, 191); margin: 0px 8px 0px 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" ></span><span class = "lake-preview-codeblock-content" style= "color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" >DescribeMetricListRequest describeMetricListRequest = new DescribeMetricListRequest(); </span></span><span class = "lake-preview-line" style= "color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" ><span class = "lake-preview-line-number lake-lm-pad-level-0" style= "color: rgb(191, 191, 191); margin: 0px 8px 0px 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" ></span><span class = "lake-preview-codeblock-content" style= "color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" >describeMetricListRequest.setNamespace( "acs_kubernetes" ); </span></span><span class = "lake-preview-line" style= "color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" ><span class = "lake-preview-line-number lake-lm-pad-level-0" style= "color: rgb(191, 191, 191); margin: 0px 8px 0px 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" ></span><span class = "lake-preview-codeblock-content" style= "color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" >describeMetricListRequest.setDimensions(JSON.toJSONString(list)); </span></span><span class = "lake-preview-line" style= "color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" ><span class = "lake-preview-line-number lake-lm-pad-level-0" style= "color: rgb(191, 191, 191); margin: 0px 8px 0px 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" ></span><span class = "lake-preview-codeblock-content" style= "color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" >describeMetricListRequest.setMetricName( "pod.cpu.usage" ); </span></span><span class = "lake-preview-line" style= "color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" ><span class = "lake-preview-line-number lake-lm-pad-level-0" style= "color: rgb(191, 191, 191); margin: 0px 8px 0px 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" ></span><span class = "lake-preview-codeblock-content" style= "color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" >describeMetricListRequest.setStartTime( "2020-02-19 16:00:00" ); </span></span><span class = "lake-preview-line" style= "color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" ><span class = "lake-preview-line-number lake-lm-pad-level-0" style= "color: rgb(191, 191, 191); margin: 0px 8px 0px 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" ></span><span class = "lake-preview-codeblock-content" style= "color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" >describeMetricListRequest.setEndTime( "2020-02-19 16:05:00" ); </span></span><span class = "lake-preview-line" style= "color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" ><span class = "lake-preview-line-number lake-lm-pad-level-0" style= "color: rgb(191, 191, 191); margin: 0px 8px 0px 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" ></span><span class = "lake-preview-codeblock-content" style= "color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" >describeMetricListRequest.setPeriod( "60" ); </span></span><span class = "lake-preview-line" style= "color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" ><span class = "lake-preview-line-number lake-lm-pad-level-0" style= "color: rgb(191, 191, 191); margin: 0px 8px 0px 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" ></span><span class = "lake-preview-codeblock-content" style= "color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" > </span></span><span class = "lake-preview-line" style= "color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" ><span class = "lake-preview-line-number lake-lm-pad-level-0" style= "color: rgb(191, 191, 191); margin: 0px 8px 0px 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" ></span><span class = "lake-preview-codeblock-content" style= "color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);" >DescribeMetricListResponse describeMetricListResponse = client.getAcsResponse(describeMetricListRequest);</span></span> |
说明,此处的参数podId为云监控实例id(通过云监控api 根据云监控分组查询得到),并非聚石塔pod容器名称。