1ELK
ELK elastic ELK
Docker Docker
$ git clone [email protected]:deviantony/docker-elk.git
$ cd docker-elk
$ docker-compose up [--force-recreate]
dockerdocker-composejavanodeelk
2APM
Add APM
$ curl -L -O https://artifacts.elastic.co/downloads/apm-server/apm-server-6.3.2-darwin-x86_64.tar.gz
$ tar xzvf apm-server-6.3.2-darwin-x86_64.tar.gz
$ cd apm-server-6.3.2-darwin-x86_64/
$ ./apm-server setup
Loaded index template
Loading dashboards (Kibana must be running and reachable)
Loaded dashboards
setupapm
apm
$./apm-server -e
koaapmkoa-generatorbin/www
global.apm = require('elastic-apm-node').start({
serviceName: 'koa2-demo'
})
Elastic APM
app.jsloggerTransaction
// logger
app.use(async (ctx, next) => {
const start = new Date()
await next()
const ms = new Date() - start
console.log(`${ctx.method} ${ctx._matchedRoute} ${ctx.url} - ${ms}ms`)
apm.setTransactionName(`${ctx.method} ${ctx.url}`)
})
npm start
2
$ curl http://127.0.0.1:3000/
$ curl http://127.0.0.1:3000/users
koa2-demo
koa2-demo
router/index.js
router.get('/error', function (ctx, next) {
let err = new Error('apm.captureError(err)')
apm.captureError(err)
throw err
})
http://127.0.0.1:3000/error Kibana Dashboard -> [APM] Errors