Get an uptime check
Stay organized with collections
Save and categorize content based on your preferences.
Demonstrates how to get details of an uptime check config.
Explore further
For detailed documentation that includes this code sample, see the following:
Code sample
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],[],[],[],null,["Demonstrates how to get details of an uptime check config.\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 GetUptimeCheckConfig(string configName)\n {\n var client = UptimeCheckServiceClient.Create();\n UptimeCheckConfig config = client.GetUptimeCheckConfig(configName);\n if (config == null)\n {\n Console.Error.WriteLine(\n \"No configuration found with the name {0}\", configName);\n return -1;\n }\n Console.WriteLine(\"Name: {0}\", config.Name);\n Console.WriteLine(\"Display Name: {0}\", config.DisplayName);\n Console.WriteLine(\"Http Path: {0}\", config.HttpCheck.Path);\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 // get is an example of getting an uptime check. resourceName should be\n // of the form `projects/[PROJECT_ID]/uptimeCheckConfigs/[UPTIME_CHECK_ID]`.\n func get(w io.Writer, resourceName string) (*monitoringpb.UptimeCheckConfig, error) {\n \tctx := context.Background()\n \tclient, err := monitoring.NewUptimeCheckClient(ctx)\n \tif err != nil {\n \t\treturn nil, fmt.Errorf(\"NewUptimeCheckClient: %w\", err)\n \t}\n \tdefer client.Close()\n \treq := &monitoringpb.GetUptimeCheckConfigRequest{\n \t\tName: resourceName,\n \t}\n \tconfig, err := client.GetUptimeCheckConfig(ctx, req)\n \tif err != nil {\n \t\treturn nil, fmt.Errorf(\"GetUptimeCheckConfig: %w\", err)\n \t}\n \tfmt.Fprintf(w, \"Config: %v\", config)\n \treturn config, 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 getUptimeCheckConfig(String checkName) throws IOException {\n // Create UptimeCheckServiceSettings instance for add retry mechanism\n UptimeCheckServiceSettings.Builder uptimeCheckServiceSettingsBuilder =\n UptimeCheckServiceSettings.newBuilder();\n uptimeCheckServiceSettingsBuilder\n .getUptimeCheckConfigSettings()\n .setRetrySettings(\n uptimeCheckServiceSettingsBuilder\n .getUptimeCheckConfigSettings()\n .getRetrySettings()\n .toBuilder()\n .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(100L))\n .setRetryDelayMultiplier(1.3)\n .setMaxRetryDelay(MAX_RECONNECT_BACKOFF_TIME)\n .setInitialRpcTimeout(MAX_RECONNECT_BACKOFF_TIME)\n .setRpcTimeoutMultiplier(1.0)\n .setMaxRpcTimeout(MAX_RECONNECT_BACKOFF_TIME)\n .setTotalTimeout(MAX_RECONNECT_BACKOFF_TIME)\n .setMaxAttempts(6)\n .build());\n UptimeCheckServiceSettings uptimeCheckServiceSettings =\n uptimeCheckServiceSettingsBuilder.build();\n\n // create UptimeCheckServiceClient with retry setting\n try (UptimeCheckServiceClient client =\n UptimeCheckServiceClient.create(uptimeCheckServiceSettings)) {\n UptimeCheckConfig config = client.getUptimeCheckConfig(checkName);\n if (config != null) {\n System.out.println(config.toString());\n } else {\n System.out.println(\"No uptime check config found with ID \" + checkName);\n }\n } catch (Exception e) {\n usage(\"Exception getting uptime check: \" + 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 // const uptimeCheckConfigId = 'YOUR_UPTIME_CHECK_CONFIG_ID';\n\n const request = {\n // i.e. name: 'projects/my-project-id/uptimeCheckConfigs/My-Uptime-Check\n name: client.projectUptimeCheckConfigPath(projectId, uptimeCheckConfigId),\n };\n\n console.log(`Retrieving ${request.name}`);\n\n // Retrieves an uptime check config\n const [uptimeCheckConfig] = await client.getUptimeCheckConfig(request);\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\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\\GetUptimeCheckConfigRequest;\n\n /**\n * Example:\n * ```\n * get_uptime_check($projectId, $configName);\n * ```\n *\n * @param string $projectId Your project ID\n * @param string $configName\n */\n function get_uptime_check($projectId, $configName)\n {\n $uptimeCheckClient = new UptimeCheckServiceClient([\n 'projectId' =\u003e $projectId,\n ]);\n $getUptimeCheckConfigRequest = (new GetUptimeCheckConfigRequest())\n -\u003esetName($configName);\n\n $uptimeCheck = $uptimeCheckClient-\u003egetUptimeCheckConfig($getUptimeCheckConfigRequest);\n\n print('Retrieved an uptime check:' . PHP_EOL);\n print($uptimeCheck-\u003eserializeToJsonString() . PHP_EOL);\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 get_uptime_check_config(config_name: str) -\u003e uptime.UptimeCheckConfig:\n \"\"\"Reads the uptime check configuration\n\n Args:\n config_name: Uptime check configuration identity\n\n Returns:\n A structure that describes the updated uptime check\n \"\"\"\n client = monitoring_v3.UptimeCheckServiceClient()\n config = client.get_uptime_check_config(request={\"name\": config_name})\n pprint.pprint(config)\n return config\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 get_uptime_check_config config_name\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 config = client.get_uptime_check_config name: config_name\n pp config.to_h\n config\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)."]]