Queries the status of the advanced application monitoring feature or configures this feature for an application that is deployed in an Elastic Compute Service (ECS) or Kubernetes cluster.

To call the SwitchAdvancedMonitoring operation, you must make sure that the version of EDAS POP API SDK for Java or Python is 3.15.2 or later.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request headers

This operation uses only the common request header. For more information, see Common request parameters.

Request syntax

POST|GET /pop/v5/monitor/advancedMonitorInfo HTTP/1.1

Request parameters

Parameter Type Position Required Example Description
AppId String Query Yes 9e224bc6-a646-4484-****-e617b7e7****

The ID of the application for which you want to query or modify the advanced application monitoring settings.

EnableAdvancedMonitoring Boolean Query No true

Enables or disables the advanced application monitoring feature. Valid values:

  • true: enables the feature.
  • false: disables the feature.

    If you call this operation to query the advanced application monitoring status, you do not need to specify this parameter.

Response parameters

Parameter Type Example Description
AdvancedMonitoringEnabled Boolean false

The status of the advanced application monitoring feature. Valid values:

  • true: enabled.
  • false: disabled.
Code Integer 200

The HTTP status code.

Message String The advanced monitoring status is disabled already for application which app_id is 9e224bc6-a646-4484-ae31-e617b7e7****

The additional information.

RequestId String 577AED12-32D8-40B6-991F-17D7A601****

The ID of the request.

Examples

Sample requests

### Query the status of the advanced application monitoring feature for an application by using EDAS POP API SDK for Java:

```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("exception occurs:" + 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("modified application" + app_id + "advanced monitoring status:" + enabled);
            } else {
                System.out.println("exception occurs:" + response.getMessage() + ", RequestId: " + response.getRequestId());
            }
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        String region_id = "cn-hangzhou"; // The region where the application is located.
        String aliyun_user_ak = "LTAI4GFsXKSykRa************"; // The AccessKey ID of the Alibaba Cloud account, the sub-account, or the Resource Access Management (RAM) user.
        String aliyun_user_sk = "sIVXvt23GFGi5YF2DqLXE9osWDggCb";  // The AccessKey ID of the Alibaba Cloud account, the sub-account, or the RAM user.

        String app_id = "9e224bc6-a646-4484-ae31-e617b7e7ed18"; //The ID of the application that is deployed in an ECS or Kubernetes cluster.

        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("queried application" + app_id + "advanced monitoring status:" + advanced_monitoring_status);
    }
}
```

### Query and modify the status of the advanced application monitoring feature for an application by using EDAS POP API SDK for Python:
```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**********'  # The AccessKey ID of the Alibaba Cloud account, the sub-account, or the RAM user.
    aliyun_user_sk = 'sIVXvt23GFGi5YF2D**************'  # The AccessKey secret of the Alibaba Cloud account, the sub-account, or the RAM user.
    region_id = 'cn-hangzhou'  # The region where the application is located.
    app_id = '9e224bc6-a646-4484-ae31-e61*********'   # The ID of the application that is deployed in an ECS or Kubernetes cluster.

    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) + ".")

Sample success responses

XML format

<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 format

{
    "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
}

Error codes

HttpCode Error code Error message Description
600 Edas.Errorcode.OperationFailed.CloseAdvancedMonitor.Message Failed to disable advanced monitoring. The error message returned because the system has failed to disable advanced application monitoring for the application.
600 Edas.Errorcode.OperationFailed.OpenAdvancedMonitor.Message Failed to enable advanced monitoring. The error message returned because the system has failed to enable advanced application monitoring for the application.

For a list of error codes, visit the API Error Center.