A node.js module for Custom monitoring using Google Cloud Monitoring v3 API
Installation
npm i --save gcloud-monitor
Usage
Gauge
Create a Gauge Metric
const monitor = project: '<google-cloud-project-name>' resource: // optional, defaults to {type: 'global'} // more info: https://cloud.google.com/monitoring/api/ref_v3/rest/v3/MonitoredResource auth: // optional, if using on GCE // more info: https://github.com/google/google-api-nodejs-client#authorizing-and-authenticating // optional: default report throttle time timeout: 1000 /** * create a gauge * more info: https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.metricDescriptors#MetricDescriptor * @param * @param * @param * @param * @param * @param * @param * @param * @param * @return {Promise<Gauge,Error>} resolves gauge instance */monitor
Report Gauge Metric Data
/** * report a metric value * @param * @param * @param * @return */gauge
Delete a Gauge Metric
/** * delete the cumulative metric * @return */gauge
Cumulative
Create a Cumulative Metric
const monitor = project: '<google-cloud-project-name>' auth: /*auth-json*/ // optional, if using on GCE /** * create a cumulative metric * more info: https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.metricDescriptors#MetricDescriptor * @param * @param * @param * @param * @param * @param * @param * @param * @return {Promise<Model,Error>} resolves Cumulative instance */monitor
Report Cumulative Metric Data
/** * report a metric value * @param * @param * @param * @param * @param * @return */cumulative
Delete a Cumulative Metric
/** * delete the cumulative metric * @return */cumulative
Note about throttle
Throttle can be set globally as gcloud-monitor
opt
or on each individual "metric" as a factory opt
. This option throttles metric reports to the interval specified in ms.
Cumulative time series metrics batching can be grouped by passing opt.groupBy
function. For example, if you want to batch cumulative metric data grouped by label name
: groupBy: (timeSeriesItem) => (timeSeriesItem.metric.labels && timeSeriesItem.metric.labels.name)
License
MIT