Metrics: search

Requires authorization

Search the metrics that match the given terms. 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/search

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.
term string The regular expression terms that used to match the metric. Multiple terms are joined by Boolean And.

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#searchMetricResponse",
  "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#searchMetricResponse".
metric[] list The returned metrics.
totalResults long Total number of metrics found by this search. 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 {

  // ...

  /**
   * Search for Timeseries metrics by name.
   *
   * @param service Client Monitoring API service instance.
   * @param projectName The name of the project to get monitoring data about.
   * @param searchTerm The regular expression terms to use in the search. Multiple terms are joined with the Boolean "And"
   */
  private static void searchMetrics(Clientmonitoring service, String projectName,
      String searchTerm) {
    Metrics metrics = new Metrics();
    metrics.setProject(projectName);
    metrics.setTerm(searchTerm);

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

  // ...

}

Python

Uses the Python client library.

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

Ruby

Uses the Ruby client library.

##
# Search for Timeseries metrics by name.
#
# @param [Google::APIClient] client
#   Authorized client instance.
# @param [String] project_name
#   The name of the project to get monitoring data about.
# @param [String] search_term
#   The regular expression terms to use in the search. Multiple terms are joined with the Boolean "And"
def search_metrics(client, project_name, search_term)
  cloudmonitoring = client.discovered_api('cloudmonitoring', 'v2beta1')
  result = client.execute(
    :api_method => cloudmonitoring.metrics.search,
    :body_object => { 'project' => project_name, 'term' => search_term })
  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.search({
    'project': projectName,
    'term': searchTerm
  });
  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.

Send feedback about...

Stackdriver Monitoring