-
Notifications
You must be signed in to change notification settings - Fork 591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Monitoring: Regeneration #2427
Closed
Closed
Monitoring: Regeneration #2427
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,75 @@ | ||
# @google-cloud/monitoring ([Alpha][versioning]) | ||
> Google Stackdriver Monitoring Client Library for Node.js | ||
# Node.js Clients for Stackdriver Monitoring API ([Beta](https://github.com/GoogleCloudPlatform/google-cloud-node#versioning)) | ||
|
||
*Looking for more Google APIs than just Monitoring? You might want to check out [`google-cloud`][google-cloud].* | ||
[Stackdriver Monitoring API][Product Documentation]: Manages your Stackdriver Monitoring data and configurations. Most projects must be associated with a Stackdriver account, with a few exceptions as noted on the individual method pages. | ||
|
||
- [Official Documentation][cloud-monitoring-docs] | ||
- [Client Library Documentation][] | ||
- [Product Documentation][] | ||
|
||
## This is an auto-generated API | ||
## Quick Start | ||
In order to use this library, you first need to go through the following steps: | ||
|
||
It does not follow the conventions you're familiar with from other parts of our library. A handwritten layer is not yet available. | ||
1. [Select or create a Cloud Platform project.](https://console.cloud.google.com/project) | ||
2. [Enable the Stackdriver Monitoring API.](https://console.cloud.google.com/apis/api/monitoring) | ||
3. [Setup Authentication.](https://googlecloudplatform.github.io/google-cloud-node/#/docs/google-cloud/master/guides/authentication) | ||
|
||
The example below shows you how to instantiate the generated client. For further documentation, please browse the [Monitoring .proto files][cloud-monitoring-protos] on GitHub. | ||
|
||
|
||
```sh | ||
$ npm install --save @google-cloud/monitoring | ||
``` | ||
```js | ||
var monitoring = require('@google-cloud/monitoring').v3({ | ||
projectId: 'grape-spaceship-123', | ||
keyFilename: '/path/to/keyfile.json' | ||
}); | ||
### Installation | ||
``` | ||
|
||
|
||
## Authentication | ||
|
||
It's incredibly easy to get authenticated and start using Google's APIs. You can set your credentials on a global basis as well as on a per-API basis. See each individual API section below to see how you can auth on a per-API-basis. This is useful if you want to use different accounts for different Cloud services. | ||
|
||
### On Google Cloud Platform | ||
|
||
If you are running this client on Google Cloud Platform, we handle authentication for you with no configuration. You just need to make sure that when you [set up the GCE instance][gce-how-to], you add the correct scopes for the APIs you want to access. | ||
|
||
``` js | ||
// Authenticating on a global basis. | ||
var monitoring = require('@google-cloud/monitoring').v3(); | ||
// ...you're good to go! | ||
$ npm install --save @google-cloud/monitoring | ||
``` | ||
|
||
### Elsewhere | ||
|
||
If you are not running this client on Google Cloud Platform, you need a Google Developers service account. To create a service account: | ||
|
||
1. Visit the [Google Developers Console][dev-console]. | ||
2. Create a new project or click on an existing project. | ||
3. Navigate to **APIs & auth** > **Credentials** and then: | ||
* If you want to use a new service account key, click on **Create credentials** and select **Service account key**. After the account key is created, you will be prompted to download the JSON key file that the library uses to authenticate your requests. | ||
* If you want to generate a new service account key for an existing service account, click on **Generate new JSON key** and download the JSON key file. | ||
|
||
``` js | ||
var monitoring = require('@google-cloud/monitoring').v3({ | ||
// The path to your key file: | ||
keyFilename: '/path/to/keyfile.json' | ||
|
||
// Or the contents of the key file: | ||
credentials: require('./path/to/keyfile.json') | ||
}); | ||
|
||
// ...you're good to go! | ||
### Preview | ||
#### MetricServiceClient | ||
```js | ||
var monitoring = require('@google-cloud/monitoring'); | ||
|
||
var client = monitoring.metric({ | ||
// optional auth parameters. | ||
}); | ||
|
||
// Iterate over all elements. | ||
var formattedName = client.projectPath(projectId); | ||
|
||
client.listMonitoredResourceDescriptors({name: formattedName}).then(function(responses) { | ||
var resources = responses[0]; | ||
for (var i = 0; i < resources.length; ++i) { | ||
// doThingsWith(resources[i]) | ||
} | ||
}) | ||
.catch(function(err) { | ||
console.error(err); | ||
}); | ||
|
||
// Or obtain the paged response. | ||
var formattedName = client.projectPath(projectId); | ||
|
||
|
||
var options = {autoPaginate: false}; | ||
function callback(responses) { | ||
// The actual resources in a response. | ||
var resources = responses[0]; | ||
// The next request if the response shows there's more responses. | ||
var nextRequest = responses[1]; | ||
// The actual response object, if necessary. | ||
// var rawResponse = responses[2]; | ||
for (var i = 0; i < resources.length; ++i) { | ||
// doThingsWith(resources[i]); | ||
} | ||
if (nextRequest) { | ||
// Fetch the next page. | ||
return client.listMonitoredResourceDescriptors(nextRequest, options).then(callback); | ||
} | ||
} | ||
client.listMonitoredResourceDescriptors({name: formattedName}, options) | ||
.then(callback) | ||
.catch(function(err) { | ||
console.error(err); | ||
}); | ||
``` | ||
|
||
### Next Steps | ||
- Read the [Client Library Documentation][] for Stackdriver Monitoring API to see other available methods on the client. | ||
- Read the [Stackdriver Monitoring API Product documentation][Product Documentation] to learn more about the product and see How-to Guides. | ||
- View this [repository's main README](https://github.com/GoogleCloudPlatform/google-cloud-node/blob/master/README.md) to see the full list of Cloud APIs that we cover. | ||
|
||
[versioning]: https://github.com/GoogleCloudPlatform/google-cloud-node#versioning | ||
[google-cloud]: https://github.com/GoogleCloudPlatform/google-cloud-node/ | ||
[gce-how-to]: https://cloud.google.com/compute/docs/authentication#using | ||
[dev-console]: https://console.developers.google.com/project | ||
[cloud-monitoring-docs]: https://cloud.google.com/monitoring/docs | ||
[cloud-monitoring-protos]: https://github.com/googleapis/googleapis/tree/master/google/monitoring/v3 | ||
[Client Library Documentation]: https://googlecloudplatform.github.io/google-cloud-node/#/docs/monitoring | ||
[Product Documentation]: https://cloud.google.com/monitoring |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
packages/monitoring/smoke-test/metric_service_smoke_test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright 2017, Google Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
'use strict'; | ||
|
||
describe('MetricServiceSmokeTest', function() { | ||
if (!process.env.SMOKE_TEST_PROJECT) { | ||
This comment was marked as spam.
Sorry, something went wrong. |
||
throw new Error("Usage: SMOKE_TEST_PROJECT=<project_id> node #{$0}"); | ||
This comment was marked as spam.
Sorry, something went wrong. |
||
} | ||
var projectId = process.env.SMOKE_TEST_PROJECT; | ||
|
||
it('successfully makes a call to the service using promises', function(done) { | ||
var monitoring = require('../src'); | ||
|
||
var client = monitoring.v3.metric({ | ||
// optional auth parameters. | ||
}); | ||
|
||
// Iterate over all elements. | ||
var formattedName = client.projectPath(projectId); | ||
|
||
client.listMonitoredResourceDescriptors({name: formattedName}).then(function(responses) { | ||
var resources = responses[0]; | ||
for (var i = 0; i < resources.length; ++i) { | ||
console.log(resources[i]); | ||
This comment was marked as spam.
Sorry, something went wrong. |
||
} | ||
}) | ||
.then(done) | ||
.catch(done); | ||
}); | ||
|
||
it('successfully makes a call to the service using callbacks', function(done) { | ||
var monitoring = require('../src'); | ||
|
||
var client = monitoring.v3.metric({ | ||
// optional auth parameters. | ||
}); | ||
|
||
// Or obtain the paged response. | ||
var formattedName = client.projectPath(projectId); | ||
|
||
|
||
var options = {autoPaginate: false}; | ||
function callback(responses) { | ||
// The actual resources in a response. | ||
var resources = responses[0]; | ||
// The next request if the response shows there's more responses. | ||
var nextRequest = responses[1]; | ||
// The actual response object, if necessary. | ||
// var rawResponse = responses[2]; | ||
for (var i = 0; i < resources.length; ++i) { | ||
console.log(resources[i]) | ||
This comment was marked as spam.
Sorry, something went wrong. |
||
} | ||
if (nextRequest) { | ||
// Fetch the next page. | ||
return client.listMonitoredResourceDescriptors(nextRequest, options).then(callback); | ||
} | ||
} | ||
client.listMonitoredResourceDescriptors({name: formattedName}, options) | ||
.then(callback) | ||
.then(done) | ||
.catch(done); | ||
}); | ||
|
||
it('successfully makes a call to the service using streaming', function(done) { | ||
var monitoring = require('../src'); | ||
|
||
var client = monitoring.v3.metric({ | ||
// optional auth parameters. | ||
}); | ||
|
||
var formattedName = client.projectPath(projectId); | ||
client.listMonitoredResourceDescriptorsStream({name: formattedName}) | ||
.on('data', function(element) { | ||
console.log(element); | ||
}) | ||
.on('error', done) | ||
.on('end', done); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as spam.
Sorry, something went wrong.