Skip to content

Commit

Permalink
Add Alerting samples. (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdobry authored and Ace Nassri committed Nov 10, 2022
1 parent 521d50f commit 23f9e70
Show file tree
Hide file tree
Showing 6 changed files with 622 additions and 19 deletions.
1 change: 1 addition & 0 deletions monitoring/snippets/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
policies_backup.json
72 changes: 61 additions & 11 deletions monitoring/snippets/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[//]: # "This README.md file is auto-generated, all changes to this file will be lost."
[//]: # "To regenerate it, use `npm run generate-scaffolding`."
<img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/>

# Stackdriver Monitoring: Node.js Samples
Expand All @@ -10,6 +12,7 @@

* [Before you begin](#before-you-begin)
* [Samples](#samples)
* [Alert Policies](#alert-policies)
* [Metrics](#metrics)
* [Uptime Config](#uptime-config)

Expand All @@ -21,9 +24,56 @@ library's README.

## Samples

### Alert Policies

View the [source code][alerts_0_code].

[![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 <command>
Commands:
alerts.js backup <projectId> Save alert policies to a ./policies_backup.json file.
alerts.js restore <projectId> Restore alert policies from a ./policies_backup.json file.
alerts.js replace <alertPolicyName> <channelNames..> Replace the notification channels of the specified alert policy.
alerts.js disable <projectId> [filter] Disables policies that match the given filter.
alerts.js enable <projectId> [filter] Enables policies that match the given filter.
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

### Metrics

View the [source code][metrics_0_code].
View the [source code][metrics_1_code].

[![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)

Expand Down Expand Up @@ -52,7 +102,7 @@ Commands:
Options:
--version Show version number [boolean]
--projectId, -p [string]
--projectId, -p [string] [default: "nodejs-docs-samples"]
--help Show help [boolean]
Examples:
Expand All @@ -71,12 +121,12 @@ Examples:
For more information, see https://cloud.google.com/monitoring/docs
```

[metrics_0_docs]: https://cloud.google.com/monitoring/docs
[metrics_0_code]: metrics.js
[metrics_1_docs]: https://cloud.google.com/monitoring/docs
[metrics_1_code]: metrics.js

### Uptime Config

View the [source code][uptime_1_code].
View the [source code][uptime_2_code].

[![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)

Expand All @@ -86,19 +136,19 @@ __Usage:__ `node uptime.js --help`
uptime.js <command>
Commands:
uptime.js create <gceInstanceId> [projectId] Creates an uptime check config.
uptime.js create <hostname> [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 <uptimeCheckConfigId> [projectId] Gets an uptime check config.
uptime.js delete <uptimeCheckConfigId> [projectId] Deletes an uptime check config.
Options:
--version Show version number [boolean]
--projectId, -p [string]
--projectId, -p [string] [default: "nodejs-docs-samples"]
--help Show help [boolean]
Examples:
node uptime.js create my-instance Create an uptime check for a "my-instance" GCE instance.
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.
Expand All @@ -109,8 +159,8 @@ Examples:
For more information, see https://cloud.google.com/monitoring/uptime-checks/
```

[uptime_1_docs]: https://cloud.google.com/monitoring/docs
[uptime_1_code]: uptime.js
[uptime_2_docs]: https://cloud.google.com/monitoring/docs
[uptime_2_code]: uptime.js

[shell_img]: //gstatic.com/cloudssh/images/open-btn.png
[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
Loading

0 comments on commit 23f9e70

Please sign in to comment.