Call the CreateDashboard API to create a dashboard.
Prerequisites
Simple Log Service is activated.
The Simple Log Service SDK for Python is initialized.
Parameter description
def create_dashboard(self, project, detail):
Request parameters
Name | Type | Required | Description | Example |
project | str | Yes | Name of the project. | ali-test-project |
detail | dict | Yes | A JSON object that contains the configuration information for creating the dashboard. |
|
Description of the detail parameters:
Parameter | Type | Required | Description | Example |
dashboardName | str | Yes | Internal display name of the dashboard. | dashboard-1609294922657-123456 |
displayName | str | Yes | Display name of the dashboard. | test-alert |
description | str | No | Description of the dashboard. | This is a dashboard. |
attribute | dict | No | Attribute values of the dashboard. |
|
charts | list | Yes | A JSON array of charts contained in the dashboard. |
|
Description of the charts array:
Parameter | Type | Required | Description | Example |
title | str | Yes | Title of the chart. | my-chart |
type | str | Yes | Type of the chart. | linepro |
search | dict | Yes | Configuration of the query. |
|
display | dict | Yes | Display configuration of the chart. |
|
action | dict | No | Interaction occurrence configuration of the chart. |
|
Response parameters
For more information, see CreateDashboard.
Sample code
from aliyun.log import LogClient
import time
import os
dashboard_detail = {
"charts": [
{
"display": {
"displayName": "",
"height": 5,
"width": 5,
"xAxis": [
"province"
],
"xPos": 0,
"yAxis": [
"pv"
],
"yPos": 0
},
"search": {
"end": "now",
"logstore": "website_log",
"query": "* | select ip_to_province(remote_addr) as province,count(1) as pv group by province order by pv desc ",
"start": "-86400s",
"topic": ""
},
"title": "map",
"type": "map",
"action": {}
}
],
"dashboardName": 'dashboard_test_' + str(time.time()).replace('.', '-'),
"description": "",
"displayName": "dashboard_test"
}
def main():
# In this example, the AccessKey ID and AccessKey secret are obtained from environment variables.
accessKeyId = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID', '')
accessKey = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET', '')
# The Simple Log Service endpoint.
endpoint = "cn-hangzhou.log.aliyuncs.com"
project = 'ali-test-project'
client = LogClient(endpoint, accessKeyId, accessKey, "")
res = client.create_dashboard(project, dashboard_detail)
res.log_print()
if __name__ == '__main__':
main()
References
For more information about managing dashboard APIs, see the following:
For more code samples, see aliyun-log-python-sdk.