This topic describes how to use Database Autonomy Service (DAS) SDK for Python to call the GetInstanceInspections operation to query the result of an inspection that is performed on a database instance by using the inspection and scoring feature.
View the API documentation
Before you call the GetInstanceInspections operation, we recommend that you read the documentation about the API operation to learn about the parameters and permissions that are required to call the API operation. For more information, see List of operations by function.
Create a RAM user and grant permissions to the RAM user
If you have created a Resource Access Management (RAM) user and granted permissions to the RAM user, skip this step.
Create a RAM user.
Log on to the RAM console, go to the Users page, and then click Create User.
Set the Logon Name parameter to das-openapi-operator and select Using permanent AccessKey to access for the Access Mode parameter.
Click OK. After the RAM user is created, save the AccessKey ID and AccessKey secret of the RAM user.
Grant permissions to the RAM user.
On the Users page, find the RAM user and click Add Permissions in the Actions column.
Enter
DAS
in the search box and select the AliyunHDMReadOnlyAccess policy.NoteThe AliyunHDMReadOnlyAccess policy contains the read permissions on DAS. You can also select the AliyunHDMFullAccess policy that contains the read and write permissions on DAS or create custom policies based on your business requirements. For more information, see Create custom policies.
Click Grant permissions.
Call the API
This section describes how to use DAS SDK for Python to call API operations. You can use SDKs for other programming languages in a similar way. For more information, see DAS SDK.
Install Python
Download and install Python 3. If you have installed Python, you can run the python --version
command to view the Python version.
Configure environment variables
This section describes how to configure the ALIBABA_CLOUD_ACCESS_KEY_ID
and ALIBABA_CLOUD_ACCESS_KEY_SECRET
environment variables.
If you use a Linux or macOS operating system, replace
<access_key_id>
and<access_key_secret>
in the following commands with your AccessKey ID and AccessKey secret. Then, run the commands in sequence on your device.export ALIBABA_CLOUD_ACCESS_KEY_ID=<ACCESS_KEY_ID> export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<ACCESS_KEY_SECRET>
If you use a Windows operating system, create a file to add the
ALIBABA_CLOUD_ACCESS_KEY_ID
andALIBABA_CLOUD_ACCESS_KEY_SECRET
environment variables and specify your AccessKey ID and AccessKey secret by using the environment variables. Then, restart the Windows operating system.
Install dependencies
Run the following command on your device to install dependencies:
pip install alibabacloud_das20200116==2.4.2
Download the sample code
Go to the debugging page of the GetInstanceInspections operation in OpenAPI Explorer.
On the Parameters tab, configure the request parameters that are described in the following table. In this example, the operation is called on an ApsaraDB RDS for MySQL instance.
Parameter
Example
Engine
MySQL
StartTime
1718776527000
ImportantThe beginning of the time range to query. Set this parameter to a UNIX timestamp representing the number of milliseconds that have elapsed since January 1, 1970, 00:00:00 UTC. Set this parameter to the actual value.
EndTime
1718776827000
ImportantThe end of the time range to query. Set this parameter to a UNIX timestamp representing the number of milliseconds that have elapsed since January 1, 1970, 00:00:00 UTC. Set this parameter to the actual value.
This operation is called to query the inspection and scoring tasks that were complete within the specified period of time. If no inspection and scoring tasks were complete within the specified period of time, you can manually initiate inspection and scoring on an instance. Then, you can call this operation after the inspection and scoring task is complete. For more information about how to manually initiate inspection and scoring, see Inspection and scoring.
InstanceArea
RDS
PageNo
1
PageSize
10
On the SDK Sample Code tab on the right, select Python for the Languages parameter and click Download Project to download the sample code package.
Decompress the package on your device and go to the alibabacloud_sample directory.
Run the sample code
Run the following command:
python sample.py
Sample response:
{
"headers": {
"date": "Wed, 19 Jun 2024 06:24:10 GMT",
"content-type": "application/json;charset=utf-8",
"content-length": "1428",
"connection": "keep-alive",
"keep-alive": "timeout=25",
"vary": "Accept-Encoding",
"access-control-allow-origin": "*",
"access-control-expose-headers": "*",
"x-acs-request-id": "B576DACC-D08A-5058-8843-E613CBF474CF",
"x-acs-trace-id": "2fb5b5b76565ce67233288b9369f6d96",
"etag": "1rcNeDQg43APurk7PohefuQ8"
},
"statusCode": 200,
"body": {
"Code": 200,
"Data": {
"List": [
{
"AutoFunction": {
"AutoIndex": 1,
"AutoLimitedSql": 0,
"AutoResourceOptimize": 2,
"AutoScale": 0,
"EventSubscription": 0
},
"Data": {
"hasDeadLock": false,
"slowSqlCount": 0,
"exceptionTableMap": {},
"spaceItem": {
"valid": true,
"current": 0.16416015625,
"avg": 0.16416015625,
"min": 0.16416015625,
"max": 0.16416015625
},
"maxIops": 3100,
"bigTransactionCount": 0,
"cpu": 2,
"isRds": true,
"storage": 20,
"lastHourRate": 0.0,
"lastDayCount": 0,
"lastHourCount": 0,
"slowSqlList": [],
"lastDayRate": 0.0,
"activeSessions": [],
"enable": false,
"bigTransactionList": [],
"bigSessionList": [
{
"User": "system user",
"Command": "Query",
"State": "Replica has read all relay log; waiting for more updates",
"active": false,
"Host": "",
"Time": 24,
"Id": 61,
"Info": "",
"db": ""
}
],
"tableStats": [],
"bigSessionCount": 1,
"spaceUsage": 0.16416015625,
"availableDays": 76
},
"EnableDasPro": 0,
"EndTime": 1718726400000,
"GmtCreate": 1718776692000,
"Instance": {
"AccountId": "1648821913965368",
"Category": "standard",
"Cpu": "2",
"Engine": "MySQL",
"EngineVersion": "8.0",
"InstanceArea": "RDS",
"InstanceClass": "mysql.n2m.medium.2c",
"InstanceId": "rm-bp1s6jtqtr41m****",
"Memory": 4096,
"NetworkType": "VPC",
"Region": "cn-hangzhou",
"Storage": 20,
"Uuid": "hdm_6d00b701adcb484d5fa4d2800dc0****",
"VpcId": "vpc-bp1ov7as4yvz4kxei****"
},
"Score": 100,
"StartTime": 1718640000000,
"State": 2,
"TaskType": 1
}
],
"PageNo": 1,
"PageSize": 10,
"Total": 1
},
"Message": "Successful",
"RequestId": "B576DACC-D08A-5058-8843-E613CBF474CF",
"Success": true
}
}