你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

Azure 仪表板结构

本文档将使用以下仪表板作为示例,介绍 Azure 仪表板的结构:

Azure 门户中示例仪表板的屏幕截图。

由于共享的 Azure 仪表板是资源,所以此仪表板可以表示为 JSON。 可在 Azure 门户中选择“导出”,然后选择“下载”来下载仪表板的 JSON 表示形式。

以下 JSON 表示上述仪表板。

{
{
  "properties": {
    "lenses": {
      "0": {
        "order": 0,
        "parts": {
          "0": {
            "position": {
              "x": 0,
              "y": 0,
              "colSpan": 3,
              "rowSpan": 2
            },
            "metadata": {
              "inputs": [],
              "type": "Extension/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.",
                    "markdownUri": null
                  }
                }
              }
            }
          },
          "1": {
            "position": {
              "x": 3,
              "y": 0,
              "colSpan": 8,
              "rowSpan": 4
            },
            "metadata": {
              "inputs": [],
              "type": "Extension/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. [Create a Linux virtual machine](https://docs.microsoft.com/azure/virtual-machines/linux/quick-create-portal)\r\n1. [Create a Windows virtual machine](https://docs.microsoft.com/azure/virtual-machines/windows/quick-create-portal)\r\n1. [Create a virtual machine scale set](https://docs.microsoft.com/azure/virtual-machine-scale-sets/quick-create-portal)",
                    "title": "Test VM Dashboard",
                    "subtitle": "Contoso",
                    "markdownUri": null
                  }
                }
              }
            }
          },
          "2": {
            "position": {
              "x": 0,
              "y": 2,
              "colSpan": 3,
              "rowSpan": 2
            },
            "metadata": {
              "inputs": [],
              "type": "Extension/HubsExtension/PartType/VideoPart",
              "settings": {
                "content": {
                  "settings": {
                    "src": "https://www.youtube.com/watch?v=rOiSRkxtTeU",
                    "autoplay": false
                  }
                }
              }
            }
          },
          "3": {
            "position": {
              "x": 0,
              "y": 4,
              "colSpan": 11,
              "rowSpan": 3
            },
            "metadata": {
              "inputs": [
                {
                  "name": "queryInputs",
                  "value": {
                    "timespan": {
                      "duration": "PT1H"
                    },
                    "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SimpleWinVMResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM1",
                    "chartType": 0,
                    "metrics": [
                      {
                        "name": "Percentage CPU",
                        "resourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SimpleWinVMResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM1"
                      }
                    ]
                  }
                }
              ],
              "type": "Extension/Microsoft_Azure_Monitoring/PartType/MetricsChartPart",
              "settings": {}
            }
          },
          "4": {
            "position": {
              "x": 0,
              "y": 7,
              "colSpan": 3,
              "rowSpan": 2
            },
            "metadata": {
              "inputs": [
                {
                  "name": "queryInputs",
                  "value": {
                    "timespan": {
                      "duration": "PT1H"
                    },
                    "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SimpleWinVMResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM1",
                    "chartType": 0,
                    "metrics": [
                      {
                        "name": "Disk Read Operations/Sec",
                        "resourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SimpleWinVMResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM1"
                      },
                      {
                        "name": "Disk Write Operations/Sec",
                        "resourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SimpleWinVMResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM1"
                      }
                    ]
                  }
                }
              ],
              "type": "Extension/Microsoft_Azure_Monitoring/PartType/MetricsChartPart",
              "settings": {}
            }
          },
          "5": {
            "position": {
              "x": 3,
              "y": 7,
              "colSpan": 3,
              "rowSpan": 2
            },
            "metadata": {
              "inputs": [
                {
                  "name": "queryInputs",
                  "value": {
                    "timespan": {
                      "duration": "PT1H"
                    },
                    "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SimpleWinVMResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM1",
                    "chartType": 0,
                    "metrics": [
                      {
                        "name": "Disk Read Bytes",
                        "resourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SimpleWinVMResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM1"
                      },
                      {
                        "name": "Disk Write Bytes",
                        "resourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SimpleWinVMResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM1"
                      }
                    ]
                  }
                }
              ],
              "type": "Extension/Microsoft_Azure_Monitoring/PartType/MetricsChartPart",
              "settings": {}
            }
          },
          "6": {
            "position": {
              "x": 6,
              "y": 7,
              "colSpan": 3,
              "rowSpan": 2
            },
            "metadata": {
              "inputs": [
                {
                  "name": "queryInputs",
                  "value": {
                    "timespan": {
                      "duration": "PT1H"
                    },
                    "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SimpleWinVMResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM1",
                    "chartType": 0,
                    "metrics": [
                      {
                        "name": "Network In Total",
                        "resourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SimpleWinVMResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM1"
                      },
                      {
                        "name": "Network Out Total",
                        "resourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SimpleWinVMResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM1"
                      }
                    ]
                  }
                }
              ],
              "type": "Extension/Microsoft_Azure_Monitoring/PartType/MetricsChartPart",
              "settings": {}
            }
          },
          "7": {
            "position": {
              "x": 9,
              "y": 7,
              "colSpan": 2,
              "rowSpan": 2
            },
            "metadata": {
              "inputs": [
                {
                  "name": "id",
                  "value": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SimpleWinVMResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM1"
                }
              ],
              "type": "Extension/HubsExtension/PartType/ResourcePart",
              "asset": {
                "idInputName": "id",
                "type": "VirtualMachine"
              }
            }
          }
        }
      }
    },
    "metadata": {
      "model": {
        "timeRange": {
          "value": {
            "relative": {
              "duration": 24,
              "timeUnit": 1
            }
          },
          "type": "MsPortalFx.Composition.Configuration.ValueTypes.TimeRange"
        }
      }
    }
  },
  "name": "Simple VM Dashboard",
  "type": "Microsoft.Portal/dashboards",
  "location": "INSERT LOCATION",
  "tags": {
    "hidden-title": "Simple VM Dashboard"
  },
  "apiVersion": "2015-08-01-preview"
}

常见资源属性

现在分别介绍 JSON 的各个相关部分。 公共资源属性显示在上述示例的结尾附近。 这些属性跨所有 Azure 资源类型共享。 它们与仪表板的内容没有特别的关系。

ID

ID 表示仪表板的 Azure 资源 ID,遵循 Azure 资源命名约定。 门户创建仪表板时,通常会选择 GUID 形式的 ID;如果以编程方式创建仪表板,则可使用任何有效的名称。

从 Azure 门户导出仪表板时,不包括 id 字段。 如果通过导入包含 id 字段的 JSON 文件创建新的仪表板,则将忽略该值,并将为每个新仪表板分配新的 ID 值。

名称

Azure 门户用于仪表板的资源名称。

类型

所有仪表板的类型都是 Microsoft.Portal/dashboards

位置

与其他资源不同,仪表板没有运行时组件。 对于仪表板,`location`` 指示用于存储仪表板 JSON 表示形式的主地理位置。 该值应为可使用订阅资源上的位置 API 提取的位置代码之一。

Tags

标记是 Azure 资源的一项常见功能,可使用它按任意名称-值对来整理资源。 仪表板有一个名为 hidden-title 的特殊标记。 如果仪表板已填充此属性,则该值将用作门户中仪表板的显示名称。 通过标记可重命名仪表板的显示名称

属性

属性对象包含两个属性:lensesmetadatalenses 属性包含仪表板上的磁贴的相关信息。 metadata 属性保留用于将来可能出现的功能。

可重用功能区

lenses 属性包含仪表板。 此示例中的可重用功能区对象包含称为“0”的单个属性。 可重用功能区是一个分组概念,目前未实现。 现在,所有仪表板在 lens 对象上具有这一个“0”属性。

组成部分

“0”下面的对象包含两个属性:orderparts。 目前,order 始终设置为 0。 parts 属性包含一个对象,该对象定义仪表板上的各个部件(也称为“磁贴”)。

parts 对象对于每个部件都包含一个属性,其中属性名称为一个数字。 此数字并不重要。

每个单独的部件对象都包含 positionmetadata

位置

position 属性包含以 xyrowSpancolSpan 表示的部件大小和位置信息。 值以网格单位表示。 仪表板处于自定义模式时,网格单位可见,如下所示。

显示 Azure 门户中仪表板网格单元的屏幕截图。

例如,如果希望磁贴具有两个网格单位的宽度、一个网格单元的高度,且位于仪表板左上角,则位置对象如下所示:

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

元数据

每个部件都有一个 metadata 属性。 对象只有一个必需属性:type。 此字符串告知门户要显示的磁贴类型。 示例仪表板使用这些类型的磁贴:

  1. Extension/Microsoft_Azure_Monitoring/PartType/MetricsChartPart – 用于显示监视度量值
  2. Extension[azure]/HubsExtension/PartType/MarkdownPart - 用于显示自定义 markdown 内容(例如文本或图像),这些内容对列表和链接等信息使用基本格式。
  3. Extension[azure]/HubsExtension/PartType/VideoPart - 用于显示来自 YouTube 和 Channel9 的视频,以及使用 HTML 视频标记的任何其他类型的视频。

每个部件类型都有自己的配置选项。 可能的配置属性有 inputssettingsasset

输入

输入对象通常包含将磁贴绑定到资源实例的信息。

示例中的每个 MetricsChartPart 都有一个表示要绑定到的资源的输入(它表示 VM 的 Azure 资源 ID),还包含所显示的数据的相关信息。 例如,有磁贴的 inputs 对象,它显示“网络总流入量”和“网络总流出量”指标。

"inputs":
[
  {
    "name": "queryInputs",
    "value": {
      "timespan": {
        "duration": "PT1H"
      },
      "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SimpleWinVMResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM1",
      "chartType": 0,
      "metrics": [
        {
          "name": "Network In Total",
          "resourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SimpleWinVMResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM1"
        },
        {
          "name": "Network Out Total",
          "resourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SimpleWinVMResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM1"
        }
      ]
    }
  }
]

设置

设置对象包含部件的可配置元素。 在示例仪表板中,Markdown 部件使用设置来存储自定义 Markdown 内容以及可配置的标题和副标题。

"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. [Create a Linux virtual machine](https://docs.microsoft.com/azure/virtual-machines/linux/quick-create-portal)\r\n1. [Create a Windows virtual machine](https://docs.microsoft.com/azure/virtual-machines/windows/quick-create-portal)\r\n1. [Create a virtual machine scale set](https://docs.microsoft.com/azure/virtual-machine-scale-sets/quick-create-portal)",
      "title": "Test VM Dashboard",
      "subtitle": "Contoso"
    }
  }
}

同样,视频磁贴也有自己的设置,包含指向要播放的视频的指针、自动播放设置,以及可选的标题信息。


"settings": {
  "content": {
    "settings": {
      "src": "https://www.youtube.com/watch?v=rOiSRkxtTeU",
      "autoplay": false
    }
  }
}

资产

绑定到第一类可管理门户对象(称为“资产”)的磁贴通过 asset 对象表示此关系。 在示例仪表板中,虚拟机磁贴包含此资产说明。 idInputName 属性告知门户:ID 输入包含资产的唯一标识符(在此示例中为资源 ID)。 大多数 Azure 资源类型在门户中定义资产。

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

后续步骤