# more opt/skywalking/.env
ES_VERSION=7.9.0
#OAP_IMAGE=apache/skywalking-oap-server/oap:9.5.0
#OAP_IMAGE=apache/skywalking-oap-server/oap:9.5.0
OAP_IMAGE=apache/skywalking-oap-server:9.5.0
UI_IMAGE=apache/skywalking-ui:9.5.0
## more opt/skywalking/docker-compose.yml
# more docker-compose.yml
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
version: '3.8'
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch-oss:${ES_VERSION}
container_name: elasticsearch
ports:
- "9200:9200"
healthcheck:
test: [ "CMD-SHELL", "curl --silent --fail localhost:9200/_cluster/health || exit 1" ]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
environment:
- discovery.type=single-node
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
oap:
image: ${OAP_IMAGE}
container_name: oap
depends_on:
elasticsearch:
condition: service_healthy
links:
- elasticsearch
ports:
- "11800:11800"
- "12800:12800"
healthcheck:
test: [ "CMD-SHELL", "/skywalking/bin/swctl ch" ]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
environment:
SW_STORAGE: elasticsearch
SW_STORAGE_ES_CLUSTER_NODES: elasticsearch:9200
SW_HEALTH_CHECKER: default
SW_TELEMETRY: prometheus
JAVA_OPTS: "-Xms2048m -Xmx2048m"
ui:
image: ${UI_IMAGE}
container_name: ui
depends_on:
oap:
condition: service_healthy
links:
- oap
ports:
- "8080:8080"
environment:
SW_OAP_ADDRESS: http://oap:12800
SW_ZIPKIN_ADDRESS: http://oap:9412
# docker-compose up -d -f docker-compose.yml
JAVA_OPTS='-Xms8g -Xmx8g -Dspring.profiles.active=shsj -javaagent:/home/opt/skywalking-agent/skywalking-agent.jar -DSW_AGENT_COLLEC
TOR_BACKEND_SERVICES=172.150.1.29:11800 -Dskywalking.agent.service_name=zsyy-api '
docker 文件卷挂载
-v /home/opt/skywa
lking-agent:/home/opt/skywalking-agent
pom.xml
1.8
UTF-8
UTF-8
3.0.1
8.16.0
org.apache.skywalking
apm-toolkit-trace
${skywalking.toolkit.version}
provided
org.apache.skywalking
apm-toolkit-logback-1.x
${skywalking.toolkit.version}
配置logback.xml 文件
zsyy-api
%d{yyyy-MM-dd HH:mm:ss.SSS} [%X{tid}] [%thread] %-5level %logger{36} -%msg%n
MARKER_MP_NOTIFY
NEUTRAL
DENY
${log.path}/${LOG_NAME}.log
${log.path}/${LOG_NAME}_%d{yyyy-MM-dd}_%i.log
1000MB
30
20GB
${FILE_LOG_PATTERN}
UTF-8
%d{yyyy-MM-dd HH:mm:ss.SSS} [%X{tid}] [%thread] %-5level %logger{36} -%msg%n
${SKY_LOG_PATTERN}
${log.path}/info.log
%d{yyyy-MM-dd HH:mm:ss.SSS} [%X{tid}] [%thread] %-5level %logger{36} -%msg%n
${log.path}/info/info-%d{yyyy-MM-dd}.%i.log
1GB
45
info
ACCEPT
DENY
${log.path}/warn.log
%d{yyyy-MM-dd HH:mm:ss.SSS} [%X{tid}] [%thread] %-5level %logger{36} -%msg%n
${log.path}/warn/warn-%d{yyyy-MM-dd}.%i.log
1GB
180
warn
ACCEPT
DENY
${log.path}/error.log
%d{yyyy-MM-dd HH:mm:ss.SSS} [%X{tid}] [%thread] %-5level %logger{36} -%msg%n
${log.path}/error/error-%d{yyyy-MM-dd}.%i.log
1GB
180
error
ACCEPT
DENY
查看日志:未集成完成会生成 TAD: N/A
2023-07-13 15:22:09.799 [http-nio-14001-exec-12] INFO cn. .zsyy.order.service.CommonOrderService - [TID: N/A] -
集成成日志文件内容如下(包含tid traceid):
2023-07-13 15:59:10.264 [TID:90e9717cda1147ec946db3c1bf7b0be6.132.16892351502620001] [http-nio-14001-exec-68] INFO c.u.z.s.aop.SentinelResourceAop -医院:1123010915235514310,ip:183.129.254.162,用户:null,请求:静态资源列表/resource/patient/list
2023-07-13 15:59:10.268 [TID:90e9717cda1147ec946db3c1bf7b0be6.132.16892351502620001] [http-nio-14001-exec-68] INFO c.u.z.s.aop.SentinelResourceAop -接口:/resource/patient/list,限流配置信息:[]
参考:
微服务日志通过agent接入skywalking 8.7配置方法_skywalking接入日志_程序猿(攻城狮)的博客-CSDN博客
mdc.TraceIdMDCPatternLogbackLayout">
%d{yyyy-MM-dd HH:mm:ss.SSS} [%X{tid}] [%thread] %-5level %logger{36} -%msg%n
-javaagent
参数激活
skywalking tracer,才会输出TraceID信息。 否则,TraceID信息将会是N/A
如何激活
skywalking traceid :
JAVA_OPTS = ' -javaagent:/home/opt/skywalking-agent/skywalking-agent.jar -DSW_AGENT_COLLEC
TOR_BACKEND_SERVICES=172.150.1.29:11800 -Dskywalking.agent.service_name=zsyy-api'
]# more zsyy-api.env
APP_LOG_PATH=/home/logs/zsyy-api-skywalking/SW_AGENT_NAME=zsyy-api
SW_AGENT_COLLECTOR_BACKEND_SERVICES=172.150.1.29:11800
SW_LOGGING_LEVEL=debug
SW_LOGGING_DIR=${APP_LOG_PATH}
SW_GRPC_LOG_MAX_MESSAGE_SIZE=10485760SW_LOGGING_MAX_FILE_SIZE=1000000000
SW_LOGGING_MAX_HISTORY_FILES=180
SW_MYSQL_TRACE_SQL_PARAMETERS=true
SW_SPRING_MVC_USE_QUALIFIED_NAME_AS_ENDPOINT_NAME=true