本文說明如何使用Google Cloud 控制台、Google Cloud CLI、Cloud Monitoring API 和用戶端程式庫,管理正常運作時間檢查。
這項功能僅支援 Google Cloud 專案。 如要進行 App Hub 設定,請選取 App Hub 主專案或啟用應用程式的資料夾管理專案。
事前準備
在儲存運作時間檢查的 Google Cloud 專案中完成下列步驟:
-
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloud
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
-
前往 Google Cloud 控制台的「運作時間檢查」
頁面:
如果您是使用搜尋列尋找這個頁面,請選取子標題為「Monitoring」的結果。
以下範例顯示「運作時間檢查」頁面:
在 Google Cloud 控制台的工具列中,選取您的 Google Cloud 專案。如為「App Hub」設定,請選取 App Hub 主機專案或已啟用應用程式的資料夾管理專案。
(選用) 如要限制列出的正常運作時間檢查,請新增篩選條件。
每個篩選條件都包含名稱和值。您可以將值設為與運作時間檢查名稱完全相符,或部分相符。比對作業不會區分大小寫。舉例來說,如要列出名稱包含
default
的所有運作時間檢查,請執行下列操作:- 按一下「篩選表格」,然後選取「顯示名稱」。
- 輸入
default
,然後按下 Return 鍵。
如有多個篩選器,系統會自動以邏輯
AND
聯集篩選器合併,除非您插入OR
篩選器。上一個範例使用OR
篩選器,因此如果正常運作時間檢查的名稱符合default
或Testing check
,就會列出該檢查。- PROJECT_ID:專案的 ID。如要進行 App Hub 設定,請選取 App Hub 主專案或啟用應用程式的資料夾管理專案。
- 名稱和顯示名稱。
- 檢查 ID。
- 受監控資源。
- 檢查之間的時間間隔。
父項:必填。列出運作時間檢查的專案。 如要進行 App Hub 設定,請選取 App Hub 主專案或啟用應用程式的資料夾管理專案。這個欄位的格式如下:
projects/PROJECT_ID
-
前往 Google Cloud 控制台的「運作時間檢查」
頁面:
如果您是使用搜尋列尋找這個頁面,請選取子標題為「Monitoring」的結果。
- 在 Google Cloud 控制台的工具列中,選取您的 Google Cloud 專案。如為「App Hub」設定,請選取 App Hub 主機專案或已啟用應用程式的資料夾管理專案。
找出要查看的運作時間檢查,然後按一下其名稱。
下方的螢幕截圖顯示名稱為「Testing check」的運作時間檢查詳細資料:
「正常運作時間詳細資料」頁面包含下列資訊:
- 選取的時間間隔。預設間隔為 1 小時。
- 運作時間檢查的名稱。在範例中,名稱為「Testing check」。
- 您為運作時間檢查新增的標籤。
正常運作時間百分比和平均延遲時間。「運作時間百分比」值是以
(S/T)*100
計算的百分比,其中S
是所有位置的成功檢查回應數;T
是所有位置的檢查回應總數。如果是群組檢查,則S
與T
的值會是當下所有群組成員的加總。舉例來說,如果從所有地區執行每分鐘一次的正常運作時間檢查,在 25 分鐘內,6 個位置各會發出 25 個要求,總共 150 個要求。如果資訊主頁回報的正常運作時間為 83.3%,則表示 150 個要求中有 125 個成功。
「通過的檢查」和「運作時間檢查延遲」窗格會以圖形顯示通過的檢查次數,以及每次檢查的延遲時間 (以時間為函式)。
「目前狀態」窗格會顯示最近一次檢查的狀態。 如果區域旁邊顯示綠色圓圈和勾號,表示該區域的檢查上次執行成功;如果顯示紅色圓圈和 X,則表示失敗。如果您已啟用運作時間檢查失敗情形記錄,窗格中會顯示「查看記錄」連結。
「Configuration」(設定) 窗格會顯示運作時間檢查的設定。 這項資料會在建立運作時間檢查時指派。 「檢查 ID」值對應於 API 呼叫中的
CHECK_ID
值。「快訊政策」窗格會列出相關聯的快訊政策資訊。在範例資訊主頁中,已設定一項快訊政策。
- PROJECT_ID:專案的 ID。如要進行 App Hub 設定,請選取 App Hub 主專案或啟用應用程式的資料夾管理專案。
- CHECK_ID:運作時間檢查或綜合監控的 ID。執行
gcloud monitoring uptime list-configs
指令並檢查 name 欄位,即可找出 ID。詳情請參閱找出運作時間檢查的專屬 ID。 - 名稱和顯示名稱。
- 檢查 ID。
- 受監控資源。
- 檢查之間的時間間隔。
名稱:運作時間檢查設定的完整名稱。
projects/PROJECT_ID/uptimeCheckConfigs/CHECK_ID
在上述運算式中:
PROJECT_ID 是儲存運作時間檢查的專案。如要進行 App Hub 設定,請選取 App Hub 主專案或啟用應用程式的資料夾管理專案。
CHECK_ID 是運作時間檢查或合成監控項的 ID。詳情請參閱找出運作時間檢查的專屬 ID。
-
前往 Google Cloud 控制台的「運作時間檢查」
頁面:
如果您是使用搜尋列尋找這個頁面,請選取子標題為「Monitoring」的結果。
- 在 Google Cloud 控制台的工具列中,選取您的 Google Cloud 專案。如為「App Hub」設定,請選取 App Hub 主機專案或已啟用應用程式的資料夾管理專案。
找出要編輯的運作時間檢查,然後執行下列其中一項操作:
- 按一下「更多」圖示 more_vert,然後選取「編輯」。
- 查看正常運作時間檢查詳細資料,然後按一下「編輯」。
視需要變更欄位的值。您無法修改所有欄位。如果檢查的自訂標頭值為隱藏狀態,即表示您無法查看這些值。
如要確認檢查狀態,請按一下「測試」。如果測試失敗,請參閱「檢查失敗」瞭解可能原因。
按一下 [儲存]。
- PROJECT_ID:專案的 ID。如要進行 App Hub 設定,請選取 App Hub 主專案或啟用應用程式的資料夾管理專案。
- CHECK_ID:運作時間檢查或綜合監控的 ID。執行
gcloud monitoring uptime list-configs
指令並檢查 name 欄位,即可找出 ID。詳情請參閱找出運作時間檢查的專屬 ID。 uptimeCheckConfig.name:必填。這是 REST 網址的一部分。這是要編輯的運作時間檢查的資源名稱:
projects/PROJECT_ID/uptimeCheckConfigs/CHECK_ID
在上述運算式中:
PROJECT_ID 是儲存運作時間檢查的專案。如要進行 App Hub 設定,請選取 App Hub 主專案或啟用應用程式的資料夾管理專案。
CHECK_ID 是運作時間檢查或合成監控項的 ID。詳情請參閱找出運作時間檢查的專屬 ID。
updateMask:選填。這是查詢參數:
?updateMask=[FIELD_LIST]
。[FIELD_LIST]
是UptimeCheckConfig
物件中應進行變更的逗號分隔欄位清單。例如:"resource.type,httpCheck.path"
要求主體必須包含
UptimeCheckConfig
與新的欄位值。- PROJECT_ID:專案的 ID。如要進行 App Hub 設定,請選取 App Hub 主專案或啟用應用程式的資料夾管理專案。
- CHECK_ID:運作時間檢查或綜合監控的 ID。執行
gcloud monitoring uptime list-configs
指令並檢查 name 欄位,即可找出 ID。詳情請參閱找出運作時間檢查的專屬 ID。 名稱:必填。這是要刪除運作時間檢查設定的資源名稱:
projects/PROJECT_ID/uptimeCheckConfigs/CHECK_ID
在上述運算式中:
PROJECT_ID 是儲存運作時間檢查的專案。如要進行 App Hub 設定,請選取 App Hub 主專案或啟用應用程式的資料夾管理專案。
CHECK_ID 是運作時間檢查或合成監控項的 ID。詳情請參閱找出運作時間檢查的專屬 ID。
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
C#
如要在本機開發環境中使用本頁的 .NET 範例,請安裝並初始化 gcloud CLI,然後使用使用者憑證設定應用程式預設憑證。
詳情請參閱 Google Cloud 驗證說明文件中的「 為本機開發環境設定 ADC」。
Go
如要在本機開發環境中使用本頁的 Go 範例,請安裝並初始化 gcloud CLI,然後使用使用者憑證設定應用程式預設憑證。
詳情請參閱 Google Cloud 驗證說明文件中的「 為本機開發環境設定 ADC」。
Java
如要在本機開發環境中使用本頁的 Java 範例,請安裝並初始化 gcloud CLI,然後使用使用者憑證設定應用程式預設憑證。
詳情請參閱 Google Cloud 驗證說明文件中的「 為本機開發環境設定 ADC」。
Node.js
如要在本機開發環境中使用本頁的 Node.js 範例,請安裝並初始化 gcloud CLI,然後使用使用者憑證設定應用程式預設憑證。
詳情請參閱 Google Cloud 驗證說明文件中的「 為本機開發環境設定 ADC」。
PHP
如要在本機開發環境中使用本頁的 PHP 範例,請安裝並初始化 gcloud CLI,然後使用使用者憑證設定應用程式預設憑證。
詳情請參閱 Google Cloud 驗證說明文件中的「 為本機開發環境設定 ADC」。
Python
如要在本機開發環境中使用本頁的 Python 範例,請安裝並初始化 gcloud CLI,然後使用使用者憑證設定應用程式預設憑證。
詳情請參閱 Google Cloud 驗證說明文件中的「 為本機開發環境設定 ADC」。
Ruby
如要在本機開發環境中使用本頁的 Ruby 範例,請安裝並初始化 gcloud CLI,然後使用使用者憑證設定應用程式預設憑證。
詳情請參閱 Google Cloud 驗證說明文件中的「 為本機開發環境設定 ADC」。
REST
如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
詳情請參閱 Google Cloud 驗證說明文件中的「Authenticate for using REST」。
列出所有運作時間檢查
控制台
gcloud
如要列出運作時間檢查和綜合監控,請執行
gcloud monitoring uptime list-configs
指令:gcloud monitoring uptime list-configs --project=PROJECT_ID
執行上一個指令前,請先取代下列項目:
傳回的資料包括:
您可以設定 Google Cloud CLI 指令,篩選及排序結果。
REST
如要列出運作時間檢查和綜合監控,請呼叫
projects.uptimeCheckConfigs.list
方法。請指定以下參數:C#
如要驗證 Monitoring,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Java
如要驗證 Monitoring,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Go
如要驗證 Monitoring,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Node.js
如要驗證 Monitoring,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
PHP
如要驗證 Monitoring,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Python
如要驗證 Monitoring,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Ruby
如要驗證 Monitoring,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
查看運作時間檢查的詳細資料
控制台
gcloud
如要列出正常運作時間檢查或綜合監控的詳細資料,請執行
gcloud monitoring uptime describe
指令:gcloud monitoring uptime describe CHECK_ID --project=PROJECT_ID
執行上一個指令前,請先取代下列項目:
運作時間檢查傳回的資料包括:
REST
如要列出運作時間檢查或綜合監控的詳細資料,請呼叫
projects.uptimeCheckConfigs.get
方法。請指定以下參數:C#
如要驗證 Monitoring,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Java
如要驗證 Monitoring,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Go
如要驗證 Monitoring,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Node.js
如要驗證 Monitoring,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
PHP
如要驗證 Monitoring,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Python
如要驗證 Monitoring,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Ruby
如要驗證 Monitoring,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
編輯運作時間檢查
您可以修改運作時間檢查的部分欄位。舉例來說,您可能希望檢查更頻繁地發生,或是想增加與驗證回應相關的逾時。不過,如果運作時間檢查設定的通訊協定、資源類型或資源有誤,請刪除目前的運作時間檢查,然後建立新的檢查。
如要瞭解如何編輯監控運作時間檢查的快訊政策,請參閱下列文件:
如要編輯公開運作時間檢查,請使用下列任一分頁中的程序。如要編輯私人正常運作時間檢查,請使用「控制台」或「API」分頁:
控制台
gcloud
如要修改運作時間檢查或綜合監控,請執行
gcloud monitoring uptime update
指令:gcloud monitoring uptime update CHECK_ID OPTIONAL_FLAGS --project=PROJECT_ID
執行上一個指令前,請先取代下列項目:
您也必須定義要修改的欄位。
舉例來說,如要將運作時間檢查的週期設為 10 分鐘,請執行下列指令:
gcloud monitoring uptime update CHECK_ID --period=10
REST
呼叫
projects.uptimeCheckConfigs.patch
方法。如下設定方法的參數:如果設定了
updateMask
,則只有updateMask
中列出的欄位會取代現有設定中的對應欄位。如果欄位有子欄位,且欄位列於欄位遮罩中,但沒有任何一個子欄位列於欄位遮罩中,則該欄位的所有子欄位都會取代對應欄位。如果未設定
updateMask
,則要求主體中的設定會取代整個現有設定。patch
方法會針對已更改的設定傳回UptimeCheckConfig
物件。C#
如要驗證 Monitoring,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Java
如要驗證 Monitoring,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Go
如要驗證 Monitoring,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Node.js
如要驗證 Monitoring,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
PHP
如要驗證 Monitoring,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Python
如要驗證 Monitoring,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Ruby
如要驗證 Monitoring,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
在您看見新的運作時間檢查結果之前,可能會有長達 5 分鐘的延遲。在該期間,先前運作時間檢查的結果會顯示在資訊主頁中,並在快訊政策中使用。
刪除運作時間檢查
建議您在關閉服務或資源時,刪除運作時間檢查。
如要刪除運作時間檢查,請執行下列操作:
控制台
gcloud
如要刪除運作時間檢查或合成監控,請執行
gcloud monitoring uptime delete
指令:gcloud monitoring uptime delete CHECK_ID --project=PROJECT_ID
執行上一個指令前,請先取代下列項目:
REST
如要刪除運作時間檢查或合成監控項,請呼叫
projects.uptimeCheckConfigs.delete
方法。如下填寫參數:C#
如要驗證 Monitoring,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Java
如要驗證 Monitoring,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Go
如要驗證 Monitoring,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Node.js
如要驗證 Monitoring,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
PHP
如要驗證 Monitoring,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Python
如要驗證 Monitoring,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Ruby
如要驗證 Monitoring,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
監控運作時間檢查
建議您建立快訊政策,以便在運作時間檢查失敗時收到通知。詳情請參閱「為運作時間檢查建立快訊政策」。
找出運作時間檢查的專屬 ID
建立運作時間檢查時,Monitoring 會指派一個 ID,稱為運作時間檢查 ID。此 ID 會嵌入到運作時間檢查的資源名稱內:
projects/PROJECT_ID/uptimeCheckConfigs/CHECK_ID
PROJECT_ID 是儲存正常運作時間檢查的專案 ID。如要進行 App Hub 設定,請選取 App Hub 主專案或啟用應用程式的資料夾管理專案。
建立或列出運作時間檢查的 Cloud Monitoring API 方法,都會在回應中納入運作時間檢查 ID。您也可以在Google Cloud 主控台的「運作時間詳細資料」頁面中,找到「設定」窗格內的運作時間檢查 ID。如要瞭解如何查看「運作時間詳細資料」頁面,請參閱本文的「查看運作時間檢查的詳細資料」一節。
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-11 (世界標準時間)。
-