Update a dashboard

Updated at:

You can call the UpdateDashboard method of the Log Service Python SDK to update the charts, layout, and display name of an existing dashboard.

Prerequisites

Make sure that you have completed the following tasks:

Parameters

def update_dashboard(self, project, detail):

Request parameters

Parameter

Type

Required

Description

Example

project

str

Yes

Project name.

ali-test-project

detail

dict

Yes

Dashboard configuration. See the following table for details.

{
    "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_1730181295-123456",
    "description": "",
    "displayName": "dashboard_test"
}

The detail parameter contains the following fields:

Parameter

Type

Required

Description

Example

dashboardName

str

Yes

Unique identifier for the dashboard. This value cannot be changed after the dashboard is created.

dashboard-1609294922657-123456

displayName

str

Yes

Display name of the dashboard, shown in the console.

test-alert

description

str

No

Description of the dashboard.

This is a dashboard.

attribute

dict

No

Dashboard attributes, such as layout type.

{"type": "grid"}

charts

list

Yes

Chart objects in the dashboard. See the following table for the chart object structure.

[
    {
        "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"
    },
    {
        "display": {
            "displayName": "",
            "height": 5,
            "width": 5,
            "xAxis": [
                "province"
            ],
            "xPos": 5,
            "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": "post_map",
        "type": "map"
    }
]

Each chart object in the charts array contains the following parameters:

Parameter

Type

Required

Description

Example

title

str

Yes

Chart title.

my-chart

type

str

Yes

Chart type. Valid values include linepro, map, bar, and pie.

linepro

search

dict

Yes

Query configuration, including the Logstore, query statement, and time range.

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

display

dict

Yes

Display configuration of the chart, including position, dimensions, and axis settings.

{
    "displayName": "",
    "height": 5,
    "width": 5,
    "xAxis": [
        "province"
    ],
    "xPos": 5,
    "yAxis": [
        "pv"
    ],
    "yPos": 0
}

action

dict

No

Interactive events configured for the chart, such as drill-down actions.

{}

Response parameters

For response details, see UpdateDashboard.

Example

from aliyun.log import LogClient
import os

# Define the dashboard configuration with a single map chart.
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_1730181295-123456",
    "description": "",
    "displayName": "dashboard_test"
}


def main():
    # Retrieve 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', '')

    # Specify the Log Service endpoint. Replace with your actual region.
    endpoint = "cn-hangzhou.log.aliyuncs.com"

    # Specify the project that contains the dashboard.
    project = 'ali-test-project'

    # Initialize the client and update the dashboard.
    client = LogClient(endpoint, accessKeyId, accessKey, "")

    res = client.update_dashboard(project, dashboard_detail)
    res.log_print()


if __name__ == '__main__':
    main()

References