資訊主頁和版面配置範例

本頁說明如何使用 Cloud Monitoring API 建立資訊主頁。每個範例都會顯示 JSON 中的資訊主頁定義,以及對應的資訊主頁。您可以向 Google Cloud CLI 和 Cloud Monitoring API 端點提供 JSON。

Cloud Monitoring 也會在 GitHub 上提供精選的資訊主頁定義。您可以在 Google Cloud 專案中安裝這些定義,做為自訂資訊主頁。如要進一步瞭解這個存放區和如何安裝這些資訊主頁,請參閱「安裝範例資訊主頁」。

使用 API 或 Google Cloud CLI 的時機

您可以透過 Cloud Monitoring API 和 Google Cloud CLI,一次管理多個資訊主頁。您可以使用Google Cloud 控制台管理資訊主頁,但使用指令碼大量管理自訂資訊主頁可能會更輕鬆。

如要在資訊主頁中新增空白預留位置小工具,也必須使用 API。

透過 API 使用 MQL 或 PromQL

您可以使用 dashboards.create 方法建立資訊主頁。您會將 Dashboard 物件傳遞至 API 方法,其中包含資訊主頁顯示的每個小工具項目。

當小工具顯示時間序列資料 (例如圖表小工具) 時,Dashboard 物件中的項目會包含 TimeSeriesQuery 物件。這個物件會說明要繪製成圖表的時間序列資料,您可以透過監控篩選器MQL 查詢PromQL 查詢指定資料:

  • 如要使用監控篩選器,請填入 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 專案中的記錄項目。

新增資訊主頁篩選器和變數

如要控管資訊主頁小工具顯示的資料,可以新增變數和已釘選的篩選器。變數與釘選篩選器不同,因為變數會套用至特定小工具。

如果您建立已釘選的篩選器或變數,監控功能會更新自訂資訊主頁的工具列,顯示篩選器。如果是已釘選的篩選器,工具列篩選器的名稱就是已釘選篩選器的名稱。如果是變數,工具列篩選條件的名稱是美元符號 $, 後方加上變數名稱。每個工具列篩選器都包含一個選單,可讓您變更相關聯的已釘選篩選器或變數值。如果是變數,您可以將工具列篩選器換成資訊主頁小工具。詳情請參閱「資訊主頁與 FilterControl 小工具」。

如要進一步瞭解變數和已釘選的篩選器,以及如何將變數套用至小工具,請參閱「資訊主頁篩選器」。

新增資訊主頁標籤

這個範例顯示 Dashboard 物件,其中指定名為 playbook 的標籤。

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

如上一個範例所示,labels 欄位會實作為 map,其中 keyvalue 欄位都是字串。為資訊主頁新增標籤時,請將 key 設為標籤名稱,並將 value 欄位設為空字串。

您可以選擇是否要在資訊主頁中新增標籤。

已啟用 Widgets 的資訊主頁

本節包含不同類型小工具的資訊主頁範例。

資訊主頁 (XyChart)

這個資訊主頁會顯示含有基本 XyChart 的資訊主頁。如果您曾使用 Google Cloud 控制台在資訊主頁上建立圖表,這些圖表就是 XyChart 小工具的執行個體。

這個 API 提供的功能與 Google Cloud 控制台類似,可讓您變更圖表的 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 圖表小工具、如何在圖表上顯示門檻,以及如何設定圖表是否使用左側 Y 軸、右側 Y 軸或兩者。

內含記錄檔分析圖表的資訊主頁

這個資訊主頁會顯示含有 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  `VIEW`"
                  }
                }
              }
            ],
            "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 欄位中,右側 Y 軸使用「Y1」,左側 Y 軸使用「Y2」。如果省略 targetAxis 欄位,系統會使用右側 Y 軸。

這個資訊主頁上的圖表類似於下列範例:

使用左側 Y 軸並設有門檻的 XyChart 範例。

您可以建構圖表,顯示多種指標類型,並使用左右軸。上一個範例說明的圖表只有單一指標類型,也就是 dataSets 陣列中只有一個元素。繪製兩種指標類型時,dataSets 陣列會包含兩個元素,且每個元素都會指定 targetAxis

資訊主頁,內含 STACKED_AREA PlotTypeXyChart

這個資訊主頁會顯示 XyChart,並附上 STACKED_AREA PlotType

{
  "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 範例。

資訊主頁,內含 XyChart 和 STACKED_BAR PlotType

這個資訊主頁會顯示 XyChart,並附上 STACKED_BAR PlotType

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

資訊主頁看起來會像下列範例:

含有評量表小工具的資訊主頁範例。

資訊主頁,內含 Scorecard,並顯示 GaugeView

這個資訊主頁會在先前範例的基本評量表中新增量表。 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 的評量表小工具。

資訊主頁,內含 Scorecard,並顯示 SparkChartView

這個資訊主頁會以走勢圖取代上一個範例中的儀表板。 SparkChartView 物件可在評量表上建立折線圖或長條圖。 本範例使用一行。只要值未違反門檻,就會顯示綠色。如要新增走勢圖,請將先前圖表中的 gaugeView JSON 物件替換為下列內容:

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

評分表類似於下列範例:

資訊主頁範例,內含 Scorecard 小工具和 SparkChartView。

含有 PieChart 小工具的資訊主頁

資訊主頁可使用圓餅圖顯示資料。每個時間序列都會在圓餅圖中佔據一個切片。圓餅圖不會顯示一段時間內的資料,只會顯示最新值。

所有圓餅圖都是由 PieChart 小工具指定。 如要設定圖表,顯示最近一次測量的總和,請將 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
      },
    ]
  }
}

如下列螢幕截圖所示,兩個小工具都會以圓餅圖顯示資料,其中一個小工具會顯示最新值的總和:

**PieChart** 小工具範例。

含有 Treemap 小工具的資訊主頁

如要以一系列巢狀矩形顯示最新資料,其中每個矩形對應一組不重複的標籤值,請新增樹狀圖。假設您已依 zone 標籤匯總要繪製圖表的資料。 如果將小工具類型設為樹狀圖,樹狀圖中的每個矩形都會對應一個區域。矩形的色彩飽和度與代表的值成正比。

瀏覽樹狀圖時,請使用指標啟動矩形的工具提示。

下列 JSON 會設定 Treemap 小工具,依區域和儲存空間類型匯總時間序列:

{
  "displayName": "Example Treemap",
  "dashboardFilters": [],
  "labels": {},
  "mosaicLayout": {
    "columns": 48,
    "tiles": [
      {
        "xPos": 24,
        "height": 16,
        "width": 24,
        "widget": {
          "title": "VM Instance - Write read bytes [SUM]",
          "id": "",
          "treemap": {
            "dataSets": [
              {
                "breakdowns": [],
                "measures": [],
                "timeSeriesQuery": {
                  "outputFullDuration": true,
                  "timeSeriesFilter": {
                    "aggregation": {
                      "alignmentPeriod": "60s",
                      "crossSeriesReducer": "REDUCE_SUM",
                      "groupByFields": [
                        "resource.label.\"zone\"",
                        "metric.label.\"storage_type\""
                      ],
                      "perSeriesAligner": "ALIGN_RATE"
                    },
                    "filter": "metric.type=\"compute.googleapis.com/instance/disk/write_bytes_count\" resource.type=\"gce_instance\""
                  },
                  "unitOverride": ""
                }
              }
            ],
            "treemapHierarchy": [
              "resource.label.\"zone\"",
              "metric.label.\"storage_type\""
            ]
          }
        }
      }
    ]
  }
}

下方的螢幕截圖顯示了使用先前設定的樹狀圖小工具:

**樹狀圖** 小工具範例。

在螢幕截圖中,一個矩形顯示工具提示。

含有 TimeSeriesTable 小工具的資訊主頁

資訊主頁可以表格格式顯示資料,每個不重複的標籤值組合各佔一行。表格不會顯示一段時間內的資料,而是顯示最新值或匯總值。

所有資料表都由 TimeSeriesTable 小工具指定:

  • 如要設定要顯示的時間序列,請使用 dataSets 欄位。dataSets 陣列中的每個物件都對應單一指標類型。如果您查詢多個指標類型, Google Cloud 控制台會嘗試在同一資料列中顯示每項查詢的最新值。詳情請參閱「資料表如何合併多個指標類型的資料」。

    • TimeSeriesQuery 欄位會指定指標類型。
    • 如要讓表格顯示匯總值 (資料會根據資訊主頁設定的時間範圍值匯總),請將 timeSeriesQuery.outputFullDuration 欄位設為 true
  • 如要設定顯示的列數上限,請設定 pickTimeSeriesFilter 欄位。舉例來說,如要只顯示過去 10 分鐘內平均值最大的兩個時間序列,請加入下列項目:

    "pickTimeSeriesFilter": {
        "direction": "TOP",
        "numTimeSeries": 2,
        "rankingMethod": "METHOD_MEAN"
    },
    

    如果省略 pickTimeSeriesFilter 欄位,表格最多會顯示 300 列。

  • 如要設定表格顯示資料的方式,請使用 metricVisualization 欄位:

    • 如要只顯示「25%」等值,請省略這個欄位或將值設為 "NUMBER"。使用這項設定時,Google Cloud 控制台會將小工具顯示為「表格」小工具。
    • 如要顯示值,以及值與可能值範圍的比較結果,請將這個欄位的值設為 "BAR"。 使用這項設定時,Google Cloud 控制台會將小工具顯示為「熱門清單」小工具。
  • 如要設定顯示的資料欄和資料欄的屬性,請使用 columnSettings 陣列。如未指定這個欄位,表格會為每個標籤顯示一個資料欄。

    "column" 欄位的值必須設為標籤鍵或 value,後者是指時間序列的最新值。您可以設定資料欄的顯示名稱,以及設定表格儲存格內資料的對齊方式:

    • 如要自訂欄標題,請設定 displayName 欄位。
    • 如要根據最新值與門檻的比較結果,為顯示最新值的儲存格上色,請新增 thresholds 物件。
    • 如要變更文字對齊方式,請新增 alignment 欄位。

    以下範例說明兩個資料欄:

    "columnSettings": [
      {
        "column": "device_name",
        "displayName": "Device",
        "visible": true
      },
      {
        "alignment": "CENTER",
        "column": "value",
        "displayName": "Disk Write Bytes",
        "thresholds": [
          {
            "color": "YELLOW",
            "direction": "ABOVE",
            "value": 4000
          },
          {
            "color": "RED",
            "direction": "ABOVE",
            "value": 5000
          }
        ],
        "visible": true
      }
    ],
    

下列 JSON 說明包含兩個資料表的資訊主頁。第一個表格會顯示兩種指標類型:從執行個體讀取的位元組數,以及寫入執行個體的位元組數。系統會顯示匯總值和參照長條。第二個表格顯示某種指標類型的最新值,且值資料欄已設定為根據值與門檻的比較結果,為儲存格加上顏色代碼:

{
  "displayName": "Example",
  "mosaicLayout": {
    "columns": 48,
    "tiles": [
      {
        "width": 44,
        "height": 17,
        "widget": {
          "title": "VM Instance - Disk read bytes [RATE], Disk write bytes [RATE]",
          "timeSeriesTable": {
            "dataSets": [
              {
                "timeSeriesQuery": {
                  "timeSeriesFilter": {
                    "filter": "metric.type=\"compute.googleapis.com/instance/disk/read_bytes_count\" resource.type=\"gce_instance\"",
                    "aggregation": {
                      "alignmentPeriod": "60s",
                      "perSeriesAligner": "ALIGN_RATE",
                      "groupByFields": []
                    },
                    "pickTimeSeriesFilter": {
                      "rankingMethod": "METHOD_MEAN",
                      "numTimeSeries": 30,
                      "direction": "TOP"
                    }
                  },
                  "unitOverride": "",
                  "outputFullDuration": true
                },
                "tableTemplate": "",
                "minAlignmentPeriod": "60s"
              },
              {
                "timeSeriesQuery": {
                  "timeSeriesFilter": {
                    "filter": "metric.type=\"compute.googleapis.com/instance/disk/write_bytes_count\" resource.type=\"gce_instance\"",
                    "aggregation": {
                      "alignmentPeriod": "60s",
                      "perSeriesAligner": "ALIGN_RATE",
                      "groupByFields": []
                    },
                    "pickTimeSeriesFilter": {
                      "rankingMethod": "METHOD_MEAN",
                      "numTimeSeries": 30,
                      "direction": "TOP"
                    }
                  },
                  "unitOverride": "",
                  "outputFullDuration": true
                },
                "tableTemplate": "",
                "minAlignmentPeriod": "60s"
              }
            ],
            "metricVisualization": "BAR",
            "columnSettings": [
              {
                "column": "Name (from instance_id)",
                "visible": true
              },
              {
                "column": "zone",
                "visible": true
              },
              {
                "column": "device_name",
                "visible": true
              },
              {
                "column": "storage_type",
                "visible": true
              },
              {
                "column": "device_type",
                "visible": true
              },
              {
                "column": "value",
                "visible": true,
                "displayName": "Read bytes"
              },
              {
                "column": "value-1",
                "visible": true,
                "displayName": "Written bytes"
              }
            ],
            "opsAnalyticsSettings": {
              "maxRows": "0",
              "showFilterBar": false,
              "pageSize": "0"
            },
            "displayColumnType": false
          },
          "id": ""
        }
      },
      {
        "yPos": 17,
        "width": 44,
        "height": 16,
        "widget": {
          "title": "VM Instance - Disk write bytes [RATE]",
          "timeSeriesTable": {
            "columnSettings": [
              {
                "column": "device_name",
                "displayName": "Device",
                "visible": true
              },
              {
                "alignment": "LEFT",
                "column": "instance_name",
                "displayName": "Instance name",
                "visible": true
              },
              {
                "column": "storage_type",
                "displayName": "Storage type",
                "visible": true
              },
              {
                "column": "device_type",
                "displayName": "Device Type",
                "visible": true
              },
              {
                "alignment": "CENTER",
                "column": "value",
                "displayName": "Disk Write Bytes",
                "thresholds": [
                  {
                    "color": "YELLOW",
                    "direction": "ABOVE",
                    "label": "",
                    "value": 4000
                  },
                  {
                    "color": "RED",
                    "direction": "ABOVE",
                    "label": "",
                    "value": 5000
                  }
                ],
                "visible": true
              },
              {
                "alignment": "LEFT",
                "column": "Name (from instance_id)",
                "displayName": "ID",
                "visible": true
              }
            ],
            "dataSets": [
              {
                "minAlignmentPeriod": "60s",
                "timeSeriesQuery": {
                  "timeSeriesFilter": {
                    "aggregation": {
                      "alignmentPeriod": "60s",
                      "perSeriesAligner": "ALIGN_RATE"
                    },
                    "filter": "metric.type=\"compute.googleapis.com/instance/disk/write_bytes_count\" resource.type=\"gce_instance\""
                  }
                }
              }
            ],
            "displayColumnType": false,
            "metricVisualization": "NUMBER",
            "opsAnalyticsSettings": {
              "maxRows": "0",
              "pageSize": "0",
              "showFilterBar": false
            }
          }
        }
      }
    ]
  },
  "dashboardFilters": [],
  "labels": {}
}

下列螢幕截圖說明先前定義的資料表:

含有表格小工具的資訊主頁範例。

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

文字小工具看起來類似下列範例:

文字小工具範例。

含有 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 欄位的最後一個項目是警告政策 ID。

資訊主頁上的圖表類似於下列範例:

快訊政策的圖表示例。

在這個範例中,快訊政策會監控兩部不同虛擬機器的 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 個單位。

錯誤回報面板會顯示所選專案的錯誤群組,且這個面板可將錯誤群組限制為特定資源類型、服務或服務版本。以下範例說明錯誤回報面板:

錯誤回報面板設定窗格範例。

含有 FilterControl 小工具的資訊主頁

建立變數後,Monitoring 會更新自訂資訊主頁的工具列,顯示該變數的篩選器。篩選器名稱為美元符號 $,後方加上變數名稱。例如,$my-variable。每個篩選器都包含一個選單,可供您變更變數的值。

使用工具列篩選器管理變數值可能不是最佳做法。舉例來說,假設您有一個包含許多圖表的資訊主頁,而您有一個只適用於兩個圖表的變數。針對這種情況,您可能會執行下列操作:

  1. 在資訊主頁中新增 CollapsibleGroup 小工具,然後將這兩個圖表放入群組。
  2. 在資訊主頁中新增 FilterControl 小工具。 您可為變數設定這個小工具,並將這個小工具加入群組。

    群組小工具包含 FilterControl 小工具,可讓您變更變數的值,以及變數套用的目標小工具。此外,資訊主頁工具列不會再顯示變數的篩選器。

下列資訊主頁包含 FilterControl 小工具:

{
  "displayName": "Dashboard with filter control widget",
  "dashboardFilters": [
    {
      "filterType": "RESOURCE_LABEL",
      "labelKey": "project_id",
      "stringValue": "my-project",
      "templateVariable": "proj",
      "valueType": "STRING"
    }
  ],
  "description": "",
  "labels": {},
  "mosaicLayout": {
    "columns": 48,
    "tiles": [
      {
        "yPos": 70,
        "height": 5,
        "width": 16,
        "widget": {
          "title": "Project control",
          "filterControl": {
            "templateVariable": "proj"
          }
        }
      }
    ]
  }
}

上一個範例定義了一個變數 proj,並新增一個 FilterControl 小工具。完成這項設定後,變數功能表會從資訊主頁工具列移至名為「Project control」的小工具。該小工具包含選單,可用於選取專案。

含有 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,並將小工具設定為顯示 gce_instance 類型資源的所有事件。設定這個小工具時,您可以選取多項快訊政策或多種資源類型。

資訊主頁上的事件小工具如下所示:

事件小工具範例。

含有 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 call to create dashboard with a logs panel fails」。

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

在先前的範例中,可收合群組小工具包含單一圖表,顯示 VM 執行個體的 CPU 使用率。可收合的群組小工具會跨越整個資料表列。當群組的 (x,y) 位置和高度規格包含小工具的 (x,y) 位置時,小工具就會納入群組。在上例中,群組位於 (0,0) 的位置,高度為 4。xyChart 位於 (0,0) 的位置,因此會納入群組。不過,如果將圖表位置變更為 (0,5),圖表就會從群組中排除。最後,當小工具的 (x,y) 位置導致小工具納入群組時,可收合群組小工具的高度可能會擴展。

如要在資訊主頁上加入群組小工具,資訊主頁必須有 MosaicLayout

可收合群組小工具看起來會像下列範例:

可收合群組小工具的資訊主頁範例。

含有 SingleViewGroup 小工具的資訊主頁

SingleViewGroup 小工具一次會顯示一個群組成員。您可指定群組中的圖表和其他小工具。此外,您可以使用 SingleViewGroup 小工具上的選單,控制要顯示群組中的哪個小工具。

SingleViewGroup 小工具支援兩種顯示樣式:DROPDOWNTAB。這兩種樣式的差異在於如何選取要顯示的群組成員。DROPDOWN 樣式的微件會提供選單。TAB 樣式的小工具會在小工具的工具列中提供分頁:

{
  "dashboardFilters": [],
  "displayName": "Example",
  "labels": {},
  "mosaicLayout": {
    "columns": 48,
    "tiles": [
      {
        "height": 16,
        "widget": {
          "singleViewGroup": {
            "displayType": "DROPDOWN"
          },
          "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 物件,但該物件未指定所含物件。而是由 widthyPos 欄位的值決定 SingleViewGroup 物件的成員資格。widthyPos 欄位值與 SingleViewGroup 物件值相符的物件,會包含在 SingleViewGroup 物件中。在上述範例中,SingleViewGroup 物件包含兩個圖表。

含有 SectionHeader 小工具的資訊主頁

SectionHeader 小工具會在資訊主頁中建立水平分隔線,並在資訊主頁的目錄中建立項目。您可以自訂目錄中的項目,並在小工具中加入其他資訊。你也可以設定小工具,在章節標題項目後方新增目錄分隔線。

這個資訊主頁顯示包含單一圖表和 SectionHeader 小工具的資訊主頁:

{
  "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 欄位的值只會顯示在小工具中。如果 dividerBelow 的值為 true,目錄中就會加入分隔線。

含有服務等級目標小工具的資訊主頁

這個資訊主頁會顯示含有 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 小工具的資訊主頁範例。

資訊主頁,其中一個小工具空白

這個範例顯示的資訊主頁含有空白的預留位置小工具。 小工具會顯示 displayName 欄位的值。

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

資訊主頁看起來會像下列範例:

空白小工具的資訊主頁範例。

已設定小工具顯示設定的資訊主頁

這個資訊主頁包含文字小工具和變數。變數的值會決定是否顯示或隱藏文字小工具:

  • 名為 show 的變數預設值為 a。變數的值定義為 abc。由於 valueType 欄位為 STRING_ARRAY,因此變數也可以設為 a or b 等值。

  • 在文字小工具中,標示為 visibilityCondition 的項目會定義小工具的顯示狀態。如果變數 show 的值包含 b,系統就會顯示文字小工具。否則系統不會顯示文字小工具。


{
  "displayName": "Conditional Widget Example",
  "mosaicLayout": {
    "columns": 48,
    "tiles": [
      {
        "yPos": 16,
        "width": 24,
        "height": 16,
        "widget": {
          "title": "A text widget",
          "text": {
            "content": "Example showing how to use a custom variable to control visibility.",
            "format": "MARKDOWN",
            "style": {
              "backgroundColor": "#FFFFFF",
              "fontSize": "FS_LARGE",
              "horizontalAlignment": "H_LEFT",
              "padding": "P_EXTRA_SMALL",
              "pointerLocation": "POINTER_LOCATION_UNSPECIFIED",
              "textColor": "#212121",
              "verticalAlignment": "V_TOP"
            }
          },
          "visibilityCondition": {
            "templateVariableCondition": {
              "templateVariable": "show",
              "templateVariableValue": "b",
              "comparator": "REGEX_FULL_MATCH"
            }
          }
        }
      }
    ]
  },
  "dashboardFilters": [
    {
      "labelKey": "",
      "templateVariable": "show",
      "stringArrayValue": {
        "values": [
          "a"
        ]
      },
      "filterType": "VALUE_ONLY",
      "valueType": "STRING_ARRAY",
      "stringArray": {
        "values": [
          "a",
          "b",
          "c"
        ]
      }
    }
  ],
  "labels": {}
}

如要瞭解設定小工具瀏覽權限的相關限制,請參閱「設定小工具的瀏覽權限」。