列出運作時間檢查
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
說明如何列出運作時間檢查設定。
深入探索
如需包含這個程式碼範例的詳細說明文件,請參閱下列內容:
程式碼範例
Node.js
如要驗證 Monitoring,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
Python
如要驗證 Monitoring,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],[],[],[],null,["Demonstrates how to list uptime check configs.\n\nExplore further\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Manage uptime checks](/monitoring/uptime-checks/manage)\n\nCode sample \n\nC#\n\n\nTo authenticate to Monitoring, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n public static object ListUptimeCheckConfigs(string projectId)\n {\n var client = UptimeCheckServiceClient.Create();\n var configs = client.ListUptimeCheckConfigs(new ProjectName(projectId));\n foreach (UptimeCheckConfig config in configs)\n {\n Console.WriteLine(config.Name);\n }\n return 0;\n }\n\nGo\n\n\nTo authenticate to Monitoring, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n\n // list is an example of listing the uptime checks in projectID.\n func list(w io.Writer, projectID string) error {\n \tctx := context.Background()\n \tclient, err := monitoring.NewUptimeCheckClient(ctx)\n \tif err != nil {\n \t\treturn fmt.Errorf(\"NewUptimeCheckClient: %w\", err)\n \t}\n \tdefer client.Close()\n \treq := &monitoringpb.ListUptimeCheckConfigsRequest{\n \t\tParent: \"projects/\" + projectID,\n \t}\n \tit := client.ListUptimeCheckConfigs(ctx, req)\n \tfor {\n \t\tconfig, err := it.Next()\n \t\tif err == iterator.Done {\n \t\t\tbreak\n \t\t}\n \t\tif err != nil {\n \t\t\treturn fmt.Errorf(\"ListUptimeCheckConfigs: %w\", err)\n \t\t}\n \t\tfmt.Fprintln(w, config)\n \t}\n \tfmt.Fprintln(w, \"Done listing uptime checks\")\n \treturn nil\n }\n\nJava\n\n\nTo authenticate to Monitoring, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n private static void listUptimeChecks(String projectId) throws IOException {\n ListUptimeCheckConfigsRequest request =\n ListUptimeCheckConfigsRequest.newBuilder().setParent(ProjectName.format(projectId)).build();\n try (UptimeCheckServiceClient client = UptimeCheckServiceClient.create()) {\n ListUptimeCheckConfigsPagedResponse response = client.listUptimeCheckConfigs(request);\n for (UptimeCheckConfig config : response.iterateAll()) {\n System.out.println(config.getDisplayName());\n }\n } catch (Exception e) {\n usage(\"Exception listing uptime checks: \" + e.toString());\n throw e;\n }\n }\n\nNode.js\n\n\nTo authenticate to Monitoring, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n // Imports the Google Cloud client library\n const monitoring = require('https://cloud.google.com/nodejs/docs/reference/monitoring/latest/overview.html');\n\n // Creates a client\n const client = new monitoring.https://cloud.google.com/nodejs/docs/reference/monitoring/latest/overview.html();\n\n /**\n * TODO(developer): Uncomment and edit the following lines of code.\n */\n // const projectId = 'YOUR_PROJECT_ID';\n\n const request = {\n parent: client.projectPath(projectId),\n };\n\n // Retrieves an uptime check config\n const [uptimeCheckConfigs] = await client.listUptimeCheckConfigs(request);\n\n uptimeCheckConfigs.forEach(uptimeCheckConfig =\u003e {\n console.log(`ID: ${uptimeCheckConfig.name}`);\n console.log(` Display Name: ${uptimeCheckConfig.displayName}`);\n console.log(' Resource: %j', uptimeCheckConfig.monitoredResource);\n console.log(' Period: %j', uptimeCheckConfig.period);\n console.log(' Timeout: %j', uptimeCheckConfig.timeout);\n console.log(` Check type: ${uptimeCheckConfig.check_request_type}`);\n console.log(\n ' Check: %j',\n uptimeCheckConfig.httpCheck || uptimeCheckConfig.tcpCheck\n );\n console.log(\n ` Content matchers: ${uptimeCheckConfig.contentMatchers\n .map(matcher =\u003e matcher.content)\n .join(', ')}`\n );\n console.log(` Regions: ${uptimeCheckConfig.selectedRegions.join(', ')}`);\n });\n\nPHP\n\n\nTo authenticate to Monitoring, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n use Google\\Cloud\\Monitoring\\V3\\Client\\UptimeCheckServiceClient;\n use Google\\Cloud\\Monitoring\\V3\\ListUptimeCheckConfigsRequest;\n\n /**\n * Example:\n * ```\n * list_uptime_checks($projectId);\n * ```\n */\n function list_uptime_checks(string $projectId): void\n {\n $projectName = 'projects/' . $projectId;\n $uptimeCheckClient = new UptimeCheckServiceClient([\n 'projectId' =\u003e $projectId,\n ]);\n $listUptimeCheckConfigsRequest = (new ListUptimeCheckConfigsRequest())\n -\u003esetParent($projectName);\n\n $pages = $uptimeCheckClient-\u003elistUptimeCheckConfigs($listUptimeCheckConfigsRequest);\n\n foreach ($pages-\u003eiteratePages() as $page) {\n foreach ($page as $uptimeCheck) {\n print($uptimeCheck-\u003egetName() . PHP_EOL);\n }\n }\n }\n\nPython\n\n\nTo authenticate to Monitoring, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n def list_uptime_check_configs(project_id: str) -\u003e pagers.ListUptimeCheckConfigsPager:\n \"\"\"Gets all uptime checks defined in the Google Cloud project\n\n Args:\n project_id: Google Cloud project id\n\n Returns:\n A list of configurations.\n Iterating over this object will yield results and resolve additional pages automatically.\n \"\"\"\n client = monitoring_v3.UptimeCheckServiceClient()\n configs = client.list_uptime_check_configs(request={\"parent\": project_id})\n\n for config in configs:\n pprint.pprint(config)\n return configs\n\nRuby\n\n\nTo authenticate to Monitoring, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n gem \"google-cloud-monitoring\"\n require \"google/cloud/monitoring\"\n\n def list_uptime_check_configs project_id\n client = Google::Cloud::https://cloud.google.com/ruby/docs/reference/google-cloud-monitoring/latest/Google-Cloud-Monitoring.html.https://cloud.google.com/ruby/docs/reference/google-cloud-monitoring/latest/Google-Cloud-Monitoring.html\n project_name = client.project_path project: project_id\n configs = client.list_uptime_check_configs parent: project_name\n\n configs.each { |config| puts config.name }\n end\n\nWhat's next\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=monitoring)."]]