Skip to content
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
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 64 additions & 57 deletions packages/monitoring/README.md
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
49 changes: 12 additions & 37 deletions packages/monitoring/package.json
Original file line number Diff line number Diff line change
@@ -1,40 +1,13 @@
{
"repository": "googlecloudplatform/google-cloud-node",
"repository": "GoogleCloudPlatform/google-cloud-node",
"name": "@google-cloud/monitoring",
"version": "0.2.2",
"author": "Google Inc.",
"description": "Stackdriver Monitoring Client Library for Node.js",
"contributors": [
{
"name": "Burcu Dogan",
"email": "jbd@google.com"
},
{
"name": "Johan Euphrosine",
"email": "proppy@google.com"
},
{
"name": "Patrick Costello",
"email": "pcostell@google.com"
},
{
"name": "Ryan Seys",
"email": "ryan@ryanseys.com"
},
{
"name": "Silvano Luciani",
"email": "silvano@google.com"
},
{
"name": "Stephen Sawchuk",
"email": "sawchuk@gmail.com"
}
],
"version": "0.3.0",

This comment was marked as spam.

"author": "Google Inc",
"description": "Stackdriver Monitoring API client for Node.js",
"main": "src/index.js",
"files": [
"src",
"AUTHORS",
"CONTRIBUTING",
"COPYING"
],
"keywords": [
Expand All @@ -48,19 +21,21 @@
"cloud",
"google monitoring",
"monitoring",
"stackdriver monitoring",
"stackdriver"
"Stackdriver Monitoring API"
],
"dependencies": {
"extend": "^3.0.0",
"google-gax": "^0.13.0",
"google-proto-files": "^0.12.0"
"google-proto-files": "^0.12.0",
"google-gax": "^0.13.2",
"lodash.union": "^4.6.0",
"extend": "^3.0.0"
},
"devDependencies": {
"mocha": "^3.1.2"
"mocha": "^3.2.0",
"through2": "^2.0.3"

This comment was marked as spam.

},
"scripts": {
"publish-module": "node ../../scripts/publish.js monitoring",
"smoke-test": "mocha smoke-test/*.js --timeout 5000",
"test": "mocha test/*.js"
},
"license": "Apache-2.0",
Expand Down
92 changes: 92 additions & 0 deletions packages/monitoring/smoke-test/metric_service_smoke_test.js
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.

throw new Error("Usage: SMOKE_TEST_PROJECT=<project_id> node #{$0}");

This comment was marked as spam.

}
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.

}
})
.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.

}
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);
});
});
Loading