背景
Elastic APM源自于收购的Opbeat,改头换面推出的服务
基本组件
Elasticsearch
APM Agent
APM Server
Kibana APM UI
基本架构
如下架构与常见APM产品的架构类似,
应用侧部署agent,负责应用性能和错误数据,当前支持node、python、ruby、js,java和golang beta版本中;
使用都是侵入的方式,需要在应用代码显示添加apm库。
服务测在原es基础上,新增golang编写的apm server服务,接受agent的打点数据;
同时Kibana提供了对APM显示的原生适配。
安装
es安装
使用docker安装单节点版本,简单方便
docker run -p 9200:9200 -p 9300:9300 -d -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:6.3.2
kibana安装
通过环境变量ELASTICSEARCH_URL 传入es的地址,根据实际环境替换192.168.99.1为本机IP
docker run -p 5602:5601 -d -e "ELASTICSEARCH_URL=http://192.168.99.1:9200" docker.elastic.co/kibana/kibana:6.3.2
apm-server安装
golang编译的binary mac本地安装
00 下载包
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/
01 导入kibana apm定制的dashboard
./apm-server setup
02 按需修改配置,已默认es host和kibana host,按照上面步骤不需要修改,默认即可;apm-server默认端口8200,供agent配置
vi apm-server.yml
<
apm-server:
# Defines the host and port the server is listening on
host: "localhost:8200"
output.elasticsearch:
# Array of hosts to connect to.
hosts: ["localhost:9200"]
setup.kibana:
# Kibana Host
# Scheme and port can be left out and will be set to the default (http and 5601)
# In case you specify and additional path, the scheme is required: http://localhost:5601/path
# IPv6 addresses should always be defined as: https://[2001:db8::1]:5601
# host: "localhost:5602"
>
03 启动 apm-server
./apm-server -e
使用体验
集成方式
参考https://www.elastic.co/guide/en/apm/get-started/6.3/install-and-run.html
APP集成部署
整了两个app,一个nodejs,一个python,代码如下
➜ myapp cat node.js
// Add this to the VERY top of the first file loaded in your app
var apm = require('elastic-apm-node').start({
// Set required service name (allowed characters: a-z, A-Z, 0-9, -, _, and space)
serviceName: 'node-test',
// Use if APM Server requires a token
secretToken: '',
// Set custom APM Server URL (default: http://localhost:8200)
serverUrl: 'http://localhost:8200'
})
const express = require('express')
const app = express()
app.get('/', (req, res) => res.send('Hello World!'))
app.listen(3000, () => console.log('Example app listening on port 3000!'))
事先安装俩包
npm install elastic-apm-node --save # apm-agent for node js
npm install express --save
启动
node node.js
➜ myapp cat hello.py
from flask import Flask
from elasticapm.contrib.flask import ElasticAPM
from elasticapm.handlers.logging import LoggingHandler
import os
import urllib2
app = Flask(__name__)
app.config['ELASTIC_APM'] ={
'SERVER_URL': 'http://127.0.0.1:8200',
'DEBUG': True
}
apm = ElasticAPM(app,service_name='python-test',logging=True)
port = 5000
@app.route('/')
def hello_world():
contents = urllib2.urlopen("http://127.0.0.1:3000").read()
return 'Hello World! I am running on port ' + str(port) + contents
if __name__ == '__main__':
handler = LoggingHandler(client=apm.client)
app.logger.addHandler(handler)
app.run(host='0.0.0.0', port=port)
启动
一切顺利的,可以去kibana的界面看下数据 127.0.0.1:5621
APM视图
当前服务
Pandora > Elastic APM试用 > image2018-8-15_22-5-0.png
服务详情
Pandora > Elastic APM试用 > image2018-8-15_22-5-39.png
Pandora > Elastic APM试用 > image2018-8-15_22-6-26.png
dashboard视图
默认提供的几个dashboard
Pandora > Elastic APM试用 > image2018-8-15_22-8-30.png
事务统计
Pandora > Elastic APM试用 > image2018-8-15_22-8-57.png
总结
侧重app本身性能监控,web无拓扑展示入口,同时使用时两个app之间transaction未关联起来(待确认是否使用姿势问题)—补充,多个app之前互相访问无埋点,无法关联
不支持opentracing协议,有些概念不一致
kibana apm展示很充实详尽,可借鉴