您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

Azure 仪表板结构The structure of Azure Dashboards

本文档将使用以下仪表板作为示例,介绍 Azure 仪表板的结构:This document walks through the structure of an Azure dashboard, using the following dashboard as an example:

示例仪表板

由于共享的 Azure 仪表板是资源,所以此仪表板可以表示为 JSON。Since shared Azure dashboards are resources, this dashboard can be represented as JSON. 以下 JSON 表示上面构思的仪表板。The following JSON represents the dashboard visualized above.


{
    "properties": {
        "lenses": {
            "0": {
                "order": 0,
                "parts": {
                    "0": {
                        "position": {
                            "x": 0,
                            "y": 0,
                            "rowSpan": 2,
                            "colSpan": 3
                        },
                        "metadata": {
                            "inputs": [],
                            "type": "Extension[azure]/HubsExtension/PartType/MarkdownPart",
                            "settings": {
                                "content": {
                                    "settings": {
                                        "content": "## Azure Virtual Machines Overview\r\nNew team members should watch this video to get familiar with Azure Virtual Machines.",
                                        "title": "",
                                        "subtitle": ""
                                    }
                                }
                            }
                        }
                    },
                    "1": {
                        "position": {
                            "x": 3,
                            "y": 0,
                            "rowSpan": 4,
                            "colSpan": 8
                        },
                        "metadata": {
                            "inputs": [],
                            "type": "Extension[azure]/HubsExtension/PartType/MarkdownPart",
                            "settings": {
                                "content": {
                                    "settings": {
                                        "content": "This is the team dashboard for the test VM we use on our team. Here are some useful links:\r\n\r\n1. [Getting started](https://www.contoso.com/tsgs)\r\n1. [Troubleshooting guide](https://www.contoso.com/tsgs)\r\n1. [Architecture docs](https://www.contoso.com/tsgs)",
                                        "title": "Test VM Dashboard",
                                        "subtitle": "Contoso"
                                    }
                                }
                            }
                        }
                    },
                    "2": {
                        "position": {
                            "x": 0,
                            "y": 2,
                            "rowSpan": 2,
                            "colSpan": 3
                        },
                        "metadata": {
                            "inputs": [],
                            "type": "Extension[azure]/HubsExtension/PartType/VideoPart",
                            "settings": {
                                "content": {
                                    "settings": {
                                        "title": "",
                                        "subtitle": "",
                                        "src": "https://www.youtube.com/watch?v=YcylDIiKaSU&list=PLLasX02E8BPCsnETz0XAMfpLR1LIBqpgs&index=4",
                                        "autoplay": false
                                    }
                                }
                            }
                        }
                    },
                    "3": {
                        "position": {
                            "x": 0,
                            "y": 4,
                            "rowSpan": 3,
                            "colSpan": 11
                        },
                        "metadata": {
                            "inputs": [
                                {
                                    "name": "queryInputs",
                                    "value": {
                                        "timespan": {
                                            "duration": "PT1H",
                                            "start": null,
                                            "end": null
                                        },
                                        "id": "/subscriptions/6531c8c8-df32-4254-d717-b6e983273e5d/resourceGroups/contoso/providers/Microsoft.Compute/virtualMachines/myVM1",
                                        "chartType": 0,
                                        "metrics": [
                                            {
                                                "name": "Percentage CPU",
                                                "resourceId": "/subscriptions/6531c8c8-df32-4254-d717-b6e983273e5d/resourceGroups/contoso/providers/Microsoft.Compute/virtualMachines/myVM1"
                                            }
                                        ]
                                    }
                                }
                            ],
                            "type": "Extension/Microsoft_Azure_Monitoring/PartType/MetricsChartPart",
                            "settings": {}
                        }
                    },
                    "4": {
                        "position": {
                            "x": 0,
                            "y": 7,
                            "rowSpan": 2,
                            "colSpan": 3
                        },
                        "metadata": {
                            "inputs": [
                                {
                                    "name": "queryInputs",
                                    "value": {
                                        "timespan": {
                                            "duration": "PT1H",
                                            "start": null,
                                            "end": null
                                        },
                                        "id": "/subscriptions/6531c8c8-df32-4254-d717-b6e983273e5d/resourceGroups/contoso/providers/Microsoft.Compute/virtualMachines/myVM1",
                                        "chartType": 0,
                                        "metrics": [
                                            {
                                                "name": "Disk Read Operations/Sec",
                                                "resourceId": "/subscriptions/6531c8c8-df32-4254-d717-b6e983273e5d/resourceGroups/contoso/providers/Microsoft.Compute/virtualMachines/myVM1"
                                            },
                                            {
                                                "name": "Disk Write Operations/Sec",
                                                "resourceId": "/subscriptions/6531c8c8-df32-4254-d717-b6e983273e5d/resourceGroups/contoso/providers/Microsoft.Compute/virtualMachines/myVM1"
                                            }
                                        ]
                                    }
                                }
                            ],
                            "type": "Extension/Microsoft_Azure_Monitoring/PartType/MetricsChartPart",
                            "settings": {}
                        }
                    },
                    "5": {
                        "position": {
                            "x": 3,
                            "y": 7,
                            "rowSpan": 2,
                            "colSpan": 3
                        },
                        "metadata": {
                            "inputs": [
                                {
                                    "name": "queryInputs",
                                    "value": {
                                        "timespan": {
                                            "duration": "PT1H",
                                            "start": null,
                                            "end": null
                                        },
                                        "id": "/subscriptions/6531c8c8-df32-4254-d717-b6e983273e5d/resourceGroups/contoso/providers/Microsoft.Compute/virtualMachines/myVM1",
                                        "chartType": 0,
                                        "metrics": [
                                            {
                                                "name": "Disk Read Bytes",
                                                "resourceId": "/subscriptions/6531c8c8-df32-4254-d717-b6e983273e5d/resourceGroups/contoso/providers/Microsoft.Compute/virtualMachines/myVM1"
                                            },
                                            {
                                                "name": "Disk Write Bytes",
                                                "resourceId": "/subscriptions/6531c8c8-df32-4254-d717-b6e983273e5d/resourceGroups/contoso/providers/Microsoft.Compute/virtualMachines/myVM1"
                                            }
                                        ]
                                    }
                                }
                            ],
                            "type": "Extension/Microsoft_Azure_Monitoring/PartType/MetricsChartPart",
                            "settings": {}
                        }
                    },
                    "6": {
                        "position": {
                            "x": 6,
                            "y": 7,
                            "rowSpan": 2,
                            "colSpan": 3
                        },
                        "metadata": {
                            "inputs": [
                                {
                                    "name": "queryInputs",
                                    "value": {
                                        "timespan": {
                                            "duration": "PT1H",
                                            "start": null,
                                            "end": null
                                        },
                                        "id": "/subscriptions/6531c8c8-df32-4254-d717-b6e983273e5d/resourceGroups/contoso/providers/Microsoft.Compute/virtualMachines/myVM1",
                                        "chartType": 0,
                                        "metrics": [
                                            {
                                                "name": "Network In",
                                                "resourceId": "/subscriptions/6531c8c8-df32-4254-d717-b6e983273e5d/resourceGroups/contoso/providers/Microsoft.Compute/virtualMachines/myVM1"
                                            },
                                            {
                                                "name": "Network Out",
                                                "resourceId": "/subscriptions/6531c8c8-df32-4254-d717-b6e983273e5d/resourceGroups/contoso/providers/Microsoft.Compute/virtualMachines/myVM1"
                                            }
                                        ]
                                    }
                                }
                            ],
                            "type": "Extension/Microsoft_Azure_Monitoring/PartType/MetricsChartPart",
                            "settings": {}
                        }
                    },
                    "7": {
                        "position": {
                            "x": 9,
                            "y": 7,
                            "rowSpan": 2,
                            "colSpan": 2
                        },
                        "metadata": {
                            "inputs": [
                                {
                                    "name": "id",
                                    "value": "/subscriptions/6531c8c8-df32-4254-d717-b6e983273e5d/resourceGroups/contoso/providers/Microsoft.Compute/virtualMachines/myVM1"
                                }
                            ],
                            "type": "Extension/Microsoft_Azure_Compute/PartType/VirtualMachinePart",
                            "asset": {
                                "idInputName": "id",
                                "type": "VirtualMachine"
                            },
                            "defaultMenuItemId": "overview"
                        }
                    }
                }
            }
        },
        "metadata": {
            "model": {
                "timeRange": {
                    "value": {
                        "relative": {
                            "duration": 24,
                            "timeUnit": 1
                        }
                    },
                    "type": "MsPortalFx.Composition.Configuration.ValueTypes.TimeRange"
                }
            }
        }
    },
    "id": "/subscriptions/6531c8c8-df32-4254-d717-b6e983273e5d/resourceGroups/dashboards/providers/Microsoft.Portal/dashboards/aa9786ae-e159-483f-b05f-1f7f767741a9",
    "name": "aa9786ae-e159-483f-b05f-1f7f767741a9",
    "type": "Microsoft.Portal/dashboards",
    "location": "eastasia",
    "tags": {
        "hidden-title": "Created via API"
    }
}

常见资源属性Common resource properties

现在分别介绍 JSON 的各个相关部分。Let’s break down the relevant sections of the JSON. 顶级属性,即 id、名称、类型、位置和标记属性是所有 Azure 资源类型所共有的属性 。The top-level properties, id, name, type, location, and tags properties are shared across all Azure resource types. 也就是说,它们与仪表板内容没有太大关系。That is, they don’t have much to do with the dashboard’s content.

ID 属性The ID property

Azure 资源 ID,遵循 azure 资源的命名约定The Azure resource ID, subject to the naming conventions of Azure resources. 当门户创建仪表板时,它通常选择 guid 形式的 ID,但当你以编程方式创建仪表板时,可以随意使用任何有效名称。When the portal creates a dashboard it generally chooses an ID in the form of a guid, but you are free to use any valid name when you create them programmatically.

“名称”属性The name property

名称是资源 ID 中不包含订阅、资源类型或资源组信息的那部分。The name is the segment of the resource ID that does not include the subscription, resource type, or resource group information. 实质上,它是资源 ID 的最后一段。Essentially, it is the last segment of the resource ID.

“类型”属性The type property

所有仪表板均属于 Microsoft.Portal/dashboards 类型 。All dashboards are of type Microsoft.Portal/dashboards.

“位置”属性The location property

与其他资源不同,仪表板没有运行时组件。Unlike other resources, dashboards don’t have a runtime component. 对于仪表板,location 指示用于存储仪表板 JSON 表示形式的主地理位置。For dashboards, the location indicates the primary geographic location that stores the dashboard’s JSON representation. 该值应为可使用订阅资源上的位置 API 提取的位置代码之一。The value should be one of the location codes that can be fetched using the locations API on the subscriptions resource.

“标记”属性The tags property

标记是 Azure 资源的一项常见功能,可使用它按任意名称-值对来整理资源。Tags are a common feature of Azure resources that let you organize your resource by arbitrary name value pairs. 对于仪表板,有一个名为“hidden-title”的特殊标记 。For dashboards, there is one special tag called hidden-title. 如果仪表板已填充此属性,则它将用作门户中仪表板的显示名称。If your dashboard has this property populated, then it is used as the display name for your dashboard in the portal. Azure 资源 Id 不能重命名,但标记可以。Azure resource Ids cannot be renamed, but tags can. 通过标记可重命名仪表板的显示名称。This tag gives you a way to have a renamable display name for your dashboard.

"tags": { "hidden-title": "Created via API" }

属性对象The properties object

属性对象包含两个属性:可重用功能区和元数据 。The properties object contains two properties, lenses and metadata. “可重用功能区”属性包含有关仪表板上的磁贴的信息 。The lenses property contains information about the tiles on the dashboard. “元数据”属性用于将来可能会出现的功能 。The metadata property is there for potential future features.

“可重用功能区”属性The lenses property

“可重用功能区”属性包含仪表板 。The lenses property contains the dashboard. 请注意,此示例中的可重用功能区对象包含名为“0”的单个属性。Note that the lenses object in this example contains a single property called “0”. 可重用功能区是一个分组概念,当前未在仪表板中实现。Lenses are a grouping concept that is not currently implemented in dashboards. 现在,所有仪表板在可重用功能区对象上具有此单个属性,即“0”。For now, all of your dashboards have this single property on the lens object, again, called “0”.

可重用功能区对象The lens object

"0" 下的对象包含两个属性: " 顺序 " 和 " 部件"。The object underneath the “0” contains two properties, order and parts. 在当前版本的仪表板中,顺序始终为 0 。In the current version of dashboards, order is always 0. parts 属性包含一个对象,该对象定义仪表板上的各个部件(也称为“磁贴”)。The parts property contains an object that defines the individual parts (also referred to as tiles) on the dashboard.

部件对象包含每个部件的一个属性,其中属性名称为一个数字 。The parts object contains a property for each part, where the name of the property is a number. 此数字并不重要。This number is not significant.

部件对象The part object

每个部件对象具有位置和元数据 。Each individual part object has a position, and metadata.

位置对象The position object

“位置”属性包含以 x、y、rowSpan 和 colSpan 表示的部件大小和位置信息 。The position property contains the size and location information for the part expressed as x, y, rowSpan, and colSpan. 值以网格单位表示。The values are in terms of grid units. 仪表板处于自定义模式时,网格单位可见,如下所示。These grid units are visible when the dashboard is in the customize mode as shown here. 如果希望磁贴具有两个网格单位的宽度、一个网格单元的高度,且位于仪表板左上角,则位置对象如下所示:If you want a tile to have a width of two grid units, a height of one grid unit, and a location in the top left corner of the dashboard then the position object looks like this:

location: { x: 0, y: 0, rowSpan: 2, colSpan: 1 }

显示网格特写的屏幕截图,其中突出显示了一个正方形网格单元。

元数据对象The metadata object

每个部件都具有一个元数据属性,一个对象仅有一个必需的属性,名为“类型” 。Each part has a metadata property, an object has only one required property called type. 此字符串告知门户要显示的磁贴。This string tells the portal which tile to show. 示例仪表板使用这些类型的磁贴:Our example dashboard uses these types of tiles:

  1. Extension/Microsoft_Azure_Monitoring/PartType/MetricsChartPart – 用于显示监视度量值Extension/Microsoft_Azure_Monitoring/PartType/MetricsChartPart – Used to show monitoring metrics
  2. Extension[azure]/HubsExtension/PartType/MarkdownPart – 用于显示带列表、链接等基本格式的文本或图像。Extension[azure]/HubsExtension/PartType/MarkdownPart – Used to show with text or images with basic formatting for lists, links, etc.
  3. Extension[azure]/HubsExtension/PartType/VideoPart – 用于显示来自 YouTube、Channel9 的视频,以及使用 HTML 视频标记的任何其他类型的视频。Extension[azure]/HubsExtension/PartType/VideoPart – Used to show videos from YouTube, Channel9, and any other type of video that works in an HTML video tag.
  4. Extension/Microsoft_Azure_Compute/PartType/VirtualMachinePart – 用于显示 Azure 虚拟机的名称和状态。Extension/Microsoft_Azure_Compute/PartType/VirtualMachinePart – Used to show the name and status of an Azure virtual machine.

所有部件类型都有其自己的配置。Each type of part has its own configuration. 可能的配置属性有“输入”、“设置”和“资产” 。The possible configuration properties are called inputs, settings, and asset.

“输入”对象The inputs object

输入对象通常包含将磁贴绑定到资源实例的信息。The inputs object generally contains information that binds a tile to a resource instance. 示例仪表板中的虚拟机部件包含使用 Azure 资源 ID 表达绑定的单个输入。The virtual machine part in our sample dashboard contains a single input that uses the Azure resource ID to express the binding. 在所有 Azure 资源中,此资源 ID 格式是统一的。This resource ID format is consistent across all Azure resources.

"inputs":
[
    {
        "name": "id",
        "value": "/subscriptions/6531c8c8-df32-4254-d717-b6e983273e5d/resourceGroups/contoso/providers/Microsoft.Compute/virtualMachines/myVM1"
    }
]

度量值图表部件含有表示要绑定到的资源的单个输入以及有关显示的度量值的信息。The metrics chart part has a single input that expresses the resource to bind to, as well as information about the metric(s) being displayed. 以下是显示 Network In 和 Network Out 度量值的磁贴的输入。Here is the input for the tile that’s showing the Network In and Network Out metrics.

“inputs”:
[
    {
        "name": "queryInputs",
        "value": 
        {
            "timespan": 
            {
                "duration": "PT1H",
                "start": null,
                "end": null
           },
            "id": "/subscriptions/6531c8c8-df32-4254-d717-b6e983273e5d/resourceGroups/contoso/providers/Microsoft.Compute/virtualMachines/myVM1",
            "chartType": 0,
            "metrics": 
            [
                {
                    "name": "Network In",
                    "resourceId": "/subscriptions/6531c8c8-df32-4254-d717-b6e983273e5d/resourceGroups/contoso/providers/Microsoft.Compute/virtualMachines/myVM1"
                },
                {
                    "name": "Network Out",
                    "resourceId": "/subscriptions/6531c8c8-df32-4254-d717-b6e983273e5d/resourceGroups/contoso/providers/Microsoft.Compute/virtualMachines/myVM1"
                }
            ]
        }
    }
]

设置对象The settings object

设置对象包含部件的可配置元素。The settings object contains the configurable elements of a part. 在示例仪表板中,Markdown 部件使用设置来存储自定义 Markdown 内容和可配置的标题、副标题。In our sample dashboard, the Markdown part uses settings to store the custom markdown content as well as a configurable title and subtitle.

"settings": 
{
    "content": 
    {
        "settings": 
        {
            "content": "This is the team dashboard for the test VM we use on our team. Here are some useful links:\r\n\r\n1. [Getting started](https://www.contoso.com/tsgs)\r\n1. [Troubleshooting guide](https://www.contoso.com/tsgs)\r\n1. [Architecture docs](https://www.contoso.com/tsgs)",
            "title": "Test VM Dashboard",
            "subtitle": "Contoso"
        }
    }
}

同样,视频磁贴也有自己的设置,包含指向要播放的视频的指针、自动播放设置,以及可选的标题信息。Similarly, the video tile has its own settings that contain a pointer to the video to play, an autoplay setting, and optional title information.

"settings": 
{
   "content": 
    {
        "settings": 
        {
            "title": "",
            "subtitle": "",
            "src": "https://www.youtube.com/watch?v=YcylDIiKaSU&list=PLLasX02E8BPCsnETz0XAMfpLR1LIBqpgs&index=4",
            "autoplay": false
        }
    }
}

资产对象The asset object

绑定到第一类可管理门户对象(称为“资产”)的磁贴通过资产对象表示此关系。Tiles that are bound to first class manageable portal objects (called assets) have this relationship expressed via the asset object. 在示例仪表板中,虚拟机磁贴包含此资产说明。In our example dashboard, the virtual machine tile contains this asset description. idInputName 属性告知门户:ID 输入包含资产的唯一标识符(在此示例中为资源 ID) 。The idInputName property tells the portal that the ID input contains the unique identifier for the asset, in this case the resource ID. 大多数 Azure 资源类型在门户中定义资产。Most Azure resource types have assets defined in the portal.

"asset": { "idInputName": "id", "type": "VirtualMachine" }