调用SwitchAdvancedMonitoring接口查询ECS和K8s集群中应用高级监控开关状态及控制接口。
使用SwitchAdvancedMonitoring接口需要保证EDAS POP API Java or Python SDK为3.15.2及以上版本。
调试
您可以在OpenAPI Explorer中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer可以自动生成SDK代码示例。
请求头
该接口使用公共请求头,无特殊请求头。请参见公共请求参数文档。
请求语法
POST|GET /pop/v5/monitor/advancedMonitorInfo HTTP/1.1
请求参数
名称 | 类型 | 位置 | 是否必选 | 示例值 | 描述 |
---|---|---|---|---|---|
AppId | String | Query | 是 | 9e224bc6-a646-4484-****-e617b7e7**** |
需要查询或者修改应用高级监控功能的应用ID。 |
EnableAdvancedMonitoring | Boolean | Query | 否 | true |
应用高级监控的开关。
|
返回数据
名称 | 类型 | 示例值 | 描述 |
---|---|---|---|
AdvancedMonitoringEnabled | Boolean | false |
应用高级监控的开关状态:
|
Code | Integer | 200 |
接口状态或POP错误码 |
Message | String | The advanced monitoring status is disabled already for application which app_id is 9e224bc6-a646-4484-ae31-e617b7e7**** |
附加信息 |
RequestId | String | 577AED12-32D8-40B6-991F-17D7A601**** |
请求ID |
示例
请求示例
### 查询当前应用高级监控的状态(for EDAS POP API Java SDK):
```Java
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.edas.model.v20170801.SwitchAdvancedMonitoringRequest;
import com.aliyuncs.edas.model.v20170801.SwitchAdvancedMonitoringResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
public class SwitchAdvancedMonitoring {
public boolean getAppAdvancedMonitoringStatus(DefaultAcsClient default_acs_client, String app_id){
boolean advancedMonitoringEnabled = false;
SwitchAdvancedMonitoringRequest request = new SwitchAdvancedMonitoringRequest();
request.setSysMethod(MethodType.GET);
request.setAppId(app_id);
try {
SwitchAdvancedMonitoringResponse response = default_acs_client.getAcsResponse(request);
if(response.getCode() == 200){
advancedMonitoringEnabled = response.getAdvancedMonitoringEnabled();
} else {
System.out.println("发生异常: " + response.getMessage() + ", RequestId: " + response.getRequestId());
}
} catch (ClientException e) {
e.printStackTrace();
}
return advancedMonitoringEnabled;
}
public void switchAppAdvancedMonitoringStatus(DefaultAcsClient default_acs_client, String app_id, boolean enabled){
SwitchAdvancedMonitoringRequest request = new SwitchAdvancedMonitoringRequest();
request.setSysMethod(MethodType.POST);
request.setAppId(app_id);
request.setEnableAdvancedMonitoring(enabled);
try {
SwitchAdvancedMonitoringResponse response = default_acs_client.getAcsResponse(request);
if(response.getCode() == 200){
System.out.println("成功修改应用 " + app_id + " 高级监控状态为: " + enabled);
} else {
System.out.println("发生异常:" + response.getMessage() + ", RequestId: " + response.getRequestId());
}
} catch (ClientException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
String region_id = "cn-hangzhou"; //应用所在Region.
String aliyun_user_ak = "LTAI4GFsXKSykRa************"; //主账号、子账号或RAM用户的AccessKey ID。
String aliyun_user_sk = "sIVXvt23GFGi5YF2DqLXE9osWDggCb"; //主账号、子账号或RAM用户的AccessKey Secret。
String app_id = "9e224bc6-a646-4484-ae31-e617b7e7ed18"; //ECS或者K8s集群应用ID。
DefaultProfile defaultProfile = DefaultProfile.getProfile(region_id, aliyun_user_ak, aliyun_user_sk);
DefaultAcsClient defaultAcsClient = new DefaultAcsClient(defaultProfile);
SwitchAdvancedMonitoring switchAdvancedMonitoring = new SwitchAdvancedMonitoring();
switchAdvancedMonitoring.switchAppAdvancedMonitoringStatus(defaultAcsClient, app_id, true);
boolean advanced_monitoring_status = switchAdvancedMonitoring.getAppAdvancedMonitoringStatus(defaultAcsClient, app_id);
System.out.println("获取应用" + app_id + "高级监控状态为:" + advanced_monitoring_status);
}
}
```
### 查询、修改应用高级监控的状态(for EDAS POP API Python SDK):
```python
#!/usr/bin/env python
# -*- coding=UTF-8 -*-
import json
from datetime import datetime
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.http import method_type
from aliyunsdkedas.request.v20170801.SwitchAdvancedMonitoringRequest import SwitchAdvancedMonitoringRequest
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
def getCurrentTimeStamp():
return datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
def getAppAdvancedMonitoringStatus(acs_client, app_id):
advancedMonitoringEnabled = False
am_request = SwitchAdvancedMonitoringRequest()
am_request.set_method(method_type.GET) #HTTP GET for querying.
am_request.set_AppId(app_id)
try:
am_response = json.loads(acs_client.do_action_with_exception(am_request))
if am_response['Code'] == 200:
advancedMonitoringEnabled = am_response['AdvancedMonitoringEnabled']
else:
request_id = am_response['RequestId']
error_msg = am_response['Message']
print(getCurrentTimeStamp() + " - Error occurred while getting application advanced monitoring status, request id is:" + request_id + ", and error message is:" + error_msg)
except ClientException as e:
print(getCurrentTimeStamp() + " - ClientException occurred with message " + e.get_error_msg())
except ServerException as e:
print(getCurrentTimeStamp() + " - ServerException occurred with message " + e.get_error_msg())
return advancedMonitoringEnabled
def switchAppAdvancedMonitoringStatus(acs_client, app_id, enabled):
am_request = SwitchAdvancedMonitoringRequest()
am_request.set_method(method_type.POST) # HTTP POST for switching.
am_request.set_AppId(app_id)
am_request.set_EnableAdvancedMonitoring(enabled)
try:
am_response = json.loads(acs_client.do_action_with_exception(am_request))
if am_response['Code'] == 200:
print(getCurrentTimeStamp() + " - Switch the application " + app_id + " advanced monitoring status to " + str(enabled) + " successfully.")
else:
request_id = am_response['RequestId']
error_msg = am_response['Message']
print(getCurrentTimeStamp() + " - Error occurred while getting application advanced monitoring status, request id is:" + request_id + ", and error message is:" + error_msg)
except ClientException as e:
print(getCurrentTimeStamp() + " - ClientException occurred with message " + e.get_error_msg())
except ServerException as e:
print(getCurrentTimeStamp() + " - ServerException occurred with message " + e.get_error_msg())
if __name__ == '__main__':
aliyun_user_ak = 'LTAI4GFsXKSyk**********' #主账号、子账号或RAM用户的AccessKey ID。
aliyun_user_sk = 'sIVXvt23GFGi5YF2D**************' #主账号、子账号或RAM用户的AccessKey Secret。
region_id = 'cn-hangzhou' #应用所在Region.
app_id = '9e224bc6-a646-4484-ae31-e61*********' #ECS或者K8s集群应用ID。
acs_client = AcsClient(ak=aliyun_user_ak, secret=aliyun_user_sk, region_id=region_id)
switchAppAdvancedMonitoringStatus(acs_client, app_id, False)
advanced_monitoring_status = getAppAdvancedMonitoringStatus(acs_client, app_id)
print(getCurrentTimeStamp() + " - Getting application advanced monitoring status is " + str(advanced_monitoring_status) + ".")
正常返回示例
XML
格式
<AdvancedMonitoringEnabled>false</AdvancedMonitoringEnabled>
<Message>The advanced monitoring status is disabled already for application which app_id is 9e224bc6-a646-4484-ae31-e617b7e7****</Message>
<RequestId>577AED12-32D8-40B6-991F-17D7A601****</RequestId>
<Code>200</Code>
JSON
格式
{
"AdvancedMonitoringEnabled": false,
"Message": "The advanced monitoring status is disabled already for application which app_id is 9e224bc6-a646-4484-ae31-e617b7e7****",
"RequestId": "577AED12-32D8-40B6-991F-17D7A601****",
"Code": 200
}
在文档使用中是否遇到以下问题
更多建议
匿名提交