信息中心和布局示例

本页面介绍如何使用 Cloud Monitoring API 创建信息中心。对于每个示例,显示 JSON 格式的信息中心定义和相应的信息中心。

Cloud Monitoring 还在 GitHub 上提供了一组精选的信息中心定义。您可以在 Google Cloud 项目中将这些定义安装为自定义信息中心。如需了解此代码库以及如何安装这些信息中心,请参阅安装示例信息中心

何时使用 API

Cloud Monitoring API 为您提供了一种同时管理多个信息中心的方法。虽然您可以使用 Google Cloud 控制台管理信息中心,但您可能会发现使用 API 批量管理自定义信息中心更为方便。

如果您想将空白占位符窗口微件添加到信息中心,也需要使用 API。

通过 API 使用 MQL 或 PromQL

您可以使用 dashboards.create 方法创建信息中心。您将向 API 方法传递一个 Dashboard 对象,其中包含信息中心显示的每个 widget 的一个条目。

当 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"
            }
          }
        ]
      }
    ]
  }
}

此信息中心类似于以下示例:

列布局的信息中心示例

启用信息中心事件,以及添加过滤条件和标签

本部分介绍如何向信息中心添加过滤条件和标签,以及如何配置信息中心以显示事件。

在信息中心内启用事件

您可以通过在 Dashboard 对象中添加 annotations 字段,将信息中心配置为显示事件,例如 Google Kubernetes Engine 更新事件或虚拟机故障事件。annotations 字段包含 DashboardAnnotations 对象的实例,后者包含两个字段:

  • defaultResourceName 字段列出了 Google Cloud 项目用于搜索事件的信息中心级默认值。如果您未指定此字段,则会搜索所选项目。

  • EventAnnotation 对象数组。每个对象都包含以下内容:

    • displayName 字段,可让您定义特定于事件的切换开关上的标签。如果未指定此字段或此字段的值为空字符串,则系统会显示事件的默认名称。
    • enabled 字段,用于控制事件切换开关的值。如果为 true,切换开关处于 on 位置,并且事件会显示在信息中心内。如果为 false,切换开关处于 off 位置。
    • eventType 字段,包含来自 EventType 枚举的值。
    • filter 字段,可让您指定要附加到特定于事件的查询的查询。如果此字段的值为空字符串,则使用针对特定事件的查询。
    • resourceNames 字段,可让您定义要搜索事件的 Google Cloud 项目列表。当此字段为空数组时,系统将搜索您所选的项目。

以下示例显示了一个指定 Google Kubernetes Engine 事件的 annotations 字段:

{
  "displayName": "Annotation example",
  "annotations": {
    "defaultResourceNames": [],
    "eventAnnotations": [
      {
        "displayName": "",
        "enabled": true,
        "eventType": "GKE_CLUSTER_UPDATE",
        "filter": "resource.labels.cluster_name=my-cluster",
        "resourceNames": []
      }
    ]
  },
  "dashboardFilters": [],
  "mosaicLayout": {
  ...
  },
  "labels": {}
}

在前面的示例中,filter 字段用于将查询限制为集群 my-namedisplayName 字段设置为空字符串,因此事件类型的默认名称会显示在该事件的切换开关上。最后,由于 resourceNames 设置为空数组,因此系统会查询当前 Google Cloud 项目中的日志条目。

添加信息中心过滤条件

您可以向信息中心添加永久性过滤条件,以控制信息中心上的 widget 显示哪些数据。如需查看包含永久过滤条件的信息中心示例,请参阅信息中心过滤条件

添加信息中心标签

此示例展示了一个 Dashboard 对象,用于指定名为 playbook 的标签。

{
  "displayName": "Example",
  "mosaicLayout": {
    "columns": 12,
    "tiles": [
      ...
    ]
  },
  "dashboardFilters": [],
  "labels": {
    "playbook": ""
  }
}

如上例所示,labels 字段作为 map 实现,其中 keyvalue 字段都是字符串。向信息中心添加标签时,请将 key 设置为标签的名称,并将 value 字段设置为空字符串。

向信息中心添加标签是可选操作。

包含 Widgets 的信息中心

本部分包含包含不同类型 widget 的信息中心示例。

包含 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
      }
    ]
  }
}

信息中心内的图表与以下示例类似:

XyChart 示例。

下一部分介绍了如何创建 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": {}
}

信息中心内的图表与以下示例类似:

包含 Log Analytics SQL 查询的 XyChart 示例。

包含 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 轴。

此信息中心上的图表类似于以下示例:

使用左侧 Y 轴并包含阈值的 XyChart 示例。

您可以构建显示多种指标类型并使用左轴和右轴的图表。上面的示例展示了一个具有单一指标类型(即 dataSets 数组中有一个元素)的图表。为两种指标类型绘制图表时,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
      }
    ]
  }
}

信息中心内的图表与以下示例类似:

包含堆积面积图的 XyChart 示例。

包含 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
      }
    ]
  }
}

此信息中心类似于以下示例:

包含堆叠条形图的 XyChart 示例。

包含基本 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
      }
    ]
  }
}

此信息中心类似于以下示例:

包含统计信息摘要图表微件的信息中心示例。

包含带有 GaugeViewScorecard 的信息中心

此信息中心为上一个示例中的基本统计信息摘要添加了一个仪表盘。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
      }
    ]
  }
}

此信息中心上的图表类似于以下示例:

包含带有 GaugeView 的统计信息摘要图表微件的信息中心示例。

包含带有 SparkChartViewScorecard 的信息中心

此信息中心将上一个示例中的仪表盘替换为迷你图。SparkChartView 对象可以在统计信息摘要上创建折线图或条形图。此示例使用了折线。只要值没有违反阈值,就会显示为绿色。要添加迷你图,请将上一个图表中的 gaugeView JSON 对象替换为以下内容:

  "sparkChartView": {
    "sparkChartType": "SPARK_LINE"
  },

统计信息摘要与以下示例类似:

包含带有 SparkChartView 的统计信息摘要图表微件的信息中心示例。

包含 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 显示最近值的总和:

**PieChart** 微件示例。

包含 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 控制台会将该 widget 显示为顶部列表 widget。
  • 如需配置要显示的列,请使用 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": "Alerting policy 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 个单位。在前面的示例中,widget 的高度为 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 跨越表格的整行。当某个 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 一次显示群组的一个成员。您可以将图表和其他微件指定为组中的成员。此外,您还可以使用 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 对象中的成员资格由 widthyPos 字段的值决定。如果 widthyPos 字段的值与 SingleViewGroup 对象的值匹配,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 微件的信息中心:

{
  "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 微件与以下示例类似:

包含 SLO 微件的信息中心示例。

包含空白微件的信息中心

此示例展示了一个包含空占位符 widget 的信息中心。displayName 字段的值会显示在微件中。

{
  "displayName": "Demo Dashboard",
  "gridLayout": {
    "widgets": [
      {
        "blank": {}
      }
    ]
  }
}

此信息中心类似于以下示例:

包含空白微件的信息中心示例。