一、 安装es-5.x
略
二、 安装配置skywalking
- 在apache-skywalking-apm-incubating\config\application.yml文件配置接收器信息(es、grpc、agent上报等)
naming: jetty: #OS real network IP(binding required), for agent to find collector cluster host: 0.0.0.0 port: 10800 contextPath: / ... storage: elasticsearch: clusterName: test # es 集群名称 clusterTransportSniffer: true clusterNodes: 192.168.10.103:9300 # 注意是9300 es集群通信端口 indexShardsNumber: 2 indexReplicasNumber: 0 highPerformanceMode: true # Batch process setting, refer to https://www.elastic.co/guide/en/elasticsearch/client/java-api/5.5/java-docs-bulk-processor.html bulkActions: 2000 # Execute the bulk every 2000 requests bulkSize: 20 # flush the bulk every 20mb flushInterval: 10 # flush the bulk every 10 seconds whatever the number of requests concurrentRequests: 2 # the number of concurrent requests # Set a timeout on metric data. After the timeout has expired, the metric data will automatically be deleted. traceDataTTL: 90 # Unit is minute minuteMetricDataTTL: 90 # Unit is minute hourMetricDataTTL: 36 # Unit is hour dayMetricDataTTL: 45 # Unit is day monthMetricDataTTL: 18 # Unit is month
- 在apache-skywalking-apm-incubating\webapp\webapp.yml文件中配置sykwalking-web信息
server: port: 8080 collector: path: /graphql ribbon: ReadTimeout: 10000 listOfServers: 127.0.0.1:10800 # 与application.yml文件中 naming一致 security: user: admin: password: admin
- 执行
.\skywalking\apache-skywalking-apm-incubating\bin\startup.sh
启动,查看监听接口10800、8080等
三、 目标项目配置使用
- 自动探针配置
java -jar -javaagent:$AGENT_PATH/skywalking-agent.jar -Dskywalking.agent.application_code=user_service user_service.jar
- 启动项目时配置 javaagent启动,比如springboot项目打包为user_service.jar,
- $AGENT_PATH是skywalking-agent的绝对路径
- application_code是动态为服务配置的名称,也可以在config文件夹下的agent.config文件中配置
-
手动探针使用
- 添加skywalking依赖
<dependency> <groupId>org.apache.skywalking</groupId> <artifactId>apm-toolkit-trace</artifactId> <version>5.0.0-GA</version> </dependency> <dependency> <groupId>org.apache.skywalking</groupId> <artifactId>apm-toolkit-opentracing</artifactId> <version>5.0.0-GA</version> </dependency>
- 通过
TraceContext.traceId()
API,在应用程序的任何地方获取traceId. - 对任何需要追踪的方法,使用 @Trace 标注,则此方法会被加入到追踪链中。
- 在被追踪的方法中自定义 tag.
ActiveSpan.tag("my_tag", "my_value");
- 添加skywalking依赖
四、 日志组件集成(以log4j为例)
- 添加skywalking日志依赖
<dependency> <groupId>org.apache.skywalking</groupId> <artifactId>apm-toolkit-log4j-1.x</artifactId> <version>5.0.0-GA</version> </dependency>
- 修改日志配置文件
-
配置layout
log4j.appender.stdout.layout===org.apache.skywalking.apm.toolkit.log.log4j.v1.x.TraceIdPatternLayout==
-
在layout.ConversionPattern中设置 %T来展示traceid
log4j.appender.stdout.layout.ConversionPattern=%-5p %d{yyyy-MM-dd HH:mm:ss,SSS} ==[%T]== %C{1}:%M - %m%n
当你使用-javaagent参数激活sky-walking的探针, 如果当前上下文中存在traceid,log4j将在输出traceId。如果探针没有被激活,将输出TID: N/A.
-
五、 查看效果
浏览器访问 127.0.0.1:10800
注意
- dubbo使用hessian协议链路会断,skywalking暂不支持hessian协议,