MetricServiceClient

MetricServiceClient

Manages metric descriptors, monitored resource descriptors, and time series data.

Constructor

new MetricServiceClient(optionsopt)

Construct an instance of MetricServiceClient.

Parameters:
Name Type Attributes Description
options object <optional>

The configuration object. See the subsequent parameters for more details.

Properties
Name Type Attributes Description
credentials object <optional>

Credentials object.

Properties
Name Type Attributes Description
client_email string <optional>
private_key string <optional>
email string <optional>

Account email address. Required when using a .pem or .p12 keyFilename.

keyFilename string <optional>

Full path to the a .json, .pem, or .p12 key downloaded from the Google Developers Console. If you provide a path to a JSON file, the projectId option below is not necessary. NOTE: .pem and .p12 require you to specify options.email as well.

port number <optional>

The port on which to connect to the remote host.

projectId string <optional>

The project ID from the Google Developer's Console, e.g. 'grape-spaceship-123'. We will also check the environment variable GCLOUD_PROJECT for your project ID. If your app is running in an environment which supports Application Default Credentials, your project ID will be detected automatically.

promise function <optional>

Custom promise module to use instead of native Promises.

apiEndpoint string <optional>

The domain name of the API remote host.

Source:

Members

(static) apiEndpoint

The DNS address for this API service - same as servicePath(), exists for compatibility reasons.

Source:

(static) port

The port for this API service.

Source:

(static) scopes

The scopes needed to make gRPC calls for every method defined in this service.

Source:

(static) servicePath

The DNS address for this API service.

Source:

Methods

createMetricDescriptor(request, optionsopt, callbackopt) → {Promise}

Creates a new metric descriptor. User-created metric descriptors define custom metrics.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
name string

The project on which to execute the request. The format is "projects/{project_id_or_number}".

metricDescriptor Object

The new custom metric descriptor.

This object should have the same structure as MetricDescriptor

options Object <optional>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback function <optional>

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing MetricDescriptor.

Source:
Example
const monitoring = require('@google-cloud/monitoring');

const client = new monitoring.v3.MetricServiceClient({
  // optional auth parameters.
});

const formattedName = client.projectPath('[PROJECT]');
const metricDescriptor = {};
const request = {
  name: formattedName,
  metricDescriptor: metricDescriptor,
};
client.createMetricDescriptor(request)
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

createTimeSeries(request, optionsopt, callbackopt) → {Promise}

Creates or adds data to one or more time series. The response is empty if all time series in the request were written. If any time series could not be written, a corresponding failure message is included in the error response.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
name string

The project on which to execute the request. The format is "projects/{project_id_or_number}".

timeSeries Array.<Object>

The new data to be added to a list of time series. Adds at most one data point to each of several time series. The new data point must be more recent than any other point in its time series. Each TimeSeries value must fully specify a unique time series by supplying all label values for the metric and the monitored resource.

The maximum number of TimeSeries objects per Create request is 200.

This object should have the same structure as TimeSeries

options Object <optional>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback function <optional>

The function which will be called with the result of the API call.

Source:
Example
const monitoring = require('@google-cloud/monitoring');

const client = new monitoring.v3.MetricServiceClient({
  // optional auth parameters.
});

const formattedName = client.projectPath('[PROJECT]');
const timeSeries = [];
const request = {
  name: formattedName,
  timeSeries: timeSeries,
};
client.createTimeSeries(request).catch(err => {
  console.error(err);
});

deleteMetricDescriptor(request, optionsopt, callbackopt) → {Promise}

Deletes a metric descriptor. Only user-created custom metrics can be deleted.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
name string

The metric descriptor on which to execute the request. The format is "projects/{project_id_or_number}/metricDescriptors/{metric_id}". An example of {metric_id} is: "custom.googleapis.com/my_test_metric".

options Object <optional>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback function <optional>

The function which will be called with the result of the API call.

Source:
Example
const monitoring = require('@google-cloud/monitoring');

const client = new monitoring.v3.MetricServiceClient({
  // optional auth parameters.
});

const formattedName = client.metricDescriptorPath('[PROJECT]', '[METRIC_DESCRIPTOR]');
client.deleteMetricDescriptor({name: formattedName}).catch(err => {
  console.error(err);
});

getMetricDescriptor(request, optionsopt, callbackopt) → {Promise}

Gets a single metric descriptor. This method does not require a Stackdriver account.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
name string

The metric descriptor on which to execute the request. The format is "projects/{project_id_or_number}/metricDescriptors/{metric_id}". An example value of {metric_id} is "compute.googleapis.com/instance/disk/read_bytes_count".

options Object <optional>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback function <optional>

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing MetricDescriptor.

Source:
Example
const monitoring = require('@google-cloud/monitoring');

const client = new monitoring.v3.MetricServiceClient({
  // optional auth parameters.
});

const formattedName = client.metricDescriptorPath('[PROJECT]', '[METRIC_DESCRIPTOR]');
client.getMetricDescriptor({name: formattedName})
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

getMonitoredResourceDescriptor(request, optionsopt, callbackopt) → {Promise}

Gets a single monitored resource descriptor. This method does not require a Stackdriver account.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
name string

The monitored resource descriptor to get. The format is "projects/{project_id_or_number}/monitoredResourceDescriptors/{resource_type}". The {resource_type} is a predefined type, such as cloudsql_database.

options Object <optional>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback function <optional>

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing MonitoredResourceDescriptor.

Source:
Example
const monitoring = require('@google-cloud/monitoring');

const client = new monitoring.v3.MetricServiceClient({
  // optional auth parameters.
});

const formattedName = client.monitoredResourceDescriptorPath('[PROJECT]', '[MONITORED_RESOURCE_DESCRIPTOR]');
client.getMonitoredResourceDescriptor({name: formattedName})
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

getProjectId(callback)

Return the project ID used by this class.

Parameters:
Name Type Description
callback function

the callback to be called with the current project Id.

Source:

listMetricDescriptors(request, optionsopt, callbackopt) → {Promise}

Lists metric descriptors that match a filter. This method does not require a Stackdriver account.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Attributes Description
name string

The project on which to execute the request. The format is "projects/{project_id_or_number}".

filter string <optional>

If this field is empty, all custom and system-defined metric descriptors are returned. Otherwise, the filter specifies which metric descriptors are to be returned. For example, the following filter matches all custom metrics:

  metric.type = starts_with("custom.googleapis.com/")
pageSize number <optional>

The maximum number of resources contained in the underlying API response. If page streaming is performed per-resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

options Object <optional>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback function <optional>

The function which will be called with the result of the API call.

The second parameter to the callback is Array of MetricDescriptor.

When autoPaginate: false is specified through options, it contains the result in a single response. If the response indicates the next page exists, the third parameter is set to be used for the next request object. The fourth parameter keeps the raw response object of an object representing ListMetricDescriptorsResponse.

Source:
Example
const monitoring = require('@google-cloud/monitoring');

const client = new monitoring.v3.MetricServiceClient({
  // optional auth parameters.
});

// Iterate over all elements.
const formattedName = client.projectPath('[PROJECT]');

client.listMetricDescriptors({name: formattedName})
  .then(responses => {
    const resources = responses[0];
    for (const resource of resources) {
      // doThingsWith(resource)
    }
  })
  .catch(err => {
    console.error(err);
  });

// Or obtain the paged response.
const formattedName = client.projectPath('[PROJECT]');


const options = {autoPaginate: false};
const callback = responses => {
  // The actual resources in a response.
  const resources = responses[0];
  // The next request if the response shows that there are more responses.
  const nextRequest = responses[1];
  // The actual response object, if necessary.
  // const rawResponse = responses[2];
  for (const resource of resources) {
    // doThingsWith(resource);
  }
  if (nextRequest) {
    // Fetch the next page.
    return client.listMetricDescriptors(nextRequest, options).then(callback);
  }
}
client.listMetricDescriptors({name: formattedName}, options)
  .then(callback)
  .catch(err => {
    console.error(err);
  });

listMetricDescriptorsStream(request, optionsopt) → {Stream}

Equivalent to listMetricDescriptors, but returns a NodeJS Stream object.

This fetches the paged responses for listMetricDescriptors continuously and invokes the callback registered for 'data' event for each element in the responses.

The returned object has 'end' method when no more elements are required.

autoPaginate option will be ignored.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Attributes Description
name string

The project on which to execute the request. The format is "projects/{project_id_or_number}".

filter string <optional>

If this field is empty, all custom and system-defined metric descriptors are returned. Otherwise, the filter specifies which metric descriptors are to be returned. For example, the following filter matches all custom metrics:

  metric.type = starts_with("custom.googleapis.com/")
pageSize number <optional>

The maximum number of resources contained in the underlying API response. If page streaming is performed per-resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

options Object <optional>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

Source:
See:
Example
const monitoring = require('@google-cloud/monitoring');

const client = new monitoring.v3.MetricServiceClient({
  // optional auth parameters.
});

const formattedName = client.projectPath('[PROJECT]');
client.listMetricDescriptorsStream({name: formattedName})
  .on('data', element => {
    // doThingsWith(element)
  }).on('error', err => {
    console.log(err);
  });

listMonitoredResourceDescriptors(request, optionsopt, callbackopt) → {Promise}

Lists monitored resource descriptors that match a filter. This method does not require a Stackdriver account.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Attributes Description
name string

The project on which to execute the request. The format is "projects/{project_id_or_number}".

filter string <optional>

An optional filter describing the descriptors to be returned. The filter can reference the descriptor's type and labels. For example, the following filter returns only Google Compute Engine descriptors that have an id label:

  resource.type = starts_with("gce_") AND resource.label:id
pageSize number <optional>

The maximum number of resources contained in the underlying API response. If page streaming is performed per-resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

options Object <optional>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback function <optional>

The function which will be called with the result of the API call.

The second parameter to the callback is Array of MonitoredResourceDescriptor.

When autoPaginate: false is specified through options, it contains the result in a single response. If the response indicates the next page exists, the third parameter is set to be used for the next request object. The fourth parameter keeps the raw response object of an object representing ListMonitoredResourceDescriptorsResponse.

Source:
Example
const monitoring = require('@google-cloud/monitoring');

const client = new monitoring.v3.MetricServiceClient({
  // optional auth parameters.
});

// Iterate over all elements.
const formattedName = client.projectPath('[PROJECT]');

client.listMonitoredResourceDescriptors({name: formattedName})
  .then(responses => {
    const resources = responses[0];
    for (const resource of resources) {
      // doThingsWith(resource)
    }
  })
  .catch(err => {
    console.error(err);
  });

// Or obtain the paged response.
const formattedName = client.projectPath('[PROJECT]');


const options = {autoPaginate: false};
const callback = responses => {
  // The actual resources in a response.
  const resources = responses[0];
  // The next request if the response shows that there are more responses.
  const nextRequest = responses[1];
  // The actual response object, if necessary.
  // const rawResponse = responses[2];
  for (const resource of resources) {
    // doThingsWith(resource);
  }
  if (nextRequest) {
    // Fetch the next page.
    return client.listMonitoredResourceDescriptors(nextRequest, options).then(callback);
  }
}
client.listMonitoredResourceDescriptors({name: formattedName}, options)
  .then(callback)
  .catch(err => {
    console.error(err);
  });

listMonitoredResourceDescriptorsStream(request, optionsopt) → {Stream}

Equivalent to listMonitoredResourceDescriptors, but returns a NodeJS Stream object.

This fetches the paged responses for listMonitoredResourceDescriptors continuously and invokes the callback registered for 'data' event for each element in the responses.

The returned object has 'end' method when no more elements are required.

autoPaginate option will be ignored.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Attributes Description
name string

The project on which to execute the request. The format is "projects/{project_id_or_number}".

filter string <optional>

An optional filter describing the descriptors to be returned. The filter can reference the descriptor's type and labels. For example, the following filter returns only Google Compute Engine descriptors that have an id label:

  resource.type = starts_with("gce_") AND resource.label:id
pageSize number <optional>

The maximum number of resources contained in the underlying API response. If page streaming is performed per-resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

options Object <optional>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

Source:
See:
Example
const monitoring = require('@google-cloud/monitoring');

const client = new monitoring.v3.MetricServiceClient({
  // optional auth parameters.
});

const formattedName = client.projectPath('[PROJECT]');
client.listMonitoredResourceDescriptorsStream({name: formattedName})
  .on('data', element => {
    // doThingsWith(element)
  }).on('error', err => {
    console.log(err);
  });

listTimeSeries(request, optionsopt, callbackopt) → {Promise}

Lists time series that match a filter. This method does not require a Stackdriver account.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Attributes Description
name string

The project on which to execute the request. The format is "projects/{project_id_or_number}".

filter string

A monitoring filter that specifies which time series should be returned. The filter must specify a single metric type, and can additionally specify metric labels and other information. For example:

  metric.type = "compute.googleapis.com/instance/cpu/usage_time" AND
      metric.labels.instance_name = "my-instance-name"
interval Object

The time interval for which results should be returned. Only time series that contain data points in the specified interval are included in the response.

This object should have the same structure as TimeInterval

view number

Specifies which information is returned about the time series.

The number should be among the values of TimeSeriesView

aggregation Object <optional>

Specifies the alignment of data points in individual time series as well as how to combine the retrieved time series across specified labels.

By default (if no aggregation is explicitly specified), the raw time series data is returned.

This object should have the same structure as Aggregation

orderBy string <optional>

Unsupported: must be left blank. The points in each time series are currently returned in reverse time order (most recent to oldest).

pageSize number <optional>

The maximum number of resources contained in the underlying API response. If page streaming is performed per-resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

options Object <optional>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback function <optional>

The function which will be called with the result of the API call.

The second parameter to the callback is Array of TimeSeries.

When autoPaginate: false is specified through options, it contains the result in a single response. If the response indicates the next page exists, the third parameter is set to be used for the next request object. The fourth parameter keeps the raw response object of an object representing ListTimeSeriesResponse.

Source:
Example
const monitoring = require('@google-cloud/monitoring');

const client = new monitoring.v3.MetricServiceClient({
  // optional auth parameters.
});

// Iterate over all elements.
const formattedName = client.projectPath('[PROJECT]');
const filter = '';
const interval = {};
const view = 'FULL';
const request = {
  name: formattedName,
  filter: filter,
  interval: interval,
  view: view,
};

client.listTimeSeries(request)
  .then(responses => {
    const resources = responses[0];
    for (const resource of resources) {
      // doThingsWith(resource)
    }
  })
  .catch(err => {
    console.error(err);
  });

// Or obtain the paged response.
const formattedName = client.projectPath('[PROJECT]');
const filter = '';
const interval = {};
const view = 'FULL';
const request = {
  name: formattedName,
  filter: filter,
  interval: interval,
  view: view,
};


const options = {autoPaginate: false};
const callback = responses => {
  // The actual resources in a response.
  const resources = responses[0];
  // The next request if the response shows that there are more responses.
  const nextRequest = responses[1];
  // The actual response object, if necessary.
  // const rawResponse = responses[2];
  for (const resource of resources) {
    // doThingsWith(resource);
  }
  if (nextRequest) {
    // Fetch the next page.
    return client.listTimeSeries(nextRequest, options).then(callback);
  }
}
client.listTimeSeries(request, options)
  .then(callback)
  .catch(err => {
    console.error(err);
  });

listTimeSeriesStream(request, optionsopt) → {Stream}

Equivalent to listTimeSeries, but returns a NodeJS Stream object.

This fetches the paged responses for listTimeSeries continuously and invokes the callback registered for 'data' event for each element in the responses.

The returned object has 'end' method when no more elements are required.

autoPaginate option will be ignored.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Attributes Description
name string

The project on which to execute the request. The format is "projects/{project_id_or_number}".

filter string

A monitoring filter that specifies which time series should be returned. The filter must specify a single metric type, and can additionally specify metric labels and other information. For example:

  metric.type = "compute.googleapis.com/instance/cpu/usage_time" AND
      metric.labels.instance_name = "my-instance-name"
interval Object

The time interval for which results should be returned. Only time series that contain data points in the specified interval are included in the response.

This object should have the same structure as TimeInterval

view number

Specifies which information is returned about the time series.

The number should be among the values of TimeSeriesView

aggregation Object <optional>

Specifies the alignment of data points in individual time series as well as how to combine the retrieved time series across specified labels.

By default (if no aggregation is explicitly specified), the raw time series data is returned.

This object should have the same structure as Aggregation

orderBy string <optional>

Unsupported: must be left blank. The points in each time series are currently returned in reverse time order (most recent to oldest).

pageSize number <optional>

The maximum number of resources contained in the underlying API response. If page streaming is performed per-resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

options Object <optional>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

Source:
See:
Example
const monitoring = require('@google-cloud/monitoring');

const client = new monitoring.v3.MetricServiceClient({
  // optional auth parameters.
});

const formattedName = client.projectPath('[PROJECT]');
const filter = '';
const interval = {};
const view = 'FULL';
const request = {
  name: formattedName,
  filter: filter,
  interval: interval,
  view: view,
};
client.listTimeSeriesStream(request)
  .on('data', element => {
    // doThingsWith(element)
  }).on('error', err => {
    console.log(err);
  });

matchMetricDescriptorFromMetricDescriptorName(metricDescriptorName) → {String}

Parse the metricDescriptorName from a metric_descriptor resource.

Parameters:
Name Type Description
metricDescriptorName String

A fully-qualified path representing a metric_descriptor resources.

Source:

matchMonitoredResourceDescriptorFromMonitoredResourceDescriptorName(monitoredResourceDescriptorName) → {String}

Parse the monitoredResourceDescriptorName from a monitored_resource_descriptor resource.

Parameters:
Name Type Description
monitoredResourceDescriptorName String

A fully-qualified path representing a monitored_resource_descriptor resources.

Source:

matchProjectFromMetricDescriptorName(metricDescriptorName) → {String}

Parse the metricDescriptorName from a metric_descriptor resource.

Parameters:
Name Type Description
metricDescriptorName String

A fully-qualified path representing a metric_descriptor resources.

Source:

matchProjectFromMonitoredResourceDescriptorName(monitoredResourceDescriptorName) → {String}

Parse the monitoredResourceDescriptorName from a monitored_resource_descriptor resource.

Parameters:
Name Type Description
monitoredResourceDescriptorName String

A fully-qualified path representing a monitored_resource_descriptor resources.

Source:

matchProjectFromProjectName(projectName) → {String}

Parse the projectName from a project resource.

Parameters:
Name Type Description
projectName String

A fully-qualified path representing a project resources.

Source:

metricDescriptorPath(project, metricDescriptor) → {String}

Return a fully-qualified metric_descriptor resource name string.

Parameters:
Name Type Description
project String
metricDescriptor String
Source:

monitoredResourceDescriptorPath(project, monitoredResourceDescriptor) → {String}

Return a fully-qualified monitored_resource_descriptor resource name string.

Parameters:
Name Type Description
project String
monitoredResourceDescriptor String
Source:

projectPath(project) → {String}

Return a fully-qualified project resource name string.

Parameters:
Name Type Description
project String
Source: