本页面介绍如何使用 Cloud Monitoring API 创建信息中心。对于每个示例,显示 JSON 格式的信息中心定义和相应的信息中心。
Cloud Monitoring 还在 GitHub 上提供了一组精选的信息中心定义。您可以在 Google Cloud 项目中将这些定义安装为自定义信息中心。如需了解此代码库以及如何安装这些信息中心,请参阅安装示例信息中心。
何时使用 API
Cloud Monitoring API 为您提供了一种同时管理多个信息中心的方法。虽然您可以使用 Google Cloud 控制台管理信息中心,但您可能会发现使用 API 批量管理自定义信息中心会更轻松。
如果您想将空白占位符窗口微件添加到信息中心,也需要使用 API。
将 MQL 或 PromQL 与 API 搭配使用
您可以使用 dashboards.create
方法创建信息中心。您向 API 方法传递一个 Dashboard
对象,其中包含与信息中心显示的每个微件对应的条目。
当某个 widget 显示时间序列数据时(例如图表 widget),其在 Dashboard
对象中的条目会包含一个 TimeSeriesQuery
对象。此对象描述了要绘制的时间序列数据,您可以使用 Monitoring 过滤条件、MQL 查询或 PromQL 查询指定这些数据:
如需使用 Monitoring 过滤条件,请填写
timeSeriesField
字段。本页面上的示例使用 Cloud Monitoring 过滤条件。如需使用 MQL 查询,请填写
timeSeriesQueryLanguage
字段。 如需了解详情,请参阅构建图表。如需使用 PromQL 查询,请填写
prometheusQuery
字段。 如需了解一般信息,请参阅 Cloud Monitoring 中的 PromQL。
信息中心布局
本部分包含有关可用的不同信息中心布局的信息。
GridLayout
布局的信息中心
此信息中心会显示 GridLayout
布局,其中有三个微件。
{
"displayName": "Grid Layout Example",
"gridLayout": {
"columns": "2",
"widgets": [
{
"title": "Widget 1",
"xyChart": {
"dataSets": {
"timeSeriesQuery": {
"timeSeriesFilter": {
"filter": "metric.type=\"agent.googleapis.com/nginx/connections/accepted_count\"",
"aggregation": {
"perSeriesAligner": "ALIGN_RATE"
}
},
"unitOverride": "1"
},
"plotType": "LINE"
},
"timeshiftDuration": "0s",
"yAxis": {
"label": "y1Axis",
"scale": "LINEAR"
}
}
},
{
"text": {
"content": "Widget 2"
}
},
{
"title": "Widget 3",
"xyChart": {
"dataSets": {
"timeSeriesQuery": {
"timeSeriesFilter": {
"filter": "metric.type=\"agent.googleapis.com/nginx/connections/accepted_count\"",
"aggregation": {
"perSeriesAligner": "ALIGN_RATE"
}
},
"unitOverride": "1"
},
"plotType": "STACKED_BAR"
},
"timeshiftDuration": "0s",
"yAxis": {
"label": "y1Axis",
"scale": "LINEAR"
}
}
}
]
}
}
此信息中心类似于以下示例:
MosaicLayout
布局的信息中心
此信息中心会显示包含两个微件的 MosaicLayout
。
{
"displayName": "Mosaic Layout Example",
"mosaicLayout": {
"columns": 12,
"tiles": [
{
"xPos": 2,
"yPos": 2,
"width": 7,
"height": 2,
"widget": {
"title": "CPU utilization in us-central1-a",
"scorecard": {
"timeSeriesQuery": {
"timeSeriesFilter": {
"filter": "metric.type=\"compute.googleapis.com/instance/cpu/utilization\" resource.type=\"gce_instance\" resource.label.zone=\"us-central1-a\"",
"aggregation": {
"perSeriesAligner": "ALIGN_MEAN",
"crossSeriesReducer": "REDUCE_MAX"
}
},
"unitOverride": "1"
},
"gaugeView": {
"upperBound": 1.5
},
"thresholds": [
{
"value": 0.8,
"color": "YELLOW",
"direction": "ABOVE"
},
{
"value": 1,
"color": "RED",
"direction": "ABOVE"
}
]
}
}
},
{
"xPos": 1,
"yPos": 5,
"width": 4,
"height": 4,
"widget": {
"title": "My Chart",
"xyChart": {
"dataSets": [
{
"timeSeriesQuery": {
"timeSeriesFilter": {
"filter": "metric.type=\"compute.googleapis.com/instance/cpu/utilization\" resource.type=\"gce_instance\"",
"aggregation": {
"perSeriesAligner": "ALIGN_MEAN",
"crossSeriesReducer": "REDUCE_MAX",
"groupByFields": [
"resource.label.zone"
]
}
},
"unitOverride": "'1'"
},
"plotType": "LINE",
"minAlignmentPeriod": "60s"
}
],
"yAxis": {
"label": "y1Axis",
"scale": "LINEAR"
}
}
}
}
]
}
}
此信息中心类似于以下示例:
RowLayout
布局的信息中心
此信息中心会显示 RowLayout
布局,其中有三个微件。
{
"displayName": "Row Layout Example",
"rowLayout": {
"rows": [
{
"weight": "1",
"widgets": [
{
"text": {
"content": "Widget 1",
"format": "MARKDOWN"
}
},
{
"text": {
"content": "Widget 2",
"format": "MARKDOWN"
}
},
{
"text": {
"content": "Widget 3",
"format": "MARKDOWN"
}
}
]
}
]
}
}
此信息中心类似于以下示例:
ColumnLayout
布局的信息中心
此信息中心会显示 ColumnLayout
布局,其中有三个微件。
{
"displayName": "Column Layout Example",
"columnLayout": {
"columns": [
{
"weight": "1",
"widgets": [
{
"text": {
"content": "Widget 1",
"format": "MARKDOWN"
}
},
{
"text": {
"content": "Widget 2",
"format": "MARKDOWN"
}
},
{
"text": {
"content": "Widget 3",
"format": "MARKDOWN"
}
}
]
}
]
}
}
此信息中心类似于以下示例:
包含 Widgets
的信息中心
包含 XyChart
的信息中心
此信息中心会显示一个包含基本 XyChart
的信息中心。如果您曾使用 Google Cloud 控制台在信息中心内创建图表,那么这些图表就是 XyChart
widget 的实例。
与 Google Cloud 控制台中提供的功能类似,该 API 也提供用于更改图表的 PlotType
或配置图表的视图模式的选项。
{
"dashboardFilters": [],
"displayName": "Example line chart",
"labels": {},
"mosaicLayout": {
"columns": 48,
"tiles": [
{
"height": 16,
"widget": {
"title": "VM Instance - CPU utilization [MEAN]",
"xyChart": {
"chartOptions": {
"mode": "COLOR"
},
"dataSets": [
{
"minAlignmentPeriod": "60s",
"plotType": "LINE",
"targetAxis": "Y1",
"timeSeriesQuery": {
"timeSeriesFilter": {
"aggregation": {
"alignmentPeriod": "60s",
"crossSeriesReducer": "REDUCE_MEAN",
"groupByFields": [
"resource.label.\"zone\""
],
"perSeriesAligner": "ALIGN_MEAN"
},
"filter": "metric.type=\"compute.googleapis.com/instance/cpu/utilization\" resource.type=\"gce_instance\""
}
}
}
],
"thresholds": [],
"yAxis": {
"label": "",
"scale": "LINEAR"
}
}
},
"width": 24
}
]
}
}
信息中心内的图表与以下示例类似:
下一部分介绍了如何创建 Log Analytics 图表 widget,如何在图表上显示阈值,以及如何配置图表是使用左侧 Y 轴、右侧 Y 轴,还是同时使用两者。
包含 Log Analytics 图表的信息中心
此信息中心显示的信息中心包含 Log Analytics 图表。示例 JSON 包含一个 SQL 查询。
{
"displayName": "Example",
"dashboardFilters": [],
"mosaicLayout": {
"columns": 48,
"tiles": [
{
"width": 24,
"height": 16,
"widget": {
"title": "Sample analytics chart",
"xyChart": {
"chartOptions": {
"mode": "COLOR"
},
"dataSets": [
{
"breakdowns": [],
"dimensions": [
{
"column": "location",
"columnType": "STRING",
"maxBinCount": 5,
"sortColumn": "location",
"sortOrder": "SORT_ORDER_ASCENDING"
}
],
"measures": [
{
"aggregationFunction": {
"parameters": [],
"type": "count"
},
"column": ""
}
],
"plotType": "STACKED_BAR",
"targetAxis": "Y1",
"timeSeriesQuery": {
"opsAnalyticsQuery": {
"queryHandle": "",
"sql": "SELECT\n CAST(JSON_VALUE(resource.labels.location) AS STRING) AS location,\n severity,\nFROM\n `TABLE`"
}
}
}
],
"thresholds": [],
"yAxis": {
"label": "",
"scale": "LINEAR"
}
}
}
}
]
},
"labels": {}
}
信息中心内的图表与以下示例类似:
包含 XyChart
和阈值的信息中心
此信息中心会显示一个配置了基本 XyChart
、阈值和左侧 Y 轴的信息中心。
{
"dashboardFilters": [],
"displayName": "Example line with threshold",
"labels": {},
"mosaicLayout": {
"columns": 48,
"tiles": [
{
"height": 16,
"widget": {
"title": "VM Instance - CPU utilization [MEAN]",
"xyChart": {
"chartOptions": {
"mode": "COLOR"
},
"dataSets": [
{
"minAlignmentPeriod": "60s",
"plotType": "LINE",
"targetAxis": "Y1",
"timeSeriesQuery": {
"timeSeriesFilter": {
"aggregation": {
"alignmentPeriod": "60s",
"crossSeriesReducer": "REDUCE_MEAN",
"groupByFields": [
"resource.label.\"zone\""
],
"perSeriesAligner": "ALIGN_MEAN"
},
"filter": "metric.type=\"compute.googleapis.com/instance/cpu/utilization\" resource.type=\"gce_instance\""
}
}
}
],
"thresholds": [
{
"label": "",
"targetAxis": "Y1",
"value": 0.2
}
],
"yAxis": {
"label": "",
"scale": "LINEAR"
}
}
},
"width": 24
}
]
}
}
在前面的示例中,JSON 指定使用左侧 Y 轴,因为它包含 y2Axis
结构。在 targetAxis
字段中,将“Y1”用于右 Y 轴,将“Y2”用于左 Y 轴。如果省略 targetAxis
字段,则使用右 Y 轴。
此信息中心上的图表类似于以下示例:
您可以构建显示多种指标类型并使用左右轴的图表。前面的示例展示了一个具有单一指标类型的图表,即 dataSets
数组中有 1 个元素。在为两种指标类型绘制图表时,dataSets
数组包含两个元素,每个元素都指定其 targetAxis
。
包含 STACKED_AREA PlotType
类型 XyChart
的信息中心
此信息中心会显示 STACKED_AREA
PlotType
类型的 XyChart
。
{
"dashboardFilters": [],
"displayName": "Example stacked area",
"labels": {},
"mosaicLayout": {
"columns": 48,
"tiles": [
{
"height": 16,
"widget": {
"title": "VM Instance - CPU utilization [MEAN]",
"xyChart": {
"chartOptions": {
"mode": "COLOR"
},
"dataSets": [
{
"minAlignmentPeriod": "60s",
"plotType": "STACKED_AREA",
"targetAxis": "Y1",
"timeSeriesQuery": {
"timeSeriesFilter": {
"aggregation": {
"alignmentPeriod": "60s",
"crossSeriesReducer": "REDUCE_MEAN",
"groupByFields": [
"resource.label.\"zone\""
],
"perSeriesAligner": "ALIGN_MEAN"
},
"filter": "metric.type=\"compute.googleapis.com/instance/cpu/utilization\" resource.type=\"gce_instance\""
}
}
}
],
"thresholds": [],
"yAxis": {
"label": "",
"scale": "LINEAR"
}
}
},
"width": 24
}
]
}
}
信息中心内的图表与以下示例类似:
包含 STACKED_BAR PlotType
类型 XyChart 的信息中心
此信息中心会显示 STACKED_BAR
PlotType
类型的 XyChart
。
{
"dashboardFilters": [],
"displayName": "Example stacked bar",
"labels": {},
"mosaicLayout": {
"columns": 48,
"tiles": [
{
"height": 16,
"widget": {
"title": "VM Instance - CPU utilization [MEAN]",
"xyChart": {
"chartOptions": {
"mode": "COLOR"
},
"dataSets": [
{
"minAlignmentPeriod": "60s",
"plotType": "STACKED_BAR",
"targetAxis": "Y1",
"timeSeriesQuery": {
"timeSeriesFilter": {
"aggregation": {
"alignmentPeriod": "60s",
"crossSeriesReducer": "REDUCE_MEAN",
"groupByFields": [
"resource.label.\"zone\""
],
"perSeriesAligner": "ALIGN_MEAN"
},
"filter": "metric.type=\"compute.googleapis.com/instance/cpu/utilization\" resource.type=\"gce_instance\""
}
}
}
],
"thresholds": [],
"yAxis": {
"label": "",
"scale": "LINEAR"
}
}
},
"width": 24
}
]
}
}
此信息中心类似于以下示例:
包含基本 Scorecard
的信息中心
此信息中心会显示 Scorecard
,但不带仪表盘或迷你图。此示例显示了 Compute Engine CPU 利用率,统计信息摘要图表有两个阈值。一个阈值用黄色来表示 CPU 利用率超过 70%,另一个阈值用红色来表示 CPU 利用率超过 90%。
由于当前的 CPU 利用率低于指定的阈值,因此颜色为绿色。
{
"dashboardFilters": [],
"displayName": "Example-basic scorecard",
"labels": {},
"mosaicLayout": {
"columns": 48,
"tiles": [
{
"height": 8,
"widget": {
"scorecard": {
"thresholds": [
{
"color": "YELLOW",
"direction": "ABOVE",
"label": "",
"value": 0.7
},
{
"color": "RED",
"direction": "ABOVE",
"label": "",
"value": 0.9
}
],
"timeSeriesQuery": {
"outputFullDuration": true,
"timeSeriesFilter": {
"aggregation": {
"alignmentPeriod": "60s",
"crossSeriesReducer": "REDUCE_MEAN",
"groupByFields": [],
"perSeriesAligner": "ALIGN_MEAN"
},
"filter": "metric.type=\"compute.googleapis.com/instance/cpu/utilization\" resource.type=\"gce_instance\""
}
}
},
"title": "VM Instance - CPU utilization [MEAN]"
},
"width": 16
}
]
}
}
此信息中心类似于以下示例:
包含带有 GaugeView
的 Scorecard
的信息中心
此信息中心为上一个示例中的基本统计信息摘要添加了一个仪表盘。GaugeView
对象可以指定上限和下限,以指定要在仪表盘上显示的值的范围。由于统计信息摘要图表显示 0 到 1 的值,因此这些上下限是合理的。要添加仪表盘,请将以下内容添加到基本统计信息摘要的 JSON 中:
"gaugeView": {
"lowerBound": 0,
"upperBound": 1,
},
下面显示了完整的修改后的信息中心规范:当前值低于阈值,该值在仪表盘上以适当颜色显示。
{
"dashboardFilters": [],
"displayName": "Example-Gauge",
"labels": {},
"mosaicLayout": {
"columns": 48,
"tiles": [
{
"height": 8,
"widget": {
"scorecard": {
"gaugeView": {
"lowerBound": 0,
"upperBound": 1
},
"thresholds": [
{
"color": "YELLOW",
"direction": "ABOVE",
"label": "",
"value": 0.7
},
{
"color": "RED",
"direction": "ABOVE",
"label": "",
"value": 0.9
}
],
"timeSeriesQuery": {
"outputFullDuration": true,
"timeSeriesFilter": {
"aggregation": {
"alignmentPeriod": "60s",
"crossSeriesReducer": "REDUCE_MEAN",
"groupByFields": [],
"perSeriesAligner": "ALIGN_MEAN"
},
"filter": "metric.type=\"compute.googleapis.com/instance/cpu/utilization\" resource.type=\"gce_instance\""
}
}
},
"title": "VM Instance - CPU utilization [MEAN]"
},
"width": 16
}
]
}
}
此信息中心上的图表类似于以下示例:
包含带有 SparkChartView
的 Scorecard
的信息中心
此信息中心将上一个示例中的仪表盘替换为迷你图。SparkChartView
对象可以在统计信息摘要上创建折线图或条形图。此示例使用了折线。只要值没有违反阈值,就会显示为绿色。要添加迷你图,请将上一个图表中的 gaugeView
JSON 对象替换为以下内容:
"sparkChartView": {
"sparkChartType": "SPARK_LINE"
},
统计信息摘要类似于以下示例:
包含 PieChart
微件的信息中心
信息中心可以使用饼图来显示数据。每个时序向饼图中做出一片。饼图不会显示一段时间内的数据,而是只显示最新值。
所有饼图均由 PieChart
widget 指定。
如需将图表配置为显示最近测量值的总和,请将 chartType
字段设置为 DONUT
。否则,请将此字段设置为 PIE
的值。
"pieChart": {
"chartType": "DONUT",
},
以下示例配置了一个包含两个饼图的信息中心,并且其中一个饼图配置为圆环图:
{
"dashboardFilters": [],
"displayName": "Example Pie Donut",
"labels": {},
"mosaicLayout": {
"columns": 48,
"tiles": [
{
"height": 16,
"widget": {
"pieChart": {
"chartType": "DONUT",
"dataSets": [
{
"minAlignmentPeriod": "60s",
"timeSeriesQuery": {
"timeSeriesFilter": {
"aggregation": {
"alignmentPeriod": "60s",
"perSeriesAligner": "ALIGN_RATE"
},
"filter": "metric.type=\"compute.googleapis.com/instance/disk/read_bytes_count\" resource.type=\"gce_instance\"",
"secondaryAggregation": {
"alignmentPeriod": "60s",
"perSeriesAligner": "ALIGN_MEAN"
}
}
}
}
]
},
"title": "VM Instance - Disk read bytes [MEAN]"
},
"width": 24
},
{
"height": 16,
"widget": {
"pieChart": {
"chartType": "PIE",
"dataSets": [
{
"minAlignmentPeriod": "60s",
"timeSeriesQuery": {
"timeSeriesFilter": {
"aggregation": {
"alignmentPeriod": "60s",
"perSeriesAligner": "ALIGN_RATE"
},
"filter": "metric.type=\"compute.googleapis.com/instance/disk/read_bytes_count\" resource.type=\"gce_instance\"",
"secondaryAggregation": {
"alignmentPeriod": "60s",
"perSeriesAligner": "ALIGN_MEAN"
}
}
}
}
]
},
"title": "VM Instance - Disk read bytes [MEAN]"
},
"width": 24,
"xPos": 24
},
]
}
}
如以下屏幕截图所示,这两个 widget 以饼图形式显示数据,其中一个 widget 显示最新值的总和:
包含 TimeSeriesTable
微件的信息中心
信息中心可以表格格式显示数据,其中每个受监控的时序有一行。表不会显示随时间变化的数据,而是只显示最新值。
所有表均由 TimeSeriesTable
widget 指定:
如需配置要显示的最大行数,请设置
pickTimeSeriesFilter
字段。例如,如需仅显示过去 10 分钟内平均值最大的两个时间序列,请添加以下代码:"pickTimeSeriesFilter": { "direction": "TOP", "numTimeSeries": 2, "rankingMethod": "METHOD_MEAN" },
如果省略
pickTimeSeriesFilter
字段,则表最多显示 300 行。如需配置表显示数据的方式,请使用
metricVisualization
字段:- 如需仅显示“25%”之类的值,请省略此字段或将值设置为
"NUMBER"
。使用此配置时,Google Cloud 控制台会将此 widget 显示为 Table widget。 - 如需显示值和与可能值范围的对比情况的视觉指示,请将此字段的值设置为
"BAR"
。使用此配置时,Google Cloud 控制台会将此微件显示为排行榜微件。
- 如需仅显示“25%”之类的值,请省略此字段或将值设置为
如需配置要显示哪些列,请使用
columnSettings
字段。 以下示例生成的表包含两列,一列名为Latest Value
,属于必填列,另一列名为Name (from instance_id)
:"columnSettings": [ { "column": "Name (from instance_id)", "visible": true } ],
如果您省略
columnSettings
字段,则该表会针对每个标签显示一列。
以下示例显示了一个带有 Table widget 和 Top List widget 的信息中心:
{
"dashboardFilters": [],
"displayName": "Example",
"labels": {},
"mosaicLayout": {
"columns": 48,
"tiles": [
{
"height": 16,
"widget": {
"timeSeriesTable": {
"columnSettings": [
{
"column": "value",
"visible": false
}
],
"dataSets": [
{
"minAlignmentPeriod": "60s",
"timeSeriesQuery": {
"timeSeriesFilter": {
"aggregation": {
"alignmentPeriod": "60s",
"perSeriesAligner": "ALIGN_MEAN"
},
"filter": "metric.type=\"compute.googleapis.com/instance/cpu/utilization\" resource.type=\"gce_instance\""
}
}
}
],
"metricVisualization": "NUMBER"
},
"title": "Table"
},
"width": 24,
"yPos": 16
},
{
"height": 16,
"widget": {
"timeSeriesTable": {
"columnSettings": [
{
"column": "value",
"visible": false
}
],
"dataSets": [
{
"minAlignmentPeriod": "60s",
"timeSeriesQuery": {
"timeSeriesFilter": {
"aggregation": {
"alignmentPeriod": "60s",
"perSeriesAligner": "ALIGN_MEAN"
},
"filter": "metric.type=\"compute.googleapis.com/instance/cpu/utilization\" resource.type=\"gce_instance\""
}
}
}
],
"metricVisualization": "BAR"
},
"title": "Top List"
},
"width": 24
}
]
}
}
如以下屏幕截图所示,这两个 widget 均以表格形式显示数据,并且都包含一个过滤栏。不过,这两个 widget 已经过预配置,可显示不同的列并以不同的方式表示数值:
表格的列对应于标签。每一行对应一个时序。
包含 Text
微件的信息中心
此示例显示了一个包含 Text
微件的信息中心。
{
"dashboardFilters": [],
"displayName": "DB2+TE",
"labels": {},
"mosaicLayout": {
"columns": 48,
"tiles": [
...
{
"height": 16,
"widget": {
"text": {
"content": "# Support information\n\n\nContact information: my-support-team@example.com\nOnline help: [Playbooks](https://example.com)\n\n",
"format": "MARKDOWN",
"style": {
"backgroundColor": "",
"fontSize": "FS_LARGE",
"horizontalAlignment": "H_LEFT",
"padding": "P_EXTRA_SMALL",
"textColor": "",
"verticalAlignment": "V_TOP"
}
}
},
"width": 24,
"yPos": 14
}
]
}
}
文本 widget 类似于以下示例:
包含 AlertChart
微件的信息中心
此信息中心示例展示了一个包含 AlertChart
微件的信息中心:
{
"category": "CUSTOM",
"displayName": "Alert chart example",
"mosaicLayout": {
"columns": 12,
"tiles": [
{
"height": 4,
"widget": {
"alertChart": {
"name": "projects/my-project/alertPolicies/14205854094151528373"
}
},
"width": 6,
}
]
}
}
与其他信息中心微件不同,您不需要为这些微件指定标题或指标过滤条件。但是,您可以为提醒政策指定资源名称。name
字段中的最后一个条目是提醒政策标识符。
信息中心内的图表与以下示例类似:
在此示例中,提醒政策会监控两个不同的虚拟机的 CPU 使用情况。虚线显示条件阈值,设置为 50%。带有 No incidents
标签的绿色卡片表示提醒政策没有未结突发事件。如果您将指针放在突发事件卡片上,系统会打开一个对话框,其中包含底层提醒政策的链接。
包含 ErrorReportingPanel
微件的信息中心
此信息中心示例展示了一个包含 ErrorReportingPanel
微件的信息中心:
{
"dashboardFilters": [],
"displayName": "Error reporting widget",
"labels": {},
"mosaicLayout": {
"columns": 48,
"tiles": [
{
"height": 16,
"widget": {
"errorReportingPanel": {
"projectNames": [
"projects/my-project"
],
"services": [],
"versions": []
},
"title": "Error Reporting Panel"
},
"width": 24,
}
]
}
}
我们建议您将错误报告面板的高度配置为至少 16 个单位,宽度至少为 24 个单位。在前面的示例中,微件的高度为 16 个单位,宽度为 24 个单位。
错误报告面板会显示所选项目中的错误组,此面板可以将错误组限制为特定资源类型、服务或服务版本。以下示例展示了错误报告面板:
包含 IncidentList
微件的信息中心
此信息中心示例展示了一个包含 IncidentList
微件的信息中心:
{
"category": "CUSTOM",
"dashboardFilters": [],
"displayName": "Incident widget",
"labels": {},
"mosaicLayout": {
"columns": 12,
"tiles": [
{
"height": 5,
"widget": {
"incidentList": {
"monitoredResources": [],
"policyNames": []
},
"title": "Incidents"
},
"width": 8,
"xPos": 0,
"yPos": 0
}
]
}
}
前面的示例将 title
字段设置为 Incidents
,并将该 widget 配置为显示 gce_instance
类型资源的所有突发事件。配置此 widget 时,您可以选择多个提醒政策或多种资源类型。
信息中心内的突发事件微件与以下示例类似:
包含 LogsPanel
微件的信息中心
此示例显示了一个包含 LogsPanel
微件的信息中心:
{
"category": "CUSTOM",
"displayName": "Logs Panel",
"mosaicLayout": {
"columns": 12,
"tiles": [
{
"height": 4,
"widget": {
"logsPanel": {
"filter": "",
"resourceNames": [
"projects/012012012012"
]
},
"title": "Logs Panel"
},
"width": 6,
"xPos": 0,
"yPos": 0
}
]
}
}
我们建议您将日志面板的高度配置为至少 3 个单位,将宽度配置为至少 4 个单位。在前面的示例中,微件的高度为 4 个单位,宽度为 6 个单位。
日志面板将显示 resourceNames
字段中列出的 Google Cloud 项目的日志。上例仅指定了一个项目;但是,您可以在此列表中添加多个项目。
日志面板类似于以下示例:
如需了解问题排查信息,请参阅使用日志面板创建信息中心的 API 调用失败。
包含 CollapsibleGroup
微件的信息中心
此示例显示了一个包含 CollapsibleGroup
微件的信息中心:
{
"category": "CUSTOM",
"displayName": "Group testing",
"mosaicLayout": {
"columns": 12,
"tiles": [
{
"height": 4,
"widget": {
"collapsibleGroup": {
"collapsed": false
},
"title": "My group"
},
"width": 12,
"xPos": 0,
"yPos": 0
},
{
"height": 4,
"widget": {
"title": "VM Instance - CPU utilization [MEAN]",
"xyChart": {
"chartOptions": {
"mode": "COLOR"
},
"dataSets": [
{
"minAlignmentPeriod": "60s",
"plotType": "LINE",
"targetAxis": "Y1",
"timeSeriesQuery": {
"apiSource": "DEFAULT_CLOUD",
"timeSeriesFilter": {
"aggregation": {
"alignmentPeriod": "60s",
"crossSeriesReducer": "REDUCE_NONE",
"perSeriesAligner": "ALIGN_MEAN"
},
"filter": "metric.type=\"compute.googleapis.com/instance/cpu/utilization\" resource.type=\"gce_instance\"",
"secondaryAggregation": {
"alignmentPeriod": "60s",
"crossSeriesReducer": "REDUCE_NONE",
"perSeriesAligner": "ALIGN_NONE"
}
}
}
}
],
"thresholds": [],
"timeshiftDuration": "0s",
"yAxis": {
"label": "y1Axis",
"scale": "LINEAR"
}
}
},
"width": 6,
"xPos": 0,
"yPos": 0
}
]
}
}
在前面的示例中,可收起的组微件包含一个图表,其中显示了虚拟机实例的 CPU 利用率。可收起的组 widget 横跨表的一整行。当组的 (x,y) 位置和高度规范包含 widget 的 (x,y) 位置时,该 widget 将包含在该组中。在前面的示例中,组位于 (0,0) 位置,高度为 4。xyChart
位于 (0,0) 的位置,因此它包含在组中。但是,如果该图表的位置更改为 (0,5),则该图表将从该组中排除。最后,当某个 widget 的 (x,y) 位置导致该 widget 包含在组中时,可收起的组 widget 的高度可能会展开。
如需在信息中心中添加群组 widget,信息中心必须具有 MosaicLayout
。
可收起的群组 widget 类似于以下示例:
包含 SingleViewGroup
微件的信息中心
SingleViewGroup
widget 一次显示群组的一个成员。您可以指定作为组成员的图表和其他 widget。此外,您还可以使用 SingleViewGroup
widget 上的菜单来控制显示组中的哪个 widget。
此信息中心显示的信息中心包含一个 SingleViewGroup
widget:
{
"dashboardFilters": [],
"displayName": "Example",
"labels": {},
"mosaicLayout": {
"columns": 48,
"tiles": [
{
"height": 16,
"widget": {
"singleViewGroup": {},
"title": "Untitled group"
},
"width": 24,
"yPos": 16
},
{
"height": 16,
"widget": {
"title": "VM Instance - Disk read bytes [RATE]",
"xyChart": {
"chartOptions": {
"mode": "COLOR"
},
"dataSets": [
{
"minAlignmentPeriod": "60s",
"plotType": "LINE",
"targetAxis": "Y1",
"timeSeriesQuery": {
"timeSeriesFilter": {
"aggregation": {
"alignmentPeriod": "60s",
"perSeriesAligner": "ALIGN_RATE"
},
"filter": "metric.type=\"compute.googleapis.com/instance/disk/read_bytes_count\" resource.type=\"gce_instance\""
}
}
}
],
"thresholds": [],
"yAxis": {
"label": "",
"scale": "LINEAR"
}
}
},
"width": 24,
"yPos": 16
},
{
"height": 16,
"widget": {
"title": "VM Instance - Disk write bytes [RATE]",
"xyChart": {
"chartOptions": {
"mode": "COLOR"
},
"dataSets": [
{
"minAlignmentPeriod": "60s",
"plotType": "LINE",
"targetAxis": "Y1",
"timeSeriesQuery": {
"timeSeriesFilter": {
"aggregation": {
"alignmentPeriod": "60s",
"perSeriesAligner": "ALIGN_RATE"
},
"filter": "metric.type=\"compute.googleapis.com/instance/disk/write_bytes_count\" resource.type=\"gce_instance\""
}
}
}
],
"thresholds": [],
"yAxis": {
"label": "",
"scale": "LINEAR"
}
}
},
"width": 24,
"yPos": 16
}
]
}
}
如上例所示,tiles
数组包含一个 SingleViewGroup
对象;但是,该对象没有指定它包含哪些对象。相反,SingleViewGroup
对象中的成员资格由 width
和 yPos
字段的值决定。SingleViewGroup
对象包含 width
和 yPos
字段的值与 SingleViewGroup
对象的值匹配的对象。在前面的示例中,SingleViewGroup
对象包含两个图表。
包含 SectionHeader
微件的信息中心
SectionHeader
widget 会在信息中心内创建水平分隔线,并在信息中心的目录中创建条目。您可以自定义目录中的条目,并在 widget 中添加其他信息。您还可以配置该 widget,以在章节标题条目后面向目录中添加分隔线。
此信息中心显示的信息中心包含一个图表和一个 SectionHeader
widget:
{
"dashboardFilters": [],
"displayName": "Example",
"labels": {},
"mosaicLayout": {
"columns": 48,
"tiles": [
{
"height": 16,
"widget": {
"title": "VM Instance - Disk write bytes [RATE]",
"xyChart": {
"chartOptions": {
"mode": "COLOR"
},
"dataSets": [
{
"minAlignmentPeriod": "60s",
"plotType": "LINE",
"targetAxis": "Y1",
"timeSeriesQuery": {
"timeSeriesFilter": {
"aggregation": {
"alignmentPeriod": "60s",
"perSeriesAligner": "ALIGN_RATE"
},
"filter": "metric.type=\"compute.googleapis.com/instance/disk/write_bytes_count\" resource.type=\"gce_instance\""
}
}
}
],
"thresholds": [],
"yAxis": {
"label": "",
"scale": "LINEAR"
}
}
},
"width": 24,
"yPos": 4
},
{
"height": 4,
"widget": {
"sectionHeader": {
"dividerBelow": true,
"subtitle": "Instance metrics"
},
"title": "Metrics"
},
"width": 48
}
]
}
}
在 SectionHeader
对象中,title
字段的值会显示在微件和目录中。subtitle
字段的值仅由 widget 显示。当 dividerBelow
的值为 true
时,向目录中添加分隔线。
包含 SLO 微件的信息中心
此信息中心显示了一个带有 SLO widget 的信息中心:
{
"dashboardFilters": [],
"displayName": "Example",
"labels": {},
"mosaicLayout": {
"columns": 48,
"tiles": [
{
"height": 16,
"widget": {
"title": "SLO Error Budget: 99.5% - Distribution Cut - Calendar month",
"xyChart": {
"chartOptions": {
"mode": "COLOR"
},
"dataSets": [
{
"breakdowns": [],
"dimensions": [],
"legendTemplate": "Remaining error requests before SLO is burned",
"measures": [],
"plotType": "LINE",
"targetAxis": "Y1",
"timeSeriesQuery": {
"timeSeriesFilter": {
"aggregation": {
"perSeriesAligner": "ALIGN_NEXT_OLDER"
},
"filter": "select_slo_budget(\"projects/Project_Number/services/SERVICE_ID/serviceLevelObjectives/SLO_ID\")",
},
"unitOverride": "1"
}
}
],
"thresholds": []
}
},
"width": 24
}
]
}
}
如前面的 JSON 所示,SLO 图表表示为 XyChart
对象。这些对象指定所有汇总字段和阈值,filter
字段的值是时间序列选择器。如需详细了解这些选择器,请参阅检索 SLO 数据。
SLO widget 与以下示例类似:
包含空白微件的信息中心
此示例展示了一个信息中心,其中包含一个空的占位符 widget。displayName
字段的值会显示在微件中。
{
"displayName": "Demo Dashboard",
"gridLayout": {
"widgets": [
{
"blank": {}
}
]
}
}
此信息中心类似于以下示例:
设有永久过滤条件的信息中心
如需查看具有永久过滤条件的信息中心示例,请参阅信息中心过滤条件。