diff --git a/packages/google-cloud-monitoring/.gitignore b/packages/google-cloud-monitoring/.gitignore index 531c77e628b..a4b7d6a3c59 100644 --- a/packages/google-cloud-monitoring/.gitignore +++ b/packages/google-cloud-monitoring/.gitignore @@ -12,3 +12,4 @@ system-test/*key.json google-cloud-logging-winston-*.tgz google-cloud-logging-bunyan-*.tgz package-lock.json +__pycache__ diff --git a/packages/google-cloud-monitoring/.readme-partials.yml b/packages/google-cloud-monitoring/.readme-partials.yml new file mode 100644 index 00000000000..7d23bee5856 --- /dev/null +++ b/packages/google-cloud-monitoring/.readme-partials.yml @@ -0,0 +1,4 @@ +introduction: |- + [Stackdriver Monitoring](https://cloud.google.com/monitoring/docs) collects metrics, events, and metadata from + Google Cloud Platform, Amazon Web Services (AWS), hosted uptime probes, application instrumentation, + and a variety of common application components including Cassandra, Nginx, Apache Web Server, Elasticsearch and many others. diff --git a/packages/google-cloud-monitoring/.repo-metadata.json b/packages/google-cloud-monitoring/.repo-metadata.json new file mode 100644 index 00000000000..2d8f760bf5a --- /dev/null +++ b/packages/google-cloud-monitoring/.repo-metadata.json @@ -0,0 +1,13 @@ +{ + "name": "monitoring", + "name_pretty": "Stackdriver Monitoring", + "product_documentation": "https://cloud.google.com/monitoring/docs", + "client_documentation": "https://cloud.google.com/nodejs/docs/reference/monitoring/latest/", + "issue_tracker": "https://issuetracker.google.com/savedsearches/559785", + "release_level": "beta", + "language": "nodejs", + "repo": "googleapis/nodejs-monitoring", + "distribution_name": "@google-cloud/monitoring", + "api_id": "monitoring.googleapis.com", + "requires_billing": true +} diff --git a/packages/google-cloud-monitoring/README.md b/packages/google-cloud-monitoring/README.md index 4b9acea14ae..18eef4eb583 100644 --- a/packages/google-cloud-monitoring/README.md +++ b/packages/google-cloud-monitoring/README.md @@ -1,21 +1,24 @@ [//]: # "This README.md file is auto-generated, all changes to this file will be lost." -[//]: # "To regenerate it, use `npm run generate-scaffolding`." +[//]: # "To regenerate it, use `python -m synthtool`." Google Cloud Platform logo # [Stackdriver Monitoring: Node.js Client](https://github.com/googleapis/nodejs-monitoring) -[![release level](https://img.shields.io/badge/release%20level-beta-yellow.svg?style=flat)](https://cloud.google.com/terms/launch-stages) +[![release level](https://img.shields.io/badge/release%20level-beta-yellow.svg?style=flat)](https://cloud.google.com/terms/launch-stages) [![npm version](https://img.shields.io/npm/v/@google-cloud/monitoring.svg)](https://www.npmjs.org/package/@google-cloud/monitoring) [![codecov](https://img.shields.io/codecov/c/github/googleapis/nodejs-monitoring/master.svg?style=flat)](https://codecov.io/gh/googleapis/nodejs-monitoring) -> Node.js idiomatic client for [Monitoring][product-docs]. -[Stackdriver Monitoring](https://cloud.google.com/monitoring/docs) collects metrics, events, and metadata from Google Cloud Platform, Amazon Web Services (AWS), hosted uptime probes, application instrumentation, and a variety of common application components including Cassandra, Nginx, Apache Web Server, Elasticsearch and many others. -* [Monitoring Node.js Client API Reference][client-docs] +[Stackdriver Monitoring](https://cloud.google.com/monitoring/docs) collects metrics, events, and metadata from +Google Cloud Platform, Amazon Web Services (AWS), hosted uptime probes, application instrumentation, +and a variety of common application components including Cassandra, Nginx, Apache Web Server, Elasticsearch and many others. + + +* [Stackdriver Monitoring Node.js Client API Reference][client-docs] +* [Stackdriver Monitoring Documentation][product-docs] * [github.com/googleapis/nodejs-monitoring](https://github.com/googleapis/nodejs-monitoring) -* [Monitoring Documentation][product-docs] Read more about the client libraries for Cloud APIs, including the older Google APIs Client Libraries, in [Client Libraries Explained][explained]. @@ -24,6 +27,7 @@ Google APIs Client Libraries, in [Client Libraries Explained][explained]. **Table of contents:** + * [Quickstart](#quickstart) * [Before you begin](#before-you-begin) * [Installing the client library](#installing-the-client-library) @@ -37,29 +41,18 @@ Google APIs Client Libraries, in [Client Libraries Explained][explained]. ### Before you begin -1. Select or create a Cloud Platform project. - - [Go to the projects page][projects] - -1. Enable billing for your project. - - [Enable billing][billing] - -1. Enable the Stackdriver Monitoring API. - - [Enable the API][enable_api] - +1. [Select or create a Cloud Platform project][projects]. +1. [Enable billing for your project][billing]. +1. [Enable the Stackdriver Monitoring API][enable_api]. 1. [Set up authentication with a service account][auth] so you can access the API from your local workstation. -[projects]: https://console.cloud.google.com/project -[billing]: https://support.google.com/cloud/answer/6293499#enable-billing -[enable_api]: https://console.cloud.google.com/flows/enableapi?apiid=monitoring.googleapis.com -[auth]: https://cloud.google.com/docs/authentication/getting-started - ### Installing the client library - npm install --save @google-cloud/monitoring +```bash +npm install @google-cloud/monitoring +``` + ### Using the client library @@ -67,59 +60,58 @@ Google APIs Client Libraries, in [Client Libraries Explained][explained]. // Imports the Google Cloud client library const monitoring = require('@google-cloud/monitoring'); -// Your Google Cloud Platform project ID -const projectId = 'YOUR_PROJECT_ID'; +async function quickstart() { + // Your Google Cloud Platform project ID + const projectId = process.env.GCLOUD_PROJECT || 'YOUR_PROJECT_ID'; -// Creates a client -const client = new monitoring.MetricServiceClient(); + // Creates a client + const client = new monitoring.MetricServiceClient(); -// Prepares an individual data point -const dataPoint = { - interval: { - endTime: { - seconds: Date.now() / 1000, + // Prepares an individual data point + const dataPoint = { + interval: { + endTime: { + seconds: Date.now() / 1000, + }, + }, + value: { + // The amount of sales + doubleValue: 123.45, }, - }, - value: { - // The amount of sales - doubleValue: 123.45, - }, -}; - -// Prepares the time series request -const request = { - name: client.projectPath(projectId), - timeSeries: [ - { - // Ties the data point to a custom metric - metric: { - type: 'custom.googleapis.com/stores/daily_sales', - labels: { - store_id: 'Pittsburgh', + }; + + // Prepares the time series request + const request = { + name: client.projectPath(projectId), + timeSeries: [ + { + // Ties the data point to a custom metric + metric: { + type: 'custom.googleapis.com/stores/daily_sales', + labels: { + store_id: 'Pittsburgh', + }, }, - }, - resource: { - type: 'global', - labels: { - project_id: projectId, + resource: { + type: 'global', + labels: { + project_id: projectId, + }, }, + points: [dataPoint], }, - points: [dataPoint], - }, - ], -}; - -// Writes time series data -client - .createTimeSeries(request) - .then(results => { - console.log(`Done writing time series data.`, results[0]); - }) - .catch(err => { - console.error('ERROR:', err); - }); + ], + }; + + // Writes time series data + const [result] = await client.createTimeSeries(request); + console.log(`Done writing time series data.`, result); +} + ``` + + ## Samples Samples are in the [`samples/`](https://github.com/googleapis/nodejs-monitoring/tree/master/samples) directory. The samples' `README.md` @@ -127,22 +119,30 @@ has instructions for running the samples. | Sample | Source Code | Try it | | --------------------------- | --------------------------------- | ------ | -| Alert Policies | [source code](https://github.com/googleapis/nodejs-monitoring/blob/master/samples/alerts.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-monitoring&page=editor&open_in_editor=samples/alerts.js,samples/README.md) | +| Alerts | [source code](https://github.com/googleapis/nodejs-monitoring/blob/master/samples/alerts.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-monitoring&page=editor&open_in_editor=samples/alerts.js,samples/README.md) | | Metrics | [source code](https://github.com/googleapis/nodejs-monitoring/blob/master/samples/metrics.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-monitoring&page=editor&open_in_editor=samples/metrics.js,samples/README.md) | -| Uptime Config | [source code](https://github.com/googleapis/nodejs-monitoring/blob/master/samples/uptime.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-monitoring&page=editor&open_in_editor=samples/uptime.js,samples/README.md) | +| Quickstart | [source code](https://github.com/googleapis/nodejs-monitoring/blob/master/samples/quickstart.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-monitoring&page=editor&open_in_editor=samples/quickstart.js,samples/README.md) | +| Uptime | [source code](https://github.com/googleapis/nodejs-monitoring/blob/master/samples/uptime.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-monitoring&page=editor&open_in_editor=samples/uptime.js,samples/README.md) | + -The [Monitoring Node.js Client API Reference][client-docs] documentation + +The [Stackdriver Monitoring Node.js Client API Reference][client-docs] documentation also contains samples. ## Versioning This library follows [Semantic Versioning](http://semver.org/). + + This library is considered to be in **beta**. This means it is expected to be mostly stable while we work toward a general availability release; however, complete stability is not guaranteed. We will address issues and requests against beta libraries with a high priority. + + + More Information: [Google Cloud Platform Launch Stages][launch_stages] [launch_stages]: https://cloud.google.com/terms/launch-stages @@ -160,4 +160,7 @@ See [LICENSE](https://github.com/googleapis/nodejs-monitoring/blob/master/LICENS [client-docs]: https://cloud.google.com/nodejs/docs/reference/monitoring/latest/ [product-docs]: https://cloud.google.com/monitoring/docs [shell_img]: https://gstatic.com/cloudssh/images/open-btn.png - +[projects]: https://console.cloud.google.com/project +[billing]: https://support.google.com/cloud/answer/6293499#enable-billing +[enable_api]: https://console.cloud.google.com/flows/enableapi?apiid=monitoring.googleapis.com +[auth]: https://cloud.google.com/docs/authentication/getting-started \ No newline at end of file diff --git a/packages/google-cloud-monitoring/samples/README.md b/packages/google-cloud-monitoring/samples/README.md index a3e44bb5206..7d6f61cf4a6 100644 --- a/packages/google-cloud-monitoring/samples/README.md +++ b/packages/google-cloud-monitoring/samples/README.md @@ -1,167 +1,100 @@ [//]: # "This README.md file is auto-generated, all changes to this file will be lost." -[//]: # "To regenerate it, use `npm run generate-scaffolding`." +[//]: # "To regenerate it, use `python -m synthtool`." Google Cloud Platform logo -# Stackdriver Monitoring: Node.js Samples +# [Stackdriver Monitoring: Node.js Samples](https://github.com/googleapis/nodejs-monitoring) [![Open in Cloud Shell][shell_img]][shell_link] -[Stackdriver Monitoring](https://cloud.google.com/monitoring/docs) collects metrics, events, and metadata from Google Cloud Platform, Amazon Web Services (AWS), hosted uptime probes, application instrumentation, and a variety of common application components including Cassandra, Nginx, Apache Web Server, Elasticsearch and many others. +[Stackdriver Monitoring](https://cloud.google.com/monitoring/docs) collects metrics, events, and metadata from +Google Cloud Platform, Amazon Web Services (AWS), hosted uptime probes, application instrumentation, +and a variety of common application components including Cassandra, Nginx, Apache Web Server, Elasticsearch and many others. ## Table of Contents * [Before you begin](#before-you-begin) * [Samples](#samples) - * [Alert Policies](#alert-policies) + * [Alerts](#alerts) * [Metrics](#metrics) - * [Uptime Config](#uptime-config) + * [Quickstart](#quickstart) + * [Uptime](#uptime) ## Before you begin -Before running the samples, make sure you've followed the steps in the -[Before you begin section](../README.md#before-you-begin) of the client -library's README. +Before running the samples, make sure you've followed the steps outlined in +[Using the client library](https://github.com/googleapis/nodejs-monitoring#using-the-client-library). ## Samples -### Alert Policies -View the [source code][alerts_0_code]. + +### Alerts + +View the [source code](https://github.com/googleapis/nodejs-monitoring/blob/master/samples/alerts.js). [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-monitoring&page=editor&open_in_editor=samples/alerts.js,samples/README.md) -__Usage:__ `node alerts.js --help` - -``` -alerts.js - -Commands: - alerts.js backup Save alert policies to a ./policies_backup.json file. - alerts.js restore Restore alert policies from a ./policies_backup.json file. - alerts.js replace Replace the notification channels of the specified alert policy. - alerts.js disable [filter] Disables policies that match the given filter. - alerts.js enable [filter] Enables policies that match the given filter. - alerts.js list Lists alert policies in the specified project. - -Options: - --version Show version number [boolean] - --alertPolicyName [string] - --help Show help [boolean] - -Examples: - node alerts.js backup my-project-id Backup policies. - node alerts.js restore my-project-id Restore policies. - node alerts.js replace Replace the notification channels of the specified alert - projects/my-project-id/alertPolicies/12345 channel-1 policy. - channel-2 channel-3 - node alerts.js disable my-project-id "(NOT Disables policies that match the given filter. - display_name.empty OR NOT description.empty) AND - user_labels='active'" - node alerts.js disable my-project-id "description:'cloud'" Disables policies that match the given filter. - node alerts.js disable my-project-id Disables policies that match the given filter. - "display_name=monitoring.regex.full_match('Temp \d{4}')" - node alerts.js enable my-project-id "(NOT display_name.empty Enables policies that match the given filter. - OR NOT description.empty) AND user_labels='active'" - node alerts.js enable my-project-id "description:'cloud'" Enables policies that match the given filter. - node alerts.js enable my-project-id Enables policies that match the given filter. - "display_name=monitoring.regex.full_match('Temp \d{4}')" - -For more information, see https://cloud.google.com/monitoring/docs/ -``` - -[alerts_0_docs]: https://cloud.google.com/monitoring/docs -[alerts_0_code]: alerts.js +__Usage:__ + + +`node alerts.js` + + +----- + + + ### Metrics -View the [source code][metrics_1_code]. +View the [source code](https://github.com/googleapis/nodejs-monitoring/blob/master/samples/metrics.js). [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-monitoring&page=editor&open_in_editor=samples/metrics.js,samples/README.md) -__Usage:__ `node metrics.js --help` - -``` -metrics.js - -Commands: - metrics.js create [projectId] Creates an example 'custom.googleapis.com/stores/daily_sales' - custom metric descriptor. - metrics.js list [projectId] Lists metric descriptors. - metrics.js get [projectId] Get a metric descriptor. - metrics.js delete [projectId] Deletes a custom metric descriptor. - metrics.js write [projectId] Writes example time series data to - 'custom.googleapis.com/stores/daily_sales'. - metrics.js read [projectId] Reads time series data that matches the given filter. - metrics.js read-fields [projectId] Reads headers of time series data that matches - 'compute.googleapis.com/instance/cpu/utilization'. - metrics.js read-aggregate [projectId] Aggregates time series data that matches - 'compute.googleapis.com/instance/cpu/utilization'. - metrics.js read-reduce [projectId] Reduces time series data that matches - 'compute.googleapis.com/instance/cpu/utilization'. - metrics.js list-resources [projectId] Lists monitored resource descriptors. - metrics.js get-resource [projectId] Get a monitored resource descriptor. - -Options: - --version Show version number [boolean] - --projectId, -p [string] [default: "nodejs-docs-samples"] - --help Show help [boolean] - -Examples: - node metrics.js create - node metrics.js list - node metrics.js get logging.googleapis.com/log_entry_count - node metrics.js delete custom.googleapis.com/stores/daily_sales - node metrics.js list-resources - node metrics.js get-resource cloudsql_database - node metrics.js write - node metrics.js read 'metric.type="compute.googleapis.com/instance/cpu/utilization"' - node metrics.js read-fields - node metrics.js read-aggregate - node metrics.js read-reduce - -For more information, see https://cloud.google.com/monitoring/docs -``` - -[metrics_1_docs]: https://cloud.google.com/monitoring/docs -[metrics_1_code]: metrics.js - -### Uptime Config - -View the [source code][uptime_2_code]. +__Usage:__ + + +`node metrics.js` + + +----- + + + + +### Quickstart + +View the [source code](https://github.com/googleapis/nodejs-monitoring/blob/master/samples/quickstart.js). + +[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-monitoring&page=editor&open_in_editor=samples/quickstart.js,samples/README.md) + +__Usage:__ + + +`node quickstart.js` + + +----- + + + + +### Uptime + +View the [source code](https://github.com/googleapis/nodejs-monitoring/blob/master/samples/uptime.js). [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-monitoring&page=editor&open_in_editor=samples/uptime.js,samples/README.md) -__Usage:__ `node uptime.js --help` +__Usage:__ + -``` -uptime.js +`node uptime.js` -Commands: - uptime.js create [projectId] Creates an uptime check config. - uptime.js list [projectId] Lists uptime check configs. - uptime.js list-ips Lists uptime check config IPs. - uptime.js get [projectId] Gets an uptime check config. - uptime.js delete [projectId] Deletes an uptime check config. -Options: - --version Show version number [boolean] - --projectId, -p [string] [default: "nodejs-docs-samples"] - --help Show help [boolean] -Examples: - node uptime.js create mydomain.com Create an uptime check. - node uptime.js list List all uptime check configs. - node uptime.js list "resource.type = gce_instance AND List all uptime check configs for a specific GCE - resource.label.instance_id = mongodb" instance. - node uptime.js list-ips - node uptime.js get My-Uptime-Check - node uptime.js delete My-Uptime-Check -For more information, see https://cloud.google.com/monitoring/uptime-checks/ -``` -[uptime_2_docs]: https://cloud.google.com/monitoring/docs -[uptime_2_code]: uptime.js [shell_img]: https://gstatic.com/cloudssh/images/open-btn.png [shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-monitoring&page=editor&open_in_editor=samples/README.md +[product-docs]: https://cloud.google.com/monitoring/docs \ No newline at end of file