Constructor

MetricServiceClient

new MetricServiceClient(options)

Construct an instance of MetricServiceClient.

Parameter

options

Optional

object

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

Properties

port

static

The port for this API service.

scopes

static

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

servicePath

static

The DNS address for this API service.

Methods

createMetricDescriptor

createMetricDescriptor(request, options, callback) returns Promise

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

Parameter

request

Object

The request object that will be sent.

options

Optional

Object

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

callback

Optional

function(nullable Error, nullable Object)

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

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

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing MetricDescriptor. The promise has a method named "cancel" which cancels the ongoing API call.

Example

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

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

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

createTimeSeries

createTimeSeries(request, options, callback) returns 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.

Parameter

request

Object

The request object that will be sent.

options

Optional

Object

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

callback

Optional

function(nullable Error)

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

Returns

Promise 

  • The promise which resolves when API call finishes. The promise has a method named "cancel" which cancels the ongoing API call.

Example

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

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

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

deleteMetricDescriptor

deleteMetricDescriptor(request, options, callback) returns Promise

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

Parameter

request

Object

The request object that will be sent.

options

Optional

Object

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

callback

Optional

function(nullable Error)

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

Returns

Promise 

  • The promise which resolves when API call finishes. The promise has a method named "cancel" which cancels the ongoing API call.

Example

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

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

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

getMetricDescriptor

getMetricDescriptor(request, options, callback) returns Promise

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

Parameter

request

Object

The request object that will be sent.

options

Optional

Object

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

callback

Optional

function(nullable Error, nullable Object)

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

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

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing MetricDescriptor. The promise has a method named "cancel" which cancels the ongoing API call.

Example

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

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

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

getMonitoredResourceDescriptor

getMonitoredResourceDescriptor(request, options, callback) returns Promise

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

Parameter

request

Object

The request object that will be sent.

options

Optional

Object

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

callback

Optional

function(nullable Error, nullable Object)

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

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

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing MonitoredResourceDescriptor. The promise has a method named "cancel" which cancels the ongoing API call.

Example

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

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

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

getProjectId

getProjectId(callback)

Return the project ID used by this class.

Parameter

callback

function(Error, string)

the callback to be called with the current project Id.

listMetricDescriptors

listMetricDescriptors(request, options, callback) returns Promise

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

Parameter

request

Object

The request object that will be sent.

options

Optional

Object

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

callback

Optional

function(nullable Error, nullable Array, nullable Object, nullable Object)

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.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is Array of MetricDescriptor.

    When autoPaginate: false is specified through options, the array has three elements. The first element is Array of MetricDescriptor in a single response. The second element is the next request object if the response indicates the next page exists, or null. The third element is an object representing ListMetricDescriptorsResponse.

    The promise has a method named "cancel" which cancels the ongoing API call.

Example

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

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

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

client.listMetricDescriptors({name: formattedName})
  .then(responses => {
    var resources = responses[0];
    for (let i = 0; i < resources.length; i += 1) {
      // doThingsWith(resources[i])
    }
  })
  .catch(err => {
    console.error(err);
  });

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


var options = {autoPaginate: false};
var callback = responses => {
  // The actual resources in a response.
  var resources = responses[0];
  // The next request if the response shows that there are more responses.
  var nextRequest = responses[1];
  // The actual response object, if necessary.
  // var rawResponse = responses[2];
  for (let i = 0; i < resources.length; i += 1) {
    // doThingsWith(resources[i]);
  }
  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

listMetricDescriptorsStream(request, options) returns 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.

Parameter

request

Object

The request object that will be sent.

options

Optional

Object

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

See also
https://nodejs.org/api/stream.html
Returns

Stream 

An object stream which emits an object representing MetricDescriptor on 'data' event.

Example

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

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

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

listMonitoredResourceDescriptors

listMonitoredResourceDescriptors(request, options, callback) returns Promise

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

Parameter

request

Object

The request object that will be sent.

options

Optional

Object

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

callback

Optional

function(nullable Error, nullable Array, nullable Object, nullable Object)

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.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is Array of MonitoredResourceDescriptor.

    When autoPaginate: false is specified through options, the array has three elements. The first element is Array of MonitoredResourceDescriptor in a single response. The second element is the next request object if the response indicates the next page exists, or null. The third element is an object representing ListMonitoredResourceDescriptorsResponse.

    The promise has a method named "cancel" which cancels the ongoing API call.

Example

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

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

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

client.listMonitoredResourceDescriptors({name: formattedName})
  .then(responses => {
    var resources = responses[0];
    for (let i = 0; i < resources.length; i += 1) {
      // doThingsWith(resources[i])
    }
  })
  .catch(err => {
    console.error(err);
  });

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


var options = {autoPaginate: false};
var callback = responses => {
  // The actual resources in a response.
  var resources = responses[0];
  // The next request if the response shows that there are more responses.
  var nextRequest = responses[1];
  // The actual response object, if necessary.
  // var rawResponse = responses[2];
  for (let i = 0; i < resources.length; i += 1) {
    // doThingsWith(resources[i]);
  }
  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

listMonitoredResourceDescriptorsStream(request, options) returns 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.

Parameter

request

Object

The request object that will be sent.

options

Optional

Object

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

See also
https://nodejs.org/api/stream.html
Returns

Stream 

An object stream which emits an object representing MonitoredResourceDescriptor on 'data' event.

Example

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

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

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

listTimeSeries

listTimeSeries(request, options, callback) returns Promise

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

Parameter

request

Object

The request object that will be sent.

options

Optional

Object

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

callback

Optional

function(nullable Error, nullable Array, nullable Object, nullable Object)

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.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is Array of TimeSeries.

    When autoPaginate: false is specified through options, the array has three elements. The first element is Array of TimeSeries in a single response. The second element is the next request object if the response indicates the next page exists, or null. The third element is an object representing ListTimeSeriesResponse.

    The promise has a method named "cancel" which cancels the ongoing API call.

Example

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

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

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

client.listTimeSeries(request)
  .then(responses => {
    var resources = responses[0];
    for (let i = 0; i < resources.length; i += 1) {
      // doThingsWith(resources[i])
    }
  })
  .catch(err => {
    console.error(err);
  });

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


var options = {autoPaginate: false};
var callback = responses => {
  // The actual resources in a response.
  var resources = responses[0];
  // The next request if the response shows that there are more responses.
  var nextRequest = responses[1];
  // The actual response object, if necessary.
  // var rawResponse = responses[2];
  for (let i = 0; i < resources.length; i += 1) {
    // doThingsWith(resources[i]);
  }
  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

listTimeSeriesStream(request, options) returns 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.

Parameter

request

Object

The request object that will be sent.

options

Optional

Object

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

See also
https://nodejs.org/api/stream.html
Returns

Stream 

An object stream which emits an object representing TimeSeries on 'data' event.

Example

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

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

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

matchMetricDescriptorFromMetricDescriptorName

matchMetricDescriptorFromMetricDescriptorName(metricDescriptorName) returns String

Parse the metricDescriptorName from a metric_descriptor resource.

Parameter

metricDescriptorName

String

A fully-qualified path representing a metric_descriptor resources.

Returns

String 

  • A string representing the metric_descriptor.

matchMonitoredResourceDescriptorFromMonitoredResourceDescriptorName

matchMonitoredResourceDescriptorFromMonitoredResourceDescriptorName(monitoredResourceDescriptorName) returns String

Parse the monitoredResourceDescriptorName from a monitored_resource_descriptor resource.

Parameter

monitoredResourceDescriptorName

String

A fully-qualified path representing a monitored_resource_descriptor resources.

Returns

String 

  • A string representing the monitored_resource_descriptor.

matchProjectFromMetricDescriptorName

matchProjectFromMetricDescriptorName(metricDescriptorName) returns String

Parse the metricDescriptorName from a metric_descriptor resource.

Parameter

metricDescriptorName

String

A fully-qualified path representing a metric_descriptor resources.

Returns

String 

  • A string representing the project.

matchProjectFromMonitoredResourceDescriptorName

matchProjectFromMonitoredResourceDescriptorName(monitoredResourceDescriptorName) returns String

Parse the monitoredResourceDescriptorName from a monitored_resource_descriptor resource.

Parameter

monitoredResourceDescriptorName

String

A fully-qualified path representing a monitored_resource_descriptor resources.

Returns

String 

  • A string representing the project.

matchProjectFromProjectName

matchProjectFromProjectName(projectName) returns String

Parse the projectName from a project resource.

Parameter

projectName

String

A fully-qualified path representing a project resources.

Returns

String 

  • A string representing the project.

metricDescriptorPath

metricDescriptorPath(project, metricDescriptor) returns String

Return a fully-qualified metric_descriptor resource name string.

Parameter

project

String

metricDescriptor

String

Returns

String 

monitoredResourceDescriptorPath

monitoredResourceDescriptorPath(project, monitoredResourceDescriptor) returns String

Return a fully-qualified monitored_resource_descriptor resource name string.

Parameter

project

String

monitoredResourceDescriptor

String

Returns

String 

projectPath

projectPath(project) returns String

Return a fully-qualified project resource name string.

Parameter

project

String

Returns

String