Skip to content

Commit 0b1d929

Browse files
sjanuarystalleyj
authored andcommitted
Enable preloading and remove node-hc (#499)
* enable preloading * Deprecate node-hc in README * remove node-hc * Also mention NODE_OPTIONS * Consolidate 2 different sections on preloading * Also update version number in this PR * Update version to 4.0.0 * Update version to 4.0.0 * Also note NODE_OPTIONS is in 6.12.0 * also remove launcher.js
1 parent 2f43219 commit 0b1d929

File tree

6 files changed

+34
-179
lines changed

6 files changed

+34
-179
lines changed

README.md

Lines changed: 13 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ Node Application Metrics provides the following built-in data collection sources
4040
Redis | Redis commands issued by the application
4141
Riak | Riak methods called by the application
4242
Request tracking | A tree of application requests, events and optionally trace (disabled by default)
43-
Function trace | Tracing of application function calls that occur during a request (disabled by default)
43+
Function trace | Tracing of application function calls that occur during a request (disabled by default)
44+
4445
## Performance overhead
4546

4647
Our testing has shown that the performance overhead in terms of processing is minimal, adding less than 0.5 % to the CPU usage of your application. The additional memory required is around 20 MB to gather information about your system and application.
@@ -57,38 +58,6 @@ You can get Node Application Metrics from 3 different places:
5758
* Github ([install from source](https://github.com/RuntimeTools/appmetrics/wiki/Install-direct-from-github-source) by cloning the git repository. Requires a compiler)
5859
* [IBM SDK for Node.js](https://developer.ibm.com/node/sdk/) (packaged with the SDK, native libraries are prebuilt)
5960

60-
Using **npm** you can install Node Application Metrics either locally or globally.
61-
62-
**When installed locally** you can access monitoring data via both the API and the Health Center client by modifying your application to use appmetrics (see *[Modifying your application to use the local installation](#modifying-your-application-to-use-the-local-installation)*).
63-
64-
To perform a local install:
65-
```sh
66-
$ npm install appmetrics
67-
```
68-
A local install will put the module inside "*`./node_modules` of the current package root*" (see the [npm documentation][4] for more information); usually this is the current directory and in that case the module installation directory will be `./node_modules/appmetrics`.
69-
70-
**When installed globally** you can access monitoring data via the Health Center client (but not the API) by using the `node-hc` command-line utility (see *[The `node-hc` command](#the-node-hc-command)*).
71-
72-
To perform a global install:
73-
```sh
74-
$ npm install -g appmetrics
75-
```
76-
A global install will put the module inside a directory tied to your Node.js SDK.
77-
78-
* On Windows, either:
79-
* `<UserDirectory>\AppData\Roaming\npm\node_modules`
80-
* or: `<NodeInstallDirectory>\node_modules`
81-
* On other platforms:
82-
* `<node_install_directory>/lib/node_modules`
83-
84-
It also adds the `node-hc` command to another directory tied to your Node.js SDK, one that was added to your executable search path by the Node.js SDK installer.
85-
86-
* On Windows, either:
87-
* `<UserDirectory>\AppData\Roaming\npm`
88-
* or: `<NodeInstallDirectory>`
89-
* On other platforms:
90-
* `<node_install_directory>/bin`
91-
9261
### Configuring Node Application Metrics
9362

9463
Node Application Metrics can be configured in two ways, by using the configuration file described below or via a call to configure(options).
@@ -112,16 +81,19 @@ The following options are specific to appmetrics:
11281

11382
## Running Node Application Metrics
11483

115-
### The `node-hc` command
116-
If you [globally installed](#installation) this module with npm, you can use the `node-hc` command to run your application instead of the `node` command. This will run your application as it would normally under node (including any node options) but additionally load and start `appmetrics`.
84+
### Preloading appmetrics
85+
In previous versions appmetrics came with an executable, `node-hc`, which could be used instead of the `node` command to run your application and load and start appmetrics. This has been removed in version 4.0.0, instead you can use:
11786

11887
```sh
119-
$ node-hc app.js
88+
$ node --require appmetrics/start app.js
12089
```
90+
to preload and start appmetrics, or in Node.js from versions 8.0.0 and 6.12.0 onwards, use the NODE_OPTIONS environment variable:
12191

122-
The purpose of this mode of operation is to provide monitoring of the application without requiring any changes to the application code. The data is sent to the Health Center Eclipse IDE client.
92+
```sh
93+
$ export NODE_OPTIONS="--require appmetrics/start"
94+
```
12395

124-
### Modifying your application to use the local installation
96+
### Modifying your application to use appmetrics
12597
If you [locally install](#installation) this module with npm then you will additionally have access to the monitoring data via the `appmetrics` API (see *[API Documentation](#api-documentation)*).
12698

12799
To load `appmetrics` and get the monitoring API object, add the following to the start-up code for your application:
@@ -133,9 +105,7 @@ The call to `appmetrics.monitor()` starts the data collection agent, making the
133105

134106
You should start your application using the `node` command as usual (**not** `node-hc`).
135107

136-
You must call `require('appmetrics');` *before* the require statements for any npm modules you want to monitor. Appmetrics must be initialized first so that it can instrument modules for monitoring as they are loaded. If this is a problem due to the structure of your application you can require the module on the node command line with -r to make sure it is pre-loaded:
137-
138-
`> node -r appmetrics myapp.js`
108+
You must call `require('appmetrics');` *before* the require statements for any npm modules you want to monitor. Appmetrics must be initialized first so that it can instrument modules for monitoring as they are loaded. If this is a problem due to the structure of your application you can require the module on the node command line by using -r or --require or by setting NODE_OPTIONS as described above to make sure it is pre-loaded.
139109

140110
Once you have loaded appmetrics you can then use the monitoring object to register callbacks and request information about the application:
141111
```js
@@ -466,11 +436,6 @@ By default, a message similar to the following will be written to console output
466436

467437
`[Fri Aug 21 09:36:58 2015] com.ibm.diagnostics.healthcenter.loader INFO: Node Application Metrics 1.0.1-201508210934 (Agent Core 3.0.5.201508210934)`
468438

469-
### Error "Conflicting appmetrics module was already loaded by node-hc. Try running with node instead." when using `node-hc`
470-
This error indicates you are using `node-hc` to run an application that uses the Node Application Metrics monitoring API (see *[Modifying your application to use the local installation](#modifying-your-application-to-use-the-local-installation)*). Resolve this by using `node` to run the application instead. **Alternatively**, you could remove (or disable temporarily) the use of the Node Application Metrics monitoring API in your application.
471-
472-
This error was added to prevent the scenario where 2 instances of the agent can be accidentally created and started in parallel -- the globally installed one created by `node-hc` and the locally installed one created by the `require('appmetrics');` call in an application modified to use the Node Application Metrics monitoring API.
473-
474439
### Error "The specified module could not be found ... appmetrics.node"
475440
This error indicates there was a problem while loading the native part of the module or one of its dependent libraries. On Windows, `appmetrics.node` depends on a particular version of the C runtime library and if it cannot be found this error is the likely result.
476441

@@ -510,9 +475,10 @@ The npm package for this project uses a semver-parsable X.0.Z version number for
510475
Non-release versions of this project (for example on github.com/RuntimeTools/appmetrics) will use semver-parsable X.0.Z-dev.B version numbers, where X.0.Z is the last release with Z incremented and B is an integer. For further information on the development process go to the [appmetrics wiki][3]: [Developing](https://github.com/RuntimeTools/appmetrics/wiki/Developing).
511476

512477
## Version
513-
3.1.3
478+
4.0.0
514479

515480
## Release History
481+
`4.0.0` - Remove node-hc and add support for preloading.
516482
`3.1.3` - Packaging fix.
517483
`3.1.2` - Bug fixes.
518484
`3.1.1` - Node v6 on z/OS support.

bin/appmetrics-cli.js

Lines changed: 0 additions & 60 deletions
This file was deleted.

extract_all_binaries.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ var AGENTCORE_PLATFORMS = [
4242
'os390-s390x',
4343
];
4444
var AGENTCORE_VERSION = '3.2.6';
45-
var APPMETRICS_VERSION = '3.1.3';
45+
var APPMETRICS_VERSION = '4.0.0';
4646

4747
var LOG_FILE = path.join(INSTALL_DIR, 'install.log');
4848
var logFileStream = fs.createWriteStream(LOG_FILE, { flags: 'a' });

launcher.js

Lines changed: 0 additions & 67 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
{
22
"name": "appmetrics",
3-
"version": "3.1.3",
3+
"version": "4.0.0",
44
"engines": {
55
"node": ">=4"
66
},
77
"description": "Node Application Metrics",
8-
"bin": {
9-
"node-hc": "bin/appmetrics-cli.js"
10-
},
118
"dependencies": {
129
"nan": "2.x",
1310
"tar": "2.x",

start.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*******************************************************************************
2+
* Copyright 2017 IBM Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*******************************************************************************/
16+
'use strict';
17+
18+
var appmetrics = require('./index.js');
19+
appmetrics.start();

0 commit comments

Comments
 (0)