koa-elastic-apm

Stars
7
Committers
1

1ELK

ELK elastic ELK

  • Logstash Elasticsearch
  • Elasticsearch Apache Lucene JSON
  • Kibana Node.js

Docker Docker

$ git clone [email protected]:deviantony/docker-elk.git
$ cd docker-elk
$ docker-compose up [--force-recreate]

dockerdocker-composejavanodeelk

  • 5000: Logstash TCP input.
  • 9200: Elasticsearch HTTP
  • 9300: Elasticsearch TCP transport
  • 5601: Kibana

http://127.0.0.1:5601/

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

  • transaction traces HTTP
  • traceSQL

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 start2

$ 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