Metrics: list

Requires authorization

List all of the available metrics. Large number of metrics will be paginated, use the nextPageToken returned in the response to request subsequent pages of results by setting the pageToken query parameter to the value of the nextPageToken. Try it now or see an example.

Request

HTTP request

GET https://www.googleapis.com/cloudmonitoring/v2beta1/project/metrics

Parameters

Parameter name Value Description
Path parameters
project string The project id. The value can be the numeric project ID or string-based project name.
Optional query parameters
count integer Maximum number of metrics per page. Used for pagination. If not specified, count = 100. Acceptable values are 1 to 1000, inclusive. (Default: 100)
pageToken string The pagination token, which is used to page through large result sets. Set this value to the value of the nextPageToken to retrieve the next page of results.

Authorization

This request requires authorization with the following scope (read more about authentication and authorization).

Scope
https://www.googleapis.com/auth/monitoring

Request body

Do not supply a request body with this method.

Response

If successful, this method returns a response body with the following structure:

{
  "kind": "cloudmonitoring#listMetricResponse",
  "metric": [
    metrics Resource
  ],
  "totalResults": long,
  "nextPageToken": string
}
Property name Value Description Notes
kind string Identifies what kind of resource this is. Value: the fixed string "cloudmonitoring#listMetricResponse".
metric[] list The returned metrics.
totalResults long Total number of available metrics. Since results are paginated, some metrics might not be included in this response page.
nextPageToken string Pagination token. If present, indicates that additional results are available for retrieval. To access the results past the pagination limit, set this value to the pageToken query parameter.

Examples

Note: The code examples available for this method do not represent all supported programming languages (see the client libraries page for a list of supported languages).

Java

Uses the Java client library.

import com.google.api.services.clientmonitoring.Clientmonitoring;
import com.google.api.services.clientmonitoring.model.Metrics;

import java.io.IOException;

// ...

public class MyClass {

  // ...

  /**
   * List all of the available metrics
   *
   * @param service Client Monitoring API service instance.
   * @param projectName The name of the project to get monitoring data about.
   */
  private static void listMetrics(Clientmonitoring service, String projectName) {
    Metrics metrics = new Metrics();
    metrics.setProject(projectName);

    try {
      service.metrics().list(metrics).execute();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }

  // ...

}

Python

Uses the Python client library.

body = {
    'project': projectName
  }
  try:
    return service.metrics().list(body=body).execute()
  except errors.HttpError, error:
    print 'An error occurred: %s' % error

Ruby

Uses the Ruby client library.

##
# List all of the available metrics
#
# @param [Google::APIClient] client
#   Authorized client instance.
# @param [String] project_name
#   The name of the project to get monitoring data about.

def list_metrics(client, project_name)
  cloudmonitoring = client.discovered_api('cloudmonitoring', 'v2beta1')
  result = client.execute(
    :api_method => cloudmonitoring.metrics.list,
    :body_object => { 'project' => project_name })
  if result.error?
    puts "An error occurred: #{result.data['error']['message']}"
  end
end

JavaScript

Uses the JavaScript client library.

gapi.client.load('cloudmonitoring', 'v2beta1', function() {
  var request = gapi.client.cloudmonitoring.metrics.list({
    'project': projectName
  });
  request.execute(function(resp){ });
});

Try it!

Use the APIs Explorer below to call this method on live data and see the response. Alternatively, try the standalone Explorer.

Monitor your resources on the go

Get the Google Cloud Console app to help you manage your projects.

Send feedback about...

Stackdriver Monitoring