All Products
Search
Document Center

Database Autonomy Service:GetMySQLAllSessionAsync

Last Updated:Apr 25, 2024

Asynchronously queries the sessions of an instance and collects statistics on the sessions based on dimensions.

Operation description

Note Asynchronous calls do not immediately return the complete results. You must use the value of ResultId returned in the response to re-initiate the call. The complete results are returned only if the value of IsFinish is true.
  • This operation is applicable only to ApsaraDB RDS for MySQL, PolarDB for MySQL, and PolarDB-X 2.0 instances.
  • If you use an Alibaba Cloud SDK or Database Autonomy Service (DAS) SDK to call this operation, we recommend that you use the latest version of the SDK.
  • If you use an SDK to call API operations of DAS, you must set the region ID to cn-shanghai.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer.

Authorization information

The following table shows the authorization information corresponding to the API. The authorization information can be used in the Action policy element to grant a RAM user or RAM role the permissions to call this API operation. Description:

  • Operation: the value that you can use in the Action element to specify the operation on a resource.
  • Access level: the access level of each operation. The levels are read, write, and list.
  • Resource type: the type of the resource on which you can authorize the RAM user or the RAM role to perform the operation. Take note of the following items:
    • The required resource types are displayed in bold characters.
    • If the permissions cannot be granted at the resource level, All Resources is used in the Resource type column of the operation.
  • Condition Key: the condition key that is defined by the cloud service.
  • Associated operation: other operations that the RAM user or the RAM role must have permissions to perform to complete the operation. To complete the operation, the RAM user or the RAM role must have the permissions to perform the associated operations.
OperationAccess levelResource typeCondition keyAssociated operation
hdm:GetMySQLAllSessionAsyncRead
  • All Resources
    *
    none
none

Request parameters

ParameterTypeRequiredDescriptionExample
InstanceIdstringYes

The instance ID.

Note Only ApsaraDB RDS for MySQL, PolarDB for MySQL, and PolarDB-X 2.0 instances are supported.
rm-2ze8g2am97624****
NodeIdstringNo

The node ID.

Note You must specify this parameter for PolarDB for MySQL clusters. If you do not specify a node ID, the session data of the primary node is returned by default.
pi-wz954ryd8f893****
ResultIdstringNo

The ID of the asynchronous request.

Note You can leave this parameter empty when you call the operation to initiate the request for the first time, and use the value of this parameter contained in the response to the first request for subsequent requests.
async__507044db6c4eadfa2dab9b084e80****

Response parameters

ParameterTypeDescriptionExample
object
Codelong

The HTTP status code returned.

200
Messagestring

The returned message.

Note If the request was successful, Successful is returned. If the request failed, an error message such as an error code is returned.
Successful
Dataobject

The data returned.

Failboolean

Indicates whether the asynchronous request failed. Valid values:

  • true
  • false
false
SessionDataobject

The session data.

TotalSessionCountlong

The total number of sessions.

988
ActiveSessionCountlong

The total number of active sessions.

10
MaxActiveTimelong

The maximum execution duration of an active session. Unit: seconds.

6
SessionListobject []

The sessions.

SessionIdlong

The session ID.

14521783
Userstring

The username of the database account.

testUser
Clientstring

The IP address of the client.

47.100.XX.XX
DbNamestring

The database name.

dbTest
Commandstring

The type of the command executed in the session.

Query
Timelong

The execution duration of the session. Unit: seconds.

6
Statestring

The status of the session.

starting
SqlTextstring

The SQL statement executed in the session.

INSERT INTO ...
UserClientAliasstring

The alias of the IP address of the client.

master-shanghai
TrxIdstring

The ID of the transaction to which the session belongs.

754300775132
TrxDurationlong

The duration of the transaction. Unit: seconds.

6
SqlTemplateIdstring

The SQL template ID.

Note This parameter is returned only when you use a PolarDB-X 2.0 instance.
a7cac1a9
UserStatsobject []

The sessions that are counted by database account.

Keystring

The database account.

testUser
TotalCountlong

The total number of sessions within the account.

2
ActiveCountlong

The number of active sessions within the account.

Note If the type of the command executed in the session is Query or Execute and the session in the transaction is not terminated, the session is active.
1
ThreadIdListarray

The IDs of the sessions within the account.

long

The session IDs.

[14525727,14526269]
UserListarray

The database accounts to which the sessions belong.

string

The database account.

['testUser']
ClientStatsobject []

The sessions that are counted by client IP address.

Keystring

The IP address of the client.

47.100.XX.XX
TotalCountlong

The total number of sessions that belong to the client IP address.

2
ActiveCountlong

The number of active sessions that belong to the client IP address.

Note If the type of the command executed in the session is Query or Execute and the session in the transaction is not terminated, the session is active.
1
ThreadIdListarray

The IDs of the sessions that belong to the client IP address.

long

The session IDs.

[14526018,14525956]
UserListarray

The database accounts to which the sessions belong.

string

The database account.

['testUser']
DbStatsobject []

The sessions that are counted by database.

Keystring

The database name.

dbTest
TotalCountlong

The total number of sessions of the database.

2
ActiveCountlong

The number of active sessions of the database.

Note If the type of the command executed in the session is Query or Execute and the session in the transaction is not terminated, the session is active.
1
ThreadIdListarray

The IDs of the sessions of the database.

long

The session IDs.

[14525727,14526269]
UserListarray

The database accounts to which the sessions belong.

string

The database account.

['testUser']
TimeStamplong

The time when the session was queried. This value is a UNIX timestamp representing the number of milliseconds that have elapsed since January 1, 1970, 00:00:00 UTC.

1659581514000020
ResultIdstring

The ID of the asynchronous request.

async__507044db6c4eadfa2dab9b084e80****
IsFinishboolean

Indicates whether the asynchronous request was complete. Valid values:

  • true
  • false
true
Statestring

The state of the asynchronous request. Valid values:

  • RUNNING
  • SUCCESS
  • FAIL
SUCCESS
Completeboolean

Indicates whether the asynchronous request was complete. Valid values:

  • true
  • false
true
Timestamplong

The time when the asynchronous request was made. This value is a UNIX timestamp representing the number of milliseconds that have elapsed since January 1, 1970, 00:00:00 UTC.

1660100753556
RequestIdstring

The request ID.

B6D17591-B48B-4D31-9CD6-9B9796B2****
Successboolean

Indicates whether the request was successful. Valid values:

  • true
  • false
true

Examples

Sample success responses

JSONformat

{
  "Code": 200,
  "Message": "Successful",
  "Data": {
    "Fail": false,
    "SessionData": {
      "TotalSessionCount": 988,
      "ActiveSessionCount": 10,
      "MaxActiveTime": 6,
      "SessionList": [
        {
          "SessionId": 14521783,
          "User": "testUser",
          "Client": "47.100.XX.XX",
          "DbName": "dbTest",
          "Command": "Query",
          "Time": 6,
          "State": "starting",
          "SqlText": "INSERT INTO ...",
          "UserClientAlias": "master-shanghai",
          "TrxId": "754300775132",
          "TrxDuration": 6,
          "SqlTemplateId": "a7cac1a9"
        }
      ],
      "UserStats": [
        {
          "Key": "testUser",
          "TotalCount": 2,
          "ActiveCount": 1,
          "ThreadIdList": [
            0
          ],
          "UserList": [
            "['testUser']"
          ]
        }
      ],
      "ClientStats": [
        {
          "Key": "47.100.XX.XX",
          "TotalCount": 2,
          "ActiveCount": 1,
          "ThreadIdList": [
            0
          ],
          "UserList": [
            "['testUser']"
          ]
        }
      ],
      "DbStats": [
        {
          "Key": "dbTest",
          "TotalCount": 2,
          "ActiveCount": 1,
          "ThreadIdList": [
            0
          ],
          "UserList": [
            "['testUser']"
          ]
        }
      ],
      "TimeStamp": 1659581514000020
    },
    "ResultId": "async__507044db6c4eadfa2dab9b084e80****",
    "IsFinish": true,
    "State": "SUCCESS",
    "Complete": true,
    "Timestamp": 1660100753556
  },
  "RequestId": "B6D17591-B48B-4D31-9CD6-9B9796B2****",
  "Success": true
}

Error codes

HTTP status codeError codeError message
400InvalidParamsThe request parameters are invalid.
403NoPermissionYou are not authorized to do this action.

For a list of error codes, visit the Service error codes.

Change history

Change timeSummary of changesOperation
2023-08-25API Description Update. The Error code has changed. The response structure of the API has changedsee changesets
Change itemChange content
API DescriptionAPI Description Update.
Error CodesThe Error code has changed.
    delete Error Codes: 400
Output ParametersThe response structure of the API has changed.