Skip to content

Commit

Permalink
resolve comments from review
Browse files Browse the repository at this point in the history
  • Loading branch information
megastef committed Dec 20, 2019
1 parent 12bc26d commit ec285ec
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 9 deletions.
49 changes: 47 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,72 @@ testAgent.on('process.memory', console.log)
## Metric Tags

The agent is able to use environment variables as metrics tags.
Define a list of environment variables to be used as metric tags:
Define a list of environment variables to be used as metric tags.

Let's assume this is the enviroment of the monitored application:

```
> env
TERM_PROGRAM=Apple_Terminal
TERM=xterm-256color
SHELL=/bin/bash
TMPDIR=/var/folders/v6/bh2q1xsn27g4d2g54z2ylv100000gn/T/
TERM_PROGRAM_VERSION=404.1
TERM_SESSION_ID=F12E0DBD-BF40-466D-85EC-08E89EDC3440
USER=stefan
PWD=/Users/stefan
HOME=/Users/stefan
LOGNAME=stefan
LC_CTYPE=UTF-8
DISPLAY=/private/tmp/com.apple.launchd.J60ybGpban/org.macosforge.xquartz:0
_=/usr/bin/env
```

You want to see later the performance metrics aggregated or filtered for specific user.
In this case the agent should collect the user name as tag. You can find the user name in the process environment variable `USER`.
Let's also assume the workingdirectory of the application `PWD` is another relevant identifier for your monitored application.

To configure the agent collecting USER and PWD as tags you can specify a commaseparated list of environment variables for the the agent configuration:

```
# add the values of env. variables USER, PWD as tags to metrics
export MONITORING_TAGS_FROM_ENV="USER, PWD"
```

The generated metrics include then the environment variable name and its value as tags. The result in Influx Line Protocol (ILP) format, produced by the agent for metric called `swap`:

```
swap, USER=stefan,PWD=/Users/stefan out=0i,in=0i 1576765680000000000
```

Define static tags in `key:value` format

```
export MONITORING_TAGS_FROM_ENV="organisation:sematext, service=api"
export MONITORING_TAGS_FROM_ENV="organisation:sematext, service:api"
```

The result in in ILP format:

```
swap, organisation=sematext,service=api out=0i,in=0i 1576765680000000000
```


Both types of tags can be mixed:

```
export MONITORING_TAGS_FROM_ENV="organisation:sematext, service:api, USER, PWD"
```

The result in in ILP format:

```
swap, organisation=sematext,service=api,USER=stefan,PWD=/Users/stefan,os.host=imac.local out=0i,in=0i 1576765680000000000
```


The config file entry `influx.tagsFromEnv` in `.spmagenrc` works as well:

```
Expand Down
11 changes: 5 additions & 6 deletions lib/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,19 +188,18 @@ function Agent (plugin) {
},
/**
* Stops the plugin - timers could be pushed to plugins 'timers' Array, if timers exists it tries to clearInterval(timerId)
* if no timers are defined it tries to call stop method of the plugin
* and tries to call the stop() method of the agent-plugin
*/
stop: function () {
if (this.plugin.timers) {
this.plugin.timers.forEach(function (tid) {
clearInterval(tid)
})
}
if (this.plugin.stop) {
this.plugin.stop()
} else {
if (this.plugin.stop) {
this.plugin.stop()
} else {
logger.warn('could not stop agent')
}
logger.warn('Plugin ' + plugin.name + ' has no stop() function')
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('SPM for NodeJS tests', function () {
config.logger.console = true
config.logger.level = 'debug'
var SpmAgent = require('../lib/index.js')
process.env.MONITORING_TAGS_FROM_ENV = 'USER,PWD,cutomer_id=123'
process.env.MONITORING_TAGS_FROM_ENV = 'USER,PWD,customer_id:123'
var client = new SpmAgent()
var testAgent = client.createAgent(new SpmAgent.Agent({
start: function (agent) {
Expand Down

0 comments on commit ec285ec

Please sign in to comment.