本頁提供詳細操作說明,介紹如何使用 GDC 控制台和 Cortex 端點的 curl
工具查詢及顯示未解決的快訊,以便掌握問題並解決問題。
根據 Google Distributed Cloud (GDC) 氣隙裝置環境的記錄和指標建立快訊規則後,即可開始監控專案中的未解決快訊。您可以在 GDC 控制台上查看及篩選系統事件觸發的快訊,也可以使用 curl
工具,直接從 Cortex 存取快訊,靈活編寫指令碼及自動化。
您可以透過下列兩種方法存取未結警報:
- GDC 控制台:在整合式面板中以視覺化方式呈現快訊資料,包括特定資料來源的快訊數量、嚴重程度、持續時間、狀態、訊息和標籤等資訊。GDC 控制台提供簡單易用的介面,可供您篩選及分析系統元件的快訊。
- Cortex Alertmanager 端點:如要處理更進階的用途,請在指令列上使用
curl
工具,直接查詢專案的 Cortex 執行個體。Cortex 會儲存專案的 Alertmanager 快訊,並提供 HTTP 端點供程式輔助存取。您可透過這項存取權匯出資料、自動執行工作、設定 Cron 工作,以及建構自訂整合功能。
事前準備
如要取得查詢及顯示快訊所需的權限,請要求專案 IAM 管理員在專案命名空間中,授予您其中一個相關聯的 Project Cortex Alertmanager 角色。視您需要的存取層級和權限而定,您或許可以在專案中取得這項資源的編輯者或檢視者角色。
如要取得匯出記錄所需的權限,請要求專案 IAM 管理員授予您專案 Grafana 檢視者 (project-grafana-viewer
) 角色。透過這個角色型存取控管程序,您可以安全地存取資料視覺化內容。如要進一步瞭解這些角色,請參閱「準備 IAM 權限」。
Grafana 端點
應用程式營運人員 (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」(快訊 - 總覽) 資訊主頁。
查看及篩選未結警告
選取下列其中一種方法,從專案命名空間查詢及篩選未解決的快訊:
主控台
在 GDC 控制台中查看專案中尚未解決的警告:
- 登入 GDC 控制台。
- 在 GDC 控制台中選取專案。
- 在導覽選單中,依序選取「Operations」>「Alerting」。
- 選取「快訊」分頁標籤。
- 查看快訊清單。
- 在「開啟的快訊」部分中,按一下「篩選器」,即可只顯示開啟的快訊。您也可以依其他屬性名稱或值篩選快訊。
- 按一下快訊名稱即可查看快訊詳細資料。
Cortex 端點
本節說明如何使用 Cortex Alertmanager 端點存取快訊。
找出 Cortex 端點
以下網址是專案 Cortex 執行個體的端點:
https://GDC_URL/PROJECT_NAMESPACE/cortex/alertmanager/
更改下列內容:
GDC_URL
:您在 GDC 中的機構網址。PROJECT_NAMESPACE
:您的專案命名空間。舉例來說,
org-1
機構中platform-obs
專案的 Cortex 端點為https://org-1/platform-obs/cortex/alertmanager/
。
驗證 curl
要求
- 下載並安裝 gdcloud CLI。
設定 gdcloud
core/organization_console_url
屬性:gdcloud config set core/organization_console_url https://GDC_URL
-
gdcloud auth login
使用使用者名稱和密碼進行驗證並登入。
登入成功後,您可以使用
gdcloud auth print-identity-token
指令,在 cURL 要求中加入授權標頭。詳情請參閱 gdcloud auth。
呼叫 Cortex 端點
如要使用 curl
工具連上 Cortex 端點,請完成下列步驟:
- 驗證
curl
要求。 使用
curl
呼叫 Cortex 端點,並使用標準 Alertmanager API 規格 (https://prometheus.io/docs/prometheus/latest/querying/api/#alertmanagers) 擴充網址,以查詢快訊。以下是
curl
要求範例:curl https://GDC_URL/PROJECT_NAME/cortex/alertmanager/api/v1/alertmanagers \ -H "Authorization: Bearer $(gdcloud auth print-identity-token \ --audiences=https://GDC_URL)"
執行指令後,您會取得輸出內容。API 回應採用 JSON 格式。
Alertmanager
Alertmanager 可讓你監控用戶端應用程式的警示通知。您可以使用 Alertmanager 檢查及關閉快訊,並篩選或分組快訊:
圖 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 端點並查詢快訊:
- 確認符合必要條件。
- 開啟 CLI。
使用
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。