查詢及查看未解決的快訊

在 Google Distributed Cloud (GDC) 氣隙裝置專案中建立快訊規則後,您可以透過專案系統監控執行個體的使用者介面 (UI) 查詢及查看資訊主頁上的快訊

查詢及查看資訊主頁上的快訊

您可以在 專案的系統監控執行個體。platform-obs

系統監控執行個體包含專案層級的指標、記錄和快訊,可執行網路監控和伺服器監控等監控程序。

事前準備

如要在資訊主頁上查詢及查看快訊,您必須先取得系統監控執行個體的存取權。詳情請參閱「取得資訊主頁的存取權」。

如要登入並查看快訊,請要求專案 IAM 管理員授予您專案 Grafana 檢視者 (project-grafana-viewer) 角色。透過這個角色式存取控管程序,您可以安全地存取資料視覺化內容。

系統監控執行個體端點

應用程式營運人員 (AO):

開啟下列網址,存取專案的端點:

https://GDC_URL/PROJECT_NAMESPACE/grafana

更改下列內容:

  • GDC_URL:您在 GDC 中的機構網址。
  • PROJECT_NAMESPACE:專案的命名空間。

專案的 UI 包含預設資訊主頁,例如「快訊 - 總覽」資訊主頁,其中提供快訊相關資訊。從使用者介面查詢快訊,即可從專案中以視覺化方式擷取快訊資訊,並取得資源的整合式檢視畫面,以便瞭解及快速解決問題。

平台管理員 (PA):

開啟下列網址,存取 platform-obs 專案的端點:

https://GDC_URL/platform-obs/grafana

GDC_URL 替換為貴機構在 GDC 中的網址。

系統監控執行個體的使用者介面包含預設資訊主頁,例如「快訊 - 總覽」資訊主頁,其中包含資料可觀測性的快訊相關資訊。從使用者介面查詢快訊,即可從專案中以視覺化方式擷取快訊資訊,並取得資源的整合式檢視畫面,以便瞭解及快速解決問題。

「快訊 - 總覽」資訊主頁會顯示特定資料來源的快訊數量資訊,以及快訊記錄的折線圖,顯示該資料來源每小時開啟的快訊數量。

圖 1. Grafana UI 上的「Alerts - Overview」(快訊 - 總覽) 資訊主頁。

Alertmanager

Alertmanager 可讓你監控用戶端應用程式的警示通知。您可以使用 Alertmanager 檢查及關閉快訊,並篩選或分組快訊:

在根管理員叢集中忽略 Loki 拒絕稽核記錄快訊

圖 2:從 Alertmanager 查詢稽核記錄的選單選項。

預先定義的快訊政策

下表列出 Prometheus 中預先安裝的警報規則:

名稱 說明
KubeAPIDown (重大) KubeAPI 從 Prometheus 目標探索中消失 15 分鐘。
KubeClientErrors (警告) Kubernetes API 伺服器用戶端錯誤率在 15 分鐘內 > 0.01。
KubeClientErrors (重大) Kubernetes API 伺服器用戶端錯誤率在 15 分鐘內超過 0.1。
KubePodCrashLooping (警告) Pod 處於當機迴圈狀態的時間已超過 15 分鐘。
KubePodNotReady (警告) Pod 處於非就緒狀態的時間已超過 15 分鐘。
KubePersistentVolumeFillingUp (重大) 所要求 PersistentVolume 的可用位元組數 < 0.03。
KubePersistentVolumeFillingUp (警告) 所要求 PersistentVolume 的可用位元組數 < 0.15。
KubePersistentVolumeErrors (重大) 永久磁碟區處於「失敗」或「待處理」階段五分鐘。
KubeNodeNotReady (警告) 節點已超過 15 分鐘未就緒。
KubeNodeCPUUsageHigh (重大) 節點 CPU 使用率 > 80%。
KubeNodeMemoryUsageHigh (最高) 節點記憶體用量 > 80%。
NodeFilesystemSpaceFillingUp (警告) 節點檔案系統用量超過 60%。
NodeFilesystemSpaceFillingUp (critical) 節點檔案系統用量大於 85%。
CertManagerCertExpirySoon (警告) 有憑證將於 21 天後到期。
CertManagerCertNotReady (重大) 憑證在 10 分鐘後仍無法提供流量。
CertManagerHittingRateLimits (critical) 在五分鐘內建立及續訂憑證時,已達到速率限制。
DeploymentNotReady (重大)。 機構管理員叢集上的部署作業處於非就緒狀態的時間已超過 15 分鐘。

範例 alertmanagerConfigurationConfigmaps

ConfigMap 中 alertmanagerConfigurationConfigmaps 清單的設定語法必須遵循 https://prometheus.io/docs/alerting/latest/configuration/

apiVersion: observability.gdc.goog/v1alpha1
kind: ObservabilityPipeline
metadata:
  # Choose namespace that matches the project's namespace
  namespace: kube-system
  name: observability-config
# Configure Alertmanager
 alerting:
  # Storage size for alerting data within organization
  # Permission: PA
  localStorageSize: 1Gi

  # Permission: PA & AO
  # alertmanager config must be under the key "alertmanager.yml" in the configMap
  alertmanagerConfig: <configmap-for-alertmanager-config>

  # Permission: PA
  volumes:
    - <volume referenced in volumeMounts>

  # Permission: PA
  volumeMounts:
    - <volumeMount referenced in alertmanagerConfig>

規則設定範例

# Configures either an alert or a target record for precomputation
apiVersion: monitoring.gdc.goog/v1alpha1
kind: MonitoringRule
metadata:
  # Choose namespace that contains the metrics that rules are based on
  # Note: alert/record will be produced in the same namespace
  namespace: g-fleetns-a
  name: alerting-config
spec:
  # Rule evaluation interval
  interval: <duration>

  # Configure limit for number of alerts (0: no limit)
  # Optional, Default: 0 (no limit)
  limit: <int>

  # Configure record rules
  recordRules:
    # Define which timeseries to write to (must be a valid metric name)
  - record: <string>

    # Define PromQL expression to evaluate for this rule
    expr: <string>

    # Define labels to add or overwrite
    # Optional, Map of {key, value} pairs
    labels:
      <labelname>: <labelvalue>

  # Configure alert rules
  alertRules:
    # Define alert name 
  - alert: <string>

    # Define PromQL expression to evaluate for this rule
    # https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/
    expr: <string>

    # Define when an active alert moves from pending to firing
    # Optional, Default: 0s
    for: <duration>

    # Define labels to add or overwrite
    # Required, Map of {key, value} pairs
    # Required labels: 
    #     severity: [error, critical, warning, info]
    #     code: 
    #     resource: component/service/hardware related to alert
    #     additional labels are optional
    labels:
      severity: <enum: [error, critical, warning, info]>
      code: 
      resource: <Short name of the related operable component>
      <labelname>: <tmpl_string>

    # Define annotations to add
    # Optional, Map of {key, value} pairs
    # Recommended annotations:
    #     message: value of Message field in UI
    #     expression: value of Rule field in UI
    #     runbookurl: URL for link in Actions to take field in UI
    annotations:
      <labelname>: <tmpl_string>
# Configures either an alert or a target record for precomputation
apiVersion: logging.gdc.goog/v1alpha1
kind: LoggingRule
metadata:
  # Choose namespace that contains the logs that rules are based on
  # Note: alert/record will be produced in the same namespace
  namespace: g-fleetns-a
  name: alerting-config
spec:
  # Choose which log source to base alerts on (Operational/Audit/Security Logs)
  # Optional, Default: Operational
  source: <string>

  # Rule evaluation interval
  interval: <duration>

  # Configure limit for number of alerts (0: no limit)
  # Optional, Default: 0 (no limit)
  limit: <int>

  # Configure record rules
  recordRules:
    # Define which timeseries to write to (must be a valid metric name)
  - record: <string>

    # Define LogQL expression to evaluate for this rule
    # https://grafana.com/docs/loki/latest/rules/
    expr: <string>

    # Define labels to add or overwrite
    # Optional, Map of {key, value} pairs
    labels:
      <labelname>: <labelvalue>

  # Configure alert rules
  alertRules:
    # Define alert name
  - alert: <string>

    # Define LogQL expression to evaluate for this rule
    expr: <string>

    # Define when an active alert moves from pending to firing
    # Optional, Default: 0s
    for: <duration>

    # Define labels to add or overwrite
    # Required, Map of {key, value} pairs
    # Required labels: 
    #     severity: [error, critical, warning, info]
    #     code: 
    #     resource: component/service/hardware related to alert
    #     additional labels are optional
    labels:
      severity: <enum: [error, critical, warning, info]>
      code:
      resource: <Short name of the related operable component>
      <labelname>: <tmpl_string>

    # Define annotations to add
    # Optional, Map of {key, value} pairs
    # Recommended annotations:
    #     message: value of Message field in UI
    #     expression: value of Rule field in UI
    #     runbookurl: URL for link in Actions to take field in UI
    annotations:
      <labelname>: <tmpl_string>

透過 HTTP API 查詢快訊

可觀測性平台會公開 HTTP API 端點,用於查詢及讀取專案中的指標、快訊和其他時間序列資料,以監控系統。

直接透過 Observability HTTP API 查詢快訊,即可設定自動化工作、調整回應,以及根據您的用途建構整合項目。舉例來說,您可以將輸出內容插入其他指令、將詳細資料匯出為文字檔格式,或是設定 Linux Cron 工作。您可以從指令列介面 (CLI) 或網頁瀏覽器呼叫 Observability HTTP API,並以 JSON 格式取得結果。

本節說明如何使用 API 規格,從 CLI 呼叫 Observability HTTP API 端點來查詢快訊。

直接透過 Observability HTTP API 查詢快訊,即可設定自動化工作、調整回應,以及根據您的用途建構整合項目。舉例來說,您可以將輸出內容插入其他指令、將詳細資料匯出為文字檔格式,或是設定 Linux Cron 工作。您可以從指令列介面 (CLI) 或網頁瀏覽器呼叫 Observability HTTP API,並以 JSON 格式取得結果。

本節說明如何使用 Alertmanager API 規格,從 CLI 呼叫 Observability HTTP API 端點來查詢指標。

事前準備

如要取得存取 Observability HTTP API 端點所需的權限,請要求專案 IAM 管理員在專案命名空間中,授予您 Project Cortex Alertmanager 檢視者 (project-cortex-alertmanager-viewer) 角色。

專案 IAM 管理員可以建立角色繫結,授予您存取權:

a. 基礎架構運算子 (IO) 根管理員 - Project Cortex Alertmanager Viewer

kubectl --kubeconfig $HOME/root-admin-kubeconfig create rolebinding 
io-cortex-alertmanager-viewer-binding -n infra-obs 
--user=fop-infrastructure-operator@example.com 
--role=project-cortex-alertmanager-viewer

b. 平台管理員 (PA) 根管理員 - Project Cortex Alertmanager Viewer

kubectl --kubeconfig $HOME/root-admin-kubeconfig create rolebinding
pa-cortex-alertmanager-viewer-binding -n platform-obs 
--user=fop-platform-admin@example.com 
--role=project-cortex-alertmanager-viewer

c. 應用程式運算子 (AO) 根管理員 - Project Cortex Alertmanager 檢視者: 專案:$AO_PROJECT AO 使用者名稱:$AO_USER

kubectl --kubeconfig $HOME/root-admin-kubeconfig create rolebinding 
project-cortex-alertmanager-viewer-binding -n $AO_PROJECT 
--user=$AO_USER 
--role=project-cortex-alertmanager-viewer

建立角色繫結後,您可以使用登入使用者名稱存取對應的 Alertmanager。

驗證角色繫結

kubectl --kubeconfig $HOME/org-1-admin-kubeconfig get rolebinding -n platform-obs

如要瞭解如何透過 GDC 控制台設定角色繫結,請參閱「授予資源存取權」一文。

Cortex 端點

以下是存取快訊的 Cortex 端點網址:

https://GDC_URL/PROJECT_NAME/cortex/alertmanager/

更改下列內容:

  • GDC_URL:您在 GDC 中的機構網址。
  • PROJECT_NAME:專案名稱。

呼叫 API 端點

請按照下列步驟,從 CLI 存取 Cortex API 端點並查詢快訊:

  1. 確認符合必要條件
  2. 開啟 CLI。
  3. 使用 curl 工具呼叫 Cortex 端點網址,並使用標準 https://prometheus.io/docs/prometheus/latest/querying/api/#alertmanagers 擴充網址,以查詢快訊。例如:

    curl https://console.org-1.zone1.google.gdch.test/alice/cortex/alertmanager/api/v1/alertmanagers
    

您會在 CLI 中取得指令的輸出內容。API 回應格式為 JSON。