一搓彻、 安裝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
- 執(zhí)行
.\skywalking\apache-skywalking-apm-incubating\bin\startup.sh
啟動,查看監(jiān)聽接口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是動態(tài)為服務配置的名稱,也可以在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參數(shù)激活sky-walking的探針, 如果當前上下文中存在traceid,log4j將在輸出traceId及汉。如果探針沒有被激活蛔屹,將輸出TID: N/A.
-
五、 查看效果
瀏覽器訪問 127.0.0.1:10800
注意
- dubbo使用hessian協(xié)議鏈路會斷,skywalking暫不支持hessian協(xié)議,