skywalking使用入门
一、版本问题
8版本与9版本UI差距很大,选择8.9版
官方文档:
https://skywalking.apache.org/docs/main/v8.9.1/readme/
使用环境springboot1.5.6,默认导入的lockback版本为1.1.11,skywalking日志功能启动就会报错,使用1.2.3解决此问题
探针日志命令:
tail -f skywalking-api.log
探针日志报错:
ERROR 2022-09-01 16:05:42:144 main InstMethodsInter : class[class org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender] before method[subAppend] intercept failure
java.lang.NoSuchMethodError: ch.qos.logback.core.encoder.Encoder.encode(Ljava/lang/Object;)[B
at org.apache.skywalking.apm.toolkit.activation.log.logback.v1.x.log.GRPCLogAppenderInterceptor.transformLogText(GRPCLogAppenderInterceptor.java:125)
at org.apache.skywalking.apm.toolkit.activation.log.logback.v1.x.log.GRPCLogAppenderInterceptor.transform(GRPCLogAppenderInterceptor.java:114)
at org.apache.skywalking.apm.toolkit.activation.log.logback.v1.x.log.GRPCLogAppenderInterceptor.beforeMethod(GRPCLogAppenderInterceptor.java:60)
at org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstMethodsInter.intercept(InstMethodsInter.java:76)
at org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender.subAppend(GRPCLogClientAppender.java)
at ch.qos.logback.core.OutputStreamAppender.append(OutputStreamAppender.java:100)
at ch.qos.logback.core.UnsynchronizedAppenderBase.doAppend(UnsynchronizedAppenderBase.java:84)
at ch.qos.logback.core.spi.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:51)
at ch.qos.logback.classic.Logger.appendLoopOnAppenders(Logger.java:270)
at ch.qos.logback.classic.Logger.callAppenders(Logger.java:257)
at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:421)
at ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Logger.java:383)
at ch.qos.logback.classic.Logger.log(Logger.java:765)
at org.apache.commons.logging.impl.SLF4JLocationAwareLog.info(SLF4JLocationAwareLog.java:155)
at org.springframework.boot.StartupInfoLogger.logStarted(StartupInfoLogger.java:57)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:309)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
at com.example.providerdemo.ProviderDemoApplication.main(ProviderDemoApplication.java:14)
添加maven包:
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.2.3</version>
</dependency>
二、服务接入
1.添加JVM参数方式
// 探针包路径,注意探针不只是一个jar,整个agent目录文件都需要
-javaagent:/abc/apache-skywalking-apm-bin/agent/skywalking-agent.jar
// skywalking服务名称
-DSW_AGENT_NAME=consumer-demo
// skywalking所在服务器ip
-DSW_AGENT_COLLECTOR_BACKEND=127.0.0.1:11800
2.启动服务
./bin/startup.sh
三、使用MySQL存储数据
1.默认用H2,重启数据丢失,最好采用elasticsearch
2.编辑配置文件
cd config
vi application.yml
----
storage:
selector: ${SW_STORAGE:mysql}
mysql:
properties:
# 数据库提前创建,不需要创建表,自动生成表
jdbcUrl: ${SW_JDBC_URL:"jdbc:mysql://127.0.0.1:3306/swtest?rewriteBatchedStatements=true"}
dataSource.user: ${SW_DATA_SOURCE_USER:root}
dataSource.password: ${SW_DATA_SOURCE_PASSWORD:123456}
3.启动报错
tail -f skywalking-oap-server.log
----
2022-09-01 17:27:44,729 - org.apache.skywalking.oap.server.starter.OAPServerBootstrap - 60 [main] ERROR [] - Failed to get driver instance for jdbcUrl=jdbc:mysql://123.56.110.107:3306/swtest?rewriteBatchedStatements=true
java.lang.RuntimeException: Failed to get driver instance for jdbcUrl=jdbc:mysql://123.56.110.107:3306/swtest?rewriteBatchedStatements=true
at com.zaxxer.hikari.util.DriverDataSource.<init>(DriverDataSource.java:110) ~[HikariCP-3.1.0.jar:?]
at com.zaxxer.hikari.pool.PoolBase.initializeDataSource(PoolBase.java:334) ~[HikariCP-3.1.0.jar:?]
at com.zaxxer.hikari.pool.PoolBase.<init>(PoolBase.java:109) ~[HikariCP-3.1.0.jar:?]
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:108) ~[HikariCP-3.1.0.jar:?]
at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:81) ~[HikariCP-3.1.0.jar:?]
at org.apache.skywalking.oap.server.library.client.jdbc.hikaricp.JDBCHikariCPClient.connect(JDBCHikariCPClient.java:54) ~[library-client-8.9.1.jar:8.9.1]
at org.apache.skywalking.oap.server.storage.plugin.jdbc.mysql.MySQLStorageProvider.start(MySQLStorageProvider.java:185) ~[storage-jdbc-hikaricp-plugin-8.9.1.jar:8.9.1]
at org.apache.skywalking.oap.server.library.module.BootstrapFlow.start(BootstrapFlow.java:49) ~[library-module-8.9.1.jar:8.9.1]
at org.apache.skywalking.oap.server.library.module.ModuleManager.init(ModuleManager.java:60) ~[library-module-8.9.1.jar:8.9.1]
at org.apache.skywalking.oap.server.starter.OAPServerBootstrap.start(OAPServerBootstrap.java:44) [server-starter-8.9.1.jar:8.9.1]
at org.apache.skywalking.oap.server.starter.OAPServerStartUp.main(OAPServerStartUp.java:23) [server-starter-8.9.1.jar:8.9.1]
Caused by: java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(DriverManager.java:315) ~[?:1.8.0_322]
at com.zaxxer.hikari.util.DriverDataSource.<init>(DriverDataSource.java:103) ~[HikariCP-3.1.0.jar:?]
... 10 more
在ops-lib加上MySQL驱动包:
cd oap-libs
cp mysql-connector-java-8.0.16.jar /.....
./startup.sh
启动会建154张表