v3. MetricServiceClient
Source: v3/
Manages metric descriptors, monitored resource descriptors, and time series data.
Properties
Methods
- createMetricDescriptor(request[, options][, callback])
- createTimeSeries(request[, options][, callback])
- deleteMetricDescriptor(request[, options][, callback])
- getMetricDescriptor(request[, options][, callback])
- getMonitoredResourceDescriptor(request[, options][, callback])
- getProjectId(callback)
- listMetricDescriptors(request[, options][, callback])
- listMetricDescriptorsStream(request[, options])
- listMonitoredResourceDescriptors(request[, options][, callback])
- listMonitoredResourceDescriptorsStream(request[, options])
- listTimeSeries(request[, options][, callback])
- listTimeSeriesStream(request[, options])
- matchMetricDescriptorFromMetricDescriptorName(metricDescriptorName)
- matchMonitoredResourceDescriptorFromMonitoredResourceDescriptorName(monitoredResourceDescriptorName)
- matchProjectFromMetricDescriptorName(metricDescriptorName)
- matchProjectFromMonitoredResourceDescriptorName(monitoredResourceDescriptorName)
- matchProjectFromProjectName(projectName)
- metricDescriptorPath(project, metricDescriptor)
- monitoredResourceDescriptorPath(project, monitoredResourceDescriptor)
- projectPath(project)
new MetricServiceClient([options])
Construct an instance of MetricServiceClient.
Parameters
| Name | Type | Optional | Description | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
options |
|
Yes |
The configuration object. See the subsequent parameters for more details. Values in
|
Properties
apiEndpoint
The DNS address for this API service - same as servicePath(), exists for compatibility reasons.
port
The port for this API service.
scopes
The scopes needed to make gRPC calls for every method defined in this service.
servicePath
The DNS address for this API service.
Methods
createMetricDescriptor(request[, options][, callback]) → Promise
Creates a new metric descriptor. User-created metric descriptors define custom metrics.
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);
});
Parameters
| Name | Type | Optional | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
request |
Object |
|
The request object that will be sent. Values in
|
||||||||||||
|
options |
Object |
Yes |
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(nullable Error, nullable Object) |
Yes |
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.
createTimeSeries(request[, options][, callback]) → 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.
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);
});
Parameters
| Name | Type | Optional | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
request |
Object |
|
The request object that will be sent. Values in
|
||||||||||||
|
options |
Object |
Yes |
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(nullable Error) |
Yes |
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.
deleteMetricDescriptor(request[, options][, callback]) → Promise
Deletes a metric descriptor. Only user-created custom metrics can be deleted.
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);
});
Parameters
| Name | Type | Optional | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|
request |
Object |
|
The request object that will be sent. Values in
|
||||||||
|
options |
Object |
Yes |
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(nullable Error) |
Yes |
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.
getMetricDescriptor(request[, options][, callback]) → Promise
Gets a single metric descriptor. This method does not require a Stackdriver account.
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);
});
Parameters
| Name | Type | Optional | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|
request |
Object |
|
The request object that will be sent. Values in
|
||||||||
|
options |
Object |
Yes |
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(nullable Error, nullable Object) |
Yes |
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.
getMonitoredResourceDescriptor(request[, options][, callback]) → Promise
Gets a single monitored resource descriptor. This method does not require a Stackdriver account.
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);
});
Parameters
| Name | Type | Optional | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|
request |
Object |
|
The request object that will be sent. Values in
|
||||||||
|
options |
Object |
Yes |
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(nullable Error, nullable Object) |
Yes |
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.
getProjectId(callback)
Return the project ID used by this class.
Parameter
| Name | Type | Optional | Description |
|---|---|---|---|
|
callback |
function(Error, string) |
|
the callback to be called with the current project Id. |
listMetricDescriptors(request[, options][, callback]) → Promise
Lists metric descriptors that match a filter. This method does not require a Stackdriver account.
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);
});
Parameters
| Name | Type | Optional | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
request |
Object |
|
The request object that will be sent. Values in
|
||||||||||||||||
|
options |
Object |
Yes |
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(nullable Error, nullable Array, nullable Object, nullable Object) |
Yes |
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.
-
listMetricDescriptorsStream(request[, options]) → 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.
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);
});
Parameters
| Name | Type | Optional | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
request |
Object |
|
The request object that will be sent. Values in
|
||||||||||||||||
|
options |
Object |
Yes |
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
-
StreamAn object stream which emits an object representing MetricDescriptor on 'data' event.
listMonitoredResourceDescriptors(request[, options][, callback]) → Promise
Lists monitored resource descriptors that match a filter. This method does not require a Stackdriver account.
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);
});
Parameters
| Name | Type | Optional | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
request |
Object |
|
The request object that will be sent. Values in
|
||||||||||||||||
|
options |
Object |
Yes |
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(nullable Error, nullable Array, nullable Object, nullable Object) |
Yes |
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.
-
listMonitoredResourceDescriptorsStream(request[, options]) → 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.
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);
});
Parameters
| Name | Type | Optional | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
request |
Object |
|
The request object that will be sent. Values in
|
||||||||||||||||
|
options |
Object |
Yes |
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
-
StreamAn object stream which emits an object representing MonitoredResourceDescriptor on 'data' event.
listTimeSeries(request[, options][, callback]) → Promise
Lists time series that match a filter. This method does not require a Stackdriver account.
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);
});
Parameters
| Name | Type | Optional | Description | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
request |
Object |
|
The request object that will be sent. Values in
|
||||||||||||||||||||||||||||||||
|
options |
Object |
Yes |
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(nullable Error, nullable Array, nullable Object, nullable Object) |
Yes |
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.
-
listTimeSeriesStream(request[, options]) → 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.
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);
});
Parameters
| Name | Type | Optional | Description | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
request |
Object |
|
The request object that will be sent. Values in
|
||||||||||||||||||||||||||||||||
|
options |
Object |
Yes |
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
-
StreamAn object stream which emits an object representing TimeSeries on 'data' event.
matchMetricDescriptorFromMetricDescriptorName(metricDescriptorName) → String
Parse the metricDescriptorName from a metric_descriptor resource.
Parameter
| Name | Type | Optional | Description |
|---|---|---|---|
|
metricDescriptorName |
String |
|
A fully-qualified path representing a metric_descriptor resources. |
- Returns
-
String- A string representing the metric_descriptor.
matchMonitoredResourceDescriptorFromMonitoredResourceDescriptorName(monitoredResourceDescriptorName) → String
Parse the monitoredResourceDescriptorName from a monitored_resource_descriptor resource.
Parameter
| Name | Type | Optional | Description |
|---|---|---|---|
|
monitoredResourceDescriptorName |
String |
|
A fully-qualified path representing a monitored_resource_descriptor resources. |
- Returns
-
String- A string representing the monitored_resource_descriptor.
matchProjectFromMetricDescriptorName(metricDescriptorName) → String
Parse the metricDescriptorName from a metric_descriptor resource.
Parameter
| Name | Type | Optional | Description |
|---|---|---|---|
|
metricDescriptorName |
String |
|
A fully-qualified path representing a metric_descriptor resources. |
- Returns
-
String- A string representing the project.
matchProjectFromMonitoredResourceDescriptorName(monitoredResourceDescriptorName) → String
Parse the monitoredResourceDescriptorName from a monitored_resource_descriptor resource.
Parameter
| Name | Type | Optional | Description |
|---|---|---|---|
|
monitoredResourceDescriptorName |
String |
|
A fully-qualified path representing a monitored_resource_descriptor resources. |
- Returns
-
String- A string representing the project.
matchProjectFromProjectName(projectName) → String
Parse the projectName from a project resource.
Parameter
| Name | Type | Optional | Description |
|---|---|---|---|
|
projectName |
String |
|
A fully-qualified path representing a project resources. |
- Returns
-
String- A string representing the project.
metricDescriptorPath(project, metricDescriptor) → String
Return a fully-qualified metric_descriptor resource name string.
Parameters
| Name | Type | Optional | Description |
|---|---|---|---|
|
project |
String |
|
|
|
metricDescriptor |
String |
|
- Returns
-
String
monitoredResourceDescriptorPath(project, monitoredResourceDescriptor) → String
Return a fully-qualified monitored_resource_descriptor resource name string.
Parameters
| Name | Type | Optional | Description |
|---|---|---|---|
|
project |
String |
|
|
|
monitoredResourceDescriptor |
String |
|
- Returns
-
String
projectPath(project) → String
Return a fully-qualified project resource name string.
Parameter
| Name | Type | Optional | Description |
|---|---|---|---|
|
project |
String |
|
- Returns
-
String