Google Cloud Monitoring - Get uptime check current status

Viewed 1707

I created an uptime check for my website. Then, I found this documentation page that shows how to extract information regarding the uptime check with C#.

After running the code:

public static object GetUptimeCheckConfig(string configName)
{
    var client = UptimeCheckServiceClient.Create();
    UptimeCheckConfig config = client.GetUptimeCheckConfig(configName);
    if (config == null)
    {
        Console.Error.WriteLine(
            "No configuration found with the name {0}", configName);
        return -1;
    }
    Console.WriteLine("Name: {0}", config.Name);
    Console.WriteLine("Display Name: {0}", config.DisplayName);
    Console.WriteLine("Http Path: {0}", config.HttpCheck.Path);
    return 0;
}

I found that this method provides information only about the configuration of the check. I want to get information about its current status (working good \ broken). Seems like this information is missing.

I also tried this REST call helper - the requested information is missing there too.

Is this possible to extract the current health status of the resource? Or I need to choose a more complex way to extract the data (e.g. via Webhooks)?

1 Answers

From GCP metrics docs:

To monitor the availability of a service, create an uptime check. These checks monitor the monitoring.googleapis.com/uptime_check/check_passed metric type. Don't configure an alerting policy to track a metric type such as compute.googleapis.com/instance/uptime if your goal is to monitor the availability of a service.

And then at uptime check docs:

To determine the status of your uptime checks using the API, monitor the metric monitoring.googleapis.com/uptime_check/check_passed. See Google Cloud metrics list for details.


Original answer:

Instead of GetUptimeCheckConfig you want to use timeSeries API.

You can try it in API explorer at https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.timeSeries/query

Request args:

projects/YOUR_PROJECT_ID

Request body:

{
  "query": "fetch uptime_url::monitoring.googleapis.com/uptime_check/request_latency | filter check_id = 'YOUR_CHECK_ID' | group_by [checker_location]"
}
  • * just make sure you replace YOUR_PROJECT_ID and YOUR_CHECK_ID with actual ids
Related