keymetrics / pm2-io-apm Goto Github PK
View Code? Open in Web Editor NEWPM2.io APM for Node.JS
License: Apache License 2.0
PM2.io APM for Node.JS
License: Apache License 2.0
On a une petite question liée à un plantage en PROD de notre app Node, il semble que les exceptions PMX ne remontent plus dans Keymetrics.
Voici notre code :
pmx.notify({ url: req.url, err : err });
C’est assez récent, avant on avait :
pmx.notify(err);
Auto link: https://github.com/keymetrics/keymetrics-agent with pmx
Metrics are not displayed in front.
context
to scopes
(context is already used for something else)Currently to instantiate a probe:
var probe = pmx.probe().metric({
name : 'Instance number'
})
Alias proposition 1:
var probe = pmx.metric('Instance Number')
Alias proposition 2 (multi metric):
var server_metrics = pmx.metric('Instance Number', 'File descriptors', 'tty opened')
// Snake case auto gen
console.log(server_metrics.instance_number)
console.log(server_metrics.file_descriptors)
on publish force building + test source
Exceptions are not send to front end.
@Unitech commented on Wed May 23 2018
var a = io.metric('mon_metric')
var b = io.histogram('mon_histogram')
var c = io.counter('mon_counter')
var d = io.meter('mon_meter')
a.set('value')
/// 2nd way
var e = io.metric({
name: g_key,
label: 'my/awesome/metric',
unit: 'aws',
value: function() {
return gpu_stats[g_key];
}
})
e.set('val')
// 3rd way (multi metric)
io.metrics([{
name: g_key,
value: function() {
return gpu_stats[g_key];
}
}, {
name: g_key_2,
value: function() {
return gpu_stats[g_key_3];
}
}])
This probe has been instanciated:
var errorMeter = probe.meter({
name : '404/sec',
samples : 1,
timeframe : 60
});
And here https://github.com/Unitech/pm2/blob/development/lib/API/Serve.js#L222 we do errorMeter.mark()
And get undefined:
Deprecated : you should use pmx instead of pmx.probe() !
[1525995546219] Error while serving /home/unitech/keymetrics/pm2/test/fixtures/serve/yolo.html with content-type text/html : ENOENT: no such file or directory, open '/home/unitech/keymetrics/pm2/test/fixtures/serve/yolo.html'
TypeError: Cannot read property 'mark' of undefined
at ReadFileContext.callback (/home/unitech/keymetrics/pm2/lib/API/Serve.js:222:18)
at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:441:13)
Deprecated : you should use pmx instead of pmx.probe() !
This block PM2 tests: https://travis-ci.org/Unitech/pm2
E.G.: https://github.com/keymetrics/pmx-2/blob/master/src/profiling/profilingCPU.ts#L50
Send a message like:
this.transport.send({
type : 'profiling:cpu:finished',
data : {
filesize : '20mb'
}
}, false)
Why do configureModule is commented there:
https://github.com/keymetrics/pmx-2/blob/master/src/features/notify.ts#L80 ?
this.inspectorService.createSession()
this.inspectorService.connect()
return this.inspectorService.post('Profiler.enable')
or
return this.inspectorService.post('Profiler.start')
or
return await this.getProfileInfo()
Never throw any error?
(node:8801) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 message listeners added. Use emitter.setMaxListeners() to increase limit
Its possible to trace warning with a flags to node
Could REPL could be interesting in entrypoint? Expose all custom actions as REPL commands?
const repl = require('repl');
const msg = 'message';
const r = repl.start('> ')
setInterval(function() {}, 2000)
$ pm2 start app.js
$ pm2 attach 0
> repl system
Do we really need to have a full blown class for these static things:
https://github.com/keymetrics/pmx-2/blob/master/src/configuration.ts
https://github.com/keymetrics/pmx-2/blob/master/src/utils/transport.ts
?
Should be just after this:
https://github.com/keymetrics/pmx-2/blob/master/src/profiling/profilingCPUFallback.ts#L23
Else the frontend will think that the profiling work but he did not installed the profiler
Same for inspector (but I guess that it is already available so just send true)
Object.keys(gpu_stats).forEach(function(g_key) {
console.log(g_key)
io.metric({
type: 'metric',
name: g_key,
value: function() {
return 1;
}
});
})
I don't see any value via pm2 monit
Also the destructuring API is a bit misleading ({})
Some people need to create custom tracing (example they process queries via websocket instead of http)
e.g.: https://github.com/GoogleCloudPlatform/cloud-trace-nodejs#custom-tracing-api
https://www.elastic.co/guide/en/apm/agent/nodejs/current/custom-spans.html
pmx
unitech@delta: ~/keymetrics/pm2
>>> require-time
2ms pm2-multimeter
18ms pmx
4ms promptly
@pm2/io
unitech@delta: ~/keymetrics/pm2
>>> require-time
54ms @pm2/io
28ms @pm2/agent
8ms async
(node:8752) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 message listeners added. Use emitter.setMaxListeners() to increase limit
http.js
const Koa = require('koa');
const app = new Koa();
app.use(async ctx => {
ctx.body = 'Hello World, koa.js';
});
app.listen(3000);
unitech@delta: ~/keymetrics/koa
>>> node -v
v10.1.0
unitech@delta: ~/keymetrics/koa
>>> node http.js
Benchmark:
>>> wrk -t 100 -c 100 http://localhost:3000
Running 10s test @ http://localhost:3000
100 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 5.53ms 2.62ms 52.68ms 93.35%
Req/Sec 188.39 39.86 555.00 88.43%
188721 requests in 10.10s, 28.80MB read
Requests/sec: 18685.43
Transfer/sec: 2.85MB
Requests/sec: 18685.43
unitech@delta: ~/keymetrics/koa
>>> pm2 -v
3.0.0
unitech@delta: ~/keymetrics/koa
>>> pm2 start http.js -i 1
[PM2] Starting /home/unitech/keymetrics/koa/http.js in cluster_mode (1 instance)
[PM2] Done.
┌──────────┬────┬─────────┬───────┬────────┬─────────┬────────┬─────┬───────────┬─────────┬──────────┐
│ App name │ id │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │
├──────────┼────┼─────────┼───────┼────────┼─────────┼────────┼─────┼───────────┼─────────┼──────────┤
│ http │ 0 │ cluster │ 32218 │ online │ 0 │ 0s │ 8% │ 30.6 MB │ unitech │ disabled │
└──────────┴────┴─────────┴───────┴────────┴─────────┴────────┴─────┴───────────┴─────────┴──────────┘
Use `pm2 show <id|name>` to get more details about an app
Benchmark:
>>> wrk -t 100 -c 100 http://localhost:3000
Running 10s test @ http://localhost:3000
100 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 15.14ms 59.29ms 794.60ms 97.20%
Req/Sec 161.32 23.19 323.00 91.49%
157160 requests in 10.10s, 23.98MB read
Requests/sec: 15560.12
Transfer/sec: 2.37MB
18500req/s to 15560req/s this is a 16% performance overhead!
unitech@delta: ~/keymetrics/koa
>>> pm2 start http.js -i 1 --no-pmx
[PM2] Starting /home/unitech/keymetrics/koa/http.js in cluster_mode (1 instance)
[PM2] Done.
┌──────────┬────┬─────────┬───────┬────────┬─────────┬────────┬─────┬───────────┬─────────┬──────────┐
│ App name │ id │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │
├──────────┼────┼─────────┼───────┼────────┼─────────┼────────┼─────┼───────────┼─────────┼──────────┤
│ http │ 0 │ cluster │ 32507 │ online │ 0 │ 0s │ 0% │ 30.5 MB │ unitech │ disabled │
└──────────┴────┴─────────┴───────┴────────┴─────────┴────────┴─────┴───────────┴─────────┴──────────┘
Use `pm2 show <id|name>` to get more details about an app
Benchmark:
>>> wrk -t 100 -c 100 http://localhost:3000
Running 10s test @ http://localhost:3000
100 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 12.34ms 50.18ms 704.81ms 97.45%
Req/Sec 195.02 33.86 520.00 87.91%
190190 requests in 10.10s, 29.02MB read
Requests/sec: 18830.96
Transfer/sec: 2.87MB
18830.96req/s Same result than the node binary
There is a great library to handle exit for every possible signal and strategy: https://github.com/tapjs/signal-exit
We will also add uncaughtException and unhandledRejection too on this exit strategy
Deprecated : this feature will be removed in next release !
I don't know which feature
With
pmx.init({profiling: true})
I got
Action profiling does not exist
3|pm2-auto | 2018-05-15 17:49:46 +02:00: TypeError: namespace.charCodeAt is not a function
3|pm2-auto | at selectColor (/usr/lib/node_modules/pm2/node_modules/debug/src/debug.js:47:46)
3|pm2-auto | at Function.createDebug (/usr/lib/node_modules/pm2/node_modules/debug/src/debug.js:121:17)
3|pm2-auto | at Transport.send (/usr/lib/node_modules/pm2/node_modules/pm2.io/build/main/src/utils/transport.js:14:28)
3|pm2-auto | at Configuration.configureModule (/usr/lib/node_modules/pm2/node_modules/pm2.io/build/main/src/configuration.js:17:24)
3|pm2-auto | at Function._load (/usr/lib/node_modules/pm2/node_modules/pm2.io/build/main/src/metrics/transaction.js:98:46)
3|pm2-auto | at Module.require (module.js:556:17)
3|pm2-auto | at Module.newFunc [as require] (/usr/lib/node_modules/pm2/node_modules/deep-metrics/lib/aspect.js:101:26)
3|pm2-auto | at require (internal/module.js:11:18)
3|pm2-auto | at Object.<anonymous> (/root/.pm2/modules/pm2-auto-pull/node_modules/pm2/lib/API/Keymetrics/kmapi.js:2:13)
3|pm2-auto | at Module._compile (module.js:612:30)
3|pm2-auto | 2018-05-15 17:49:46 +02:00: /usr/lib/node_modules/pm2/node_modules/debug/src/debug.js:47
3|pm2-auto | hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
3|pm2-auto | ^
3|pm2-auto | TypeError: namespace.charCodeAt is not a function
3|pm2-auto | at selectColor (/usr/lib/node_modules/pm2/node_modules/debug/src/debug.js:47:46)
3|pm2-auto | at Function.createDebug (/usr/lib/node_modules/pm2/node_modules/debug/src/debug.js:121:17)
3|pm2-auto | at Transport.send (/usr/lib/node_modules/pm2/node_modules/pm2.io/build/main/src/utils/transport.js:14:28)
3|pm2-auto | at process.uncaughtListener (/usr/lib/node_modules/pm2/node_modules/pm2.io/build/main/src/features/notify.js:80:32)
3|pm2-auto | at Object.onceWrapper (events.js:314:30)
3|pm2-auto | at emitOne (events.js:115:13)
3|pm2-auto | at process.emit (events.js:210:7)
pm2-plus-driver or pm2-plus
@vmarchaud thoughts?
Only check the presence of the property, for example :
https://github.com/keymetrics/pmx-2/blob/master/src/index.ts#L214
Increase coverage on
Not to implement but just for info for pmx migrator
Via a module like that: https://www.npmjs.com/package/clean-stack
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.