• skywalking日志上送和链路追踪


    在写之前先记录一个小tip,skywalking不仅可以监控微服务的应用,对于老的服务,比如war包部署在tomcat的都是可以监控到的,但是需要修改插件,文中第三部分会提到,有使用到的可以参考。

    官方文档连接Documentation | Apache SkyWalkinghttps://skywalking.apache.org/docs

    搭建服务

    1.下载skywalking安装包

    Downloads | Apache SkyWalking

    下载的时候需要注意,如果要使用服务日志上送功能,必须下载8.5之后的版本,8.5之前的不支持日志功能,控制台的那个service点不动。

    2.目录讲解

    可以简单看下目录讲解 因为后续使用会用到,比如命令行增加agent的时候会读取agent包同目录下的配置文件等。

    3.设置配置文件 config/application.yml

    这个配置文件主要修改持久化数据源的相关配置,我这里修改为mysql。

    1. storage:
    2. # 修改存储引擎为mysql
    3. selector: ${SW_STORAGE:mysql}
    4. ……
    5. mysql:
    6. properties:
    7. # 修改ip和数据库
    8. jdbcUrl: ${SW_JDBC_URL:"jdbc:mysql://localhost:3306/swtest"}
    9. # 修改用户名
    10. dataSource.user: ${SW_DATA_SOURCE_USER:root}
    11. 修改密码
    12. dataSource.password: ${SW_DATA_SOURCE_PASSWORD:root}
    13. ……

            skywalking支持的插拔式的数据源,有H2,mysql,elasticsearch等。

            文章开头提到的监控老服务的插件在apache-skywalking-apm-bin\agent\bootstrap-plugins  目录下,包名为apm-jdk-http-plugin-8.5.0,将此包赋值到plugins文件夹下在启动即可监控老服务,我这里struts服务请求都是可以监控的,原理其实就是链路打标是在请求中放到请求头中的,skywalking官方文档写了几种支持的请求方式,对于老的请求不能直接支持的,也提供了插件进行监控,所以进行上述操作之后即可正常监控老服务。

    4.下载MySQL连接jar

            下载链接:mysql-connector-java-5.1.49.jar--对应mysql版本

            将jar包放在oap-libs目录下即可,如果没有连接jar包,会抛如下异常:日志文件路径在logs下

    1. Failed to get driver instance for jdbcUrl=jdbc:mysql://localhost:3306/swtest
    2. No suitable driver

    5.启动服务

    6.测试

     7.如果是jar包服务 启动命令增加 如下命令

     -javaagent:E:\BaiduNetdiskDownload\apache-skywalking-apm-bin\agent\skywalking-agent.jar -Dskywalking.agent.service_name=admin -Dskywalking.collector.backend_service=localhost:11800`

            需要注意的 是skywalking-agent.jar包所在的文件夹需要有对应的插件和配置文件等 ,可以直接将skywalking安装路径下的此文件夹复制过去,配置文件如下

            包括注册名称,skywalking地址,数据库连接等配置信息。

    1. # Licensed to the Apache Software Foundation (ASF) under one
    2. # or more contributor license agreements. See the NOTICE file
    3. # distributed with this work for additional information
    4. # regarding copyright ownership. The ASF licenses this file
    5. # to you under the Apache License, Version 2.0 (the
    6. # "License"); you may not use this file except in compliance
    7. # with the License. You may obtain a copy of the License at
    8. #
    9. # http://www.apache.org/licenses/LICENSE-2.0
    10. #
    11. # Unless required by applicable law or agreed to in writing, software
    12. # distributed under the License is distributed on an "AS IS" BASIS,
    13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14. # See the License for the specific language governing permissions and
    15. # limitations under the License.
    16. # The agent namespace
    17. # agent.namespace=${SW_AGENT_NAMESPACE:default-namespace}
    18. # The service name in UI
    19. agent.service_name=${SW_AGENT_NAME:payservice}
    20. # The number of sampled traces per 3 seconds
    21. # Negative or zero means off, by default
    22. # agent.sample_n_per_3_secs=${SW_AGENT_SAMPLE:-1}
    23. # Authentication active is based on backend setting, see application.yml for more details.
    24. # agent.authentication = ${SW_AGENT_AUTHENTICATION:xxxx}
    25. # The max amount of spans in a single segment.
    26. # Through this config item, SkyWalking keep your application memory cost estimated.
    27. # agent.span_limit_per_segment=${SW_AGENT_SPAN_LIMIT:150}
    28. # Ignore the segments if their operation names end with these suffix.
    29. # agent.ignore_suffix=${SW_AGENT_IGNORE_SUFFIX:.jpg,.jpeg,.js,.css,.png,.bmp,.gif,.ico,.mp3,.mp4,.html,.svg}
    30. # If true, SkyWalking agent will save all instrumented classes files in `/debugging` folder.
    31. # SkyWalking team may ask for these files in order to resolve compatible problem.
    32. # agent.is_open_debugging_class = ${SW_AGENT_OPEN_DEBUG:true}
    33. # If true, SkyWalking agent will cache all instrumented classes files to memory or disk files (decided by class cache mode),
    34. # allow other javaagent to enhance those classes that enhanced by SkyWalking agent.
    35. # agent.is_cache_enhanced_class = ${SW_AGENT_CACHE_CLASS:false}
    36. # The instrumented classes cache mode: MEMORY or FILE
    37. # MEMORY: cache class bytes to memory, if instrumented classes is too many or too large, it may take up more memory
    38. # FILE: cache class bytes in `/class-cache` folder, automatically clean up cached class files when the application exits
    39. # agent.class_cache_mode = ${SW_AGENT_CLASS_CACHE_MODE:MEMORY}
    40. # The operationName max length
    41. # Notice, in the current practice, we don't recommend the length over 190.
    42. # agent.operation_name_threshold=${SW_AGENT_OPERATION_NAME_THRESHOLD:150}
    43. # If true, skywalking agent will enable profile when user create a new profile task. Otherwise disable profile.
    44. # profile.active=${SW_AGENT_PROFILE_ACTIVE:true}
    45. # Parallel monitor segment count
    46. # profile.max_parallel=${SW_AGENT_PROFILE_MAX_PARALLEL:5}
    47. # Max monitor segment time(minutes), if current segment monitor time out of limit, then stop it.
    48. # profile.duration=${SW_AGENT_PROFILE_DURATION:10}
    49. # Max dump thread stack depth
    50. # profile.dump_max_stack_depth=${SW_AGENT_PROFILE_DUMP_MAX_STACK_DEPTH:500}
    51. # Snapshot transport to backend buffer size
    52. # profile.snapshot_transport_buffer_size=${SW_AGENT_PROFILE_SNAPSHOT_TRANSPORT_BUFFER_SIZE:50}
    53. # Backend service addresses.
    54. collector.backend_service=${SW_AGENT_COLLECTOR_BACKEND_SERVICES:192.168.121.117:11800}
    55. # Logging file_name
    56. logging.file_name=${SW_LOGGING_FILE_NAME:skywalking-api.log}
    57. # Logging level
    58. logging.level=${SW_LOGGING_LEVEL:INFO}
    59. # Logging dir
    60. # logging.dir=${SW_LOGGING_DIR:""}
    61. # Logging max_file_size, default: 300 * 1024 * 1024 = 314572800
    62. # logging.max_file_size=${SW_LOGGING_MAX_FILE_SIZE:314572800}
    63. # The max history log files. When rollover happened, if log files exceed this number,
    64. # then the oldest file will be delete. Negative or zero means off, by default.
    65. # logging.max_history_files=${SW_LOGGING_MAX_HISTORY_FILES:-1}
    66. # Listed exceptions would not be treated as an error. Because in some codes, the exception is being used as a way of controlling business flow.
    67. # Besides, the annotation named IgnoredException in the trace toolkit is another way to configure ignored exceptions.
    68. # statuscheck.ignored_exceptions=${SW_STATUSCHECK_IGNORED_EXCEPTIONS:}
    69. # The max recursive depth when checking the exception traced by the agent. Typically, we don't recommend setting this more than 10, which could cause a performance issue. Negative value and 0 would be ignored, which means all exceptions would make the span tagged in error status.
    70. # statuscheck.max_recursive_depth=${SW_STATUSCHECK_MAX_RECURSIVE_DEPTH:1}
    71. # Mount the specific folders of the plugins. Plugins in mounted folders would work.
    72. plugin.mount=${SW_MOUNT_FOLDERS:plugins,activations}
    73. plugin.toolkit.log.grpc.reporter.server_host=${SW_GRPC_LOG_SERVER_HOST:192.168.121.117}
    74. plugin.toolkit.log.grpc.reporter.server_port=${SW_GRPC_LOG_SERVER_PORT:11800}
    75. plugin.toolkit.log.grpc.reporter.max_message_size=${SW_GRPC_LOG_MAX_MESSAGE_SIZE:10485760}
    76. plugin.toolkit.log.grpc.reporter.upstream_timeout=${SW_GRPC_LOG_GRPC_UPSTREAM_TIMEOUT:30}
    77. # Exclude activated plugins
    78. # plugin.exclude_plugins=${SW_EXCLUDE_PLUGINS:}
    79. # mysql plugin configuration
    80. # plugin.mysql.trace_sql_parameters=${SW_MYSQL_TRACE_SQL_PARAMETERS:false}
    81. # Kafka producer configuration
    82. # plugin.kafka.bootstrap_servers=${SW_KAFKA_BOOTSTRAP_SERVERS:localhost:9092}
    83. # Match spring bean with regex expression for classname
    84. # plugin.springannotation.classname_match_regex=${SW_SPRINGANNOTATION_CLASSNAME_MATCH_REGEX:}

    8、tomcat配置监控

            在catalina.sh行首加入 

    CATALINA_OPTS="$CATALINA_OPTS -javaagent:/opt/agent85/agent/skywalking-agent.jar"

            但是要记得这个skywalking-agent.jar包同目录下一定要有config配置, 可以直接将skywalking安装路径下的此文件夹复制过去。

    9.样例展示

    日志

    拓扑

     链路

     

     

  • 相关阅读:
    痞子衡嵌入式:浅谈i.MXRT1xxx系列MCU时钟相关功能引脚的作用
    Real-Time Rendering——9.9.3 Smooth-Surface Subsurface Models光滑表面地下模型
    跟羽夏学 Ghidra ——导航
    远程访问云服务器CentOS下 jupyter服务 【保姆级教程】
    看看Vue
    【毕业设计】1-基于单片机的城市轨道交通列车超速防护系统_里程表设计(原理图+PCB+源码+仿真工程+答辩论文)
    Clion~Clion常用配置和插件
    python使用pandas中的read_csv函数读取csv数据为dataframe、使用map函数和lower函数将指定字符串数据列的数据转化为小写字符串
    使用 PowerShell 将 Windows 转发事件导入 SQL Server
    leetcode 6104 统计星号
  • 原文地址:https://blog.csdn.net/qq_33790251/article/details/125536674