Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Unitech committed Apr 8, 2020
1 parent bebb010 commit 68c97ec
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

## 4.3.4

- Allow metrics to be a boolean
- Add some examples
- Track changes via CHANGELOG.md
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<img width=411px src="https://raw.githubusercontent.com/keymetrics/pm2-io-apm/master/pres/io-white.png">
</a>
<br/>

<br/>
<br/>
</div>
Expand Down Expand Up @@ -102,6 +102,19 @@ const myMetric = io.metric({
myMetric.set(23);
```

#### Passive Mode

In passive mode you hust need to return the variable to be monitored:

```javascript
const myMetric = io.metric({
name: 'Realtime Value',
value: () => {
return variable_to_monitor
}
});
```

### Counter: Discrete Counter

The second type of metric, called `counter`, is a discrete counter that helps you count the number of occurrence of a particular event. The counter starts at 0 and can be incremented or decremented.
Expand Down
25 changes: 25 additions & 0 deletions examples/standalone-example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var io = require('@pm2/io')

var agent = io.init({
standalone: true,
metrics: {
eventLoop: false,
http: false,
v8: false
},
apmOptions: {
publicKey: '<public>',
secretKey: '<secret>',
appName: 'toto'
}
})

var val = agent.metrics({
name: 'Value Report'
})

var i = 0

setInterval(() => {
val.set(i++)
}, 900)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"all": true
},
"dependencies": {
"@opencensus/core": "0.0.11",
"@opencensus/core": "0.0.9",
"@opencensus/propagation-b3": "0.0.8",
"@pm2/agent-node": "^1.1.10",
"async": "~2.6.1",
Expand Down
3 changes: 2 additions & 1 deletion src/services/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,11 @@ export class MetricService implements Service {

const isNumber = typeof metric.value === 'number'
const isString = typeof metric.value === 'string'
const isBoolean = typeof metric.value === 'boolean'
const isValidNumber = !isNaN(metric.value)
/* tslint:enable */
// we send it only if it's a string or a valid number
return isString || (isNumber && isValidNumber)
return isString || isBoolean || (isNumber && isValidNumber)
})
this.transport.setMetrics(metricsToSend)
}, constants.METRIC_INTERVAL)
Expand Down

0 comments on commit 68c97ec

Please sign in to comment.