Répertorier les tests de disponibilité
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Explique comment répertorier les configurations des tests de disponibilité.
En savoir plus
Pour obtenir une documentation détaillée incluant cet exemple de code, consultez les articles suivants :
Exemple de code
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","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)."]]