Create a dashboard
You can call the CreateDashboard operation to create a dashboard in a specified project.
Prerequisites
You have completed the following operations:
Parameters
def create_dashboard(self, project, detail):
Request parameters
|
Parameter |
Type |
Required |
Description |
Example |
|
project |
str |
Yes |
The name of the project. |
ali-test-project |
|
detail |
dict |
Yes |
The JSON object that contains the dashboard configuration. |
|
The following table describes the parameters in the detail object.
|
Parameter |
Type |
Required |
Description |
Example |
|
dashboardName |
str |
Yes |
The unique name of the dashboard. |
dashboard-1609294922657-123456 |
|
displayName |
str |
Yes |
The display name of the dashboard. |
test-alert |
|
description |
str |
No |
The description of the dashboard. |
A sample dashboard. |
|
attribute |
dict |
No |
The attributes of the dashboard. |
|
|
charts |
list |
Yes |
A JSON array of charts in the dashboard. |
|
The following table describes the elements in each charts entry.
|
Parameter |
Type |
Required |
Description |
Example |
|
title |
str |
Yes |
The title of the chart. |
my-chart |
|
type |
str |
Yes |
The type of the chart. |
linepro |
|
search |
dict |
Yes |
The query configuration. |
|
|
display |
dict |
Yes |
The display configuration of the chart. |
|
|
action |
dict |
No |
The interaction events for the chart. |
|
Response parameters
For more information about the response parameters, see CreateDashboard.
Examples
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():
# Obtain the AccessKey ID and AccessKey Secret from environment variables.
accessKeyId = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID', '')
accessKey = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET', '')
# The endpoint of Log Service.
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
-
You can call the following API operations to manage dashboards:
-
For more sample code, see Aliyun Log Python SDK on GitHub.