一、SkyWalking介绍

SkyWalking一个开源的可观测平台用于收集分析聚合可视化来自服务和云原生基础设施数据。SkyWalking 提供了一种简单方式来清晰地观测分布式系统,即使是横跨多个平台。它是一种现代 APM(application performance monitor),专为云原生基于容器分布式系统设计

二、SkyWalking下载

Downloads | Apache SkyWalking

这里选择SkyWalking 9.0.0

三、SkyWalking修改配置

3.1、application.yml

storage:
  selector: ${SW_STORAGE:mysql}
  elasticsearch:
    namespace: ${SW_NAMESPACE:""}
    clusterNodes: ${SW_STORAGE_ES_CLUSTER_NODES:localhost:9200}
    protocol: ${SW_STORAGE_ES_HTTP_PROTOCOL:"http"}
    connectTimeout: ${SW_STORAGE_ES_CONNECT_TIMEOUT:3000}
    socketTimeout: ${SW_STORAGE_ES_SOCKET_TIMEOUT:30000}
    responseTimeout: ${SW_STORAGE_ES_RESPONSE_TIMEOUT:15000}
    numHttpClientThread: ${SW_STORAGE_ES_NUM_HTTP_CLIENT_THREAD:0}
    user: ${SW_ES_USER:""}
    password: ${SW_ES_PASSWORD:""}
    trustStorePath: ${SW_STORAGE_ES_SSL_JKS_PATH:""}
    trustStorePass: ${SW_STORAGE_ES_SSL_JKS_PASS:""}
    secretsManagementFile: ${SW_ES_SECRETS_MANAGEMENT_FILE:""} # Secrets management file in the properties format includes the username, password, which are managed by 3rd party tool.
    dayStep: ${SW_STORAGE_DAY_STEP:1} # Represent the number of days in the one minute/hour/day index.
    indexShardsNumber: ${SW_STORAGE_ES_INDEX_SHARDS_NUMBER:1} # Shard number of new indexes
    indexReplicasNumber: ${SW_STORAGE_ES_INDEX_REPLICAS_NUMBER:1} # Replicas number of new indexes
    # Super data set has been defined in the codes, such as trace segments.The following 3 config would be improve es performance when storage super size data in es.
    superDatasetDayStep: ${SW_SUPERDATASET_STORAGE_DAY_STEP:-1} # Represent the number of days in the super size dataset record index, the default value is the same as dayStep when the value is less than 0
    superDatasetIndexShardsFactor: ${SW_STORAGE_ES_SUPER_DATASET_INDEX_SHARDS_FACTOR:5} #  This factor provides more shards for the super data set, shards number = indexShardsNumber * superDatasetIndexShardsFactor. Also, this factor effects Zipkin and Jaeger traces.
    superDatasetIndexReplicasNumber: ${SW_STORAGE_ES_SUPER_DATASET_INDEX_REPLICAS_NUMBER:0} # Represent the replicas number in the super size dataset record index, the default value is 0.
    indexTemplateOrder: ${SW_STORAGE_ES_INDEX_TEMPLATE_ORDER:0} # the order of index template
    bulkActions: ${SW_STORAGE_ES_BULK_ACTIONS:5000} # Execute the async bulk record data every ${SW_STORAGE_ES_BULK_ACTIONS} requests
    # flush the bulk every 10 seconds whatever the number of requests
    # INT(flushInterval * 2/3) would be used for index refresh period.
    flushInterval: ${SW_STORAGE_ES_FLUSH_INTERVAL:15}
    concurrentRequests: ${SW_STORAGE_ES_CONCURRENT_REQUESTS:2} # the number of concurrent requests
    resultWindowMaxSize: ${SW_STORAGE_ES_QUERY_MAX_WINDOW_SIZE:10000}
    metadataQueryMaxSize: ${SW_STORAGE_ES_QUERY_MAX_SIZE:10000}
    scrollingBatchSize: ${SW_STORAGE_ES_SCROLLING_BATCH_SIZE:5000}
    segmentQueryMaxSize: ${SW_STORAGE_ES_QUERY_SEGMENT_SIZE:200}
    profileTaskQueryMaxSize: ${SW_STORAGE_ES_QUERY_PROFILE_TASK_SIZE:200}
    oapAnalyzer: ${SW_STORAGE_ES_OAP_ANALYZER:"{"analyzer":{"oap_analyzer":{"type":"stop"}}}"} # the oap analyzer.
    oapLogAnalyzer: ${SW_STORAGE_ES_OAP_LOG_ANALYZER:"{"analyzer":{"oap_log_analyzer":{"type":"standard"}}}"} # the oap log analyzer. It could be customized by the ES analyzer configuration to support more language log formats, such as Chinese log, Japanese log and etc.
    advanced: ${SW_STORAGE_ES_ADVANCED:""}
  h2:
    driver: ${SW_STORAGE_H2_DRIVER:org.h2.jdbcx.JdbcDataSource}
    url: ${SW_STORAGE_H2_URL:jdbc:h2:mem:skywalking-oap-db;DB_CLOSE_DELAY=-1}
    user: ${SW_STORAGE_H2_USER:sa}
    metadataQueryMaxSize: ${SW_STORAGE_H2_QUERY_MAX_SIZE:5000}
    maxSizeOfArrayColumn: ${SW_STORAGE_MAX_SIZE_OF_ARRAY_COLUMN:20}
    numOfSearchableValuesPerTag: ${SW_STORAGE_NUM_OF_SEARCHABLE_VALUES_PER_TAG:2}
    maxSizeOfBatchSql: ${SW_STORAGE_MAX_SIZE_OF_BATCH_SQL:100}
    asyncBatchPersistentPoolSize: ${SW_STORAGE_ASYNC_BATCH_PERSISTENT_POOL_SIZE:1}
  mysql:
    properties:
      jdbcUrl: ${SW_JDBC_URL:"jdbc:mysql://localhost:3306/swtest?rewriteBatchedStatements=true"}
      dataSource.user: ${SW_DATA_SOURCE_USER:root}
      dataSource.password: ${SW_DATA_SOURCE_PASSWORD:123456}
      dataSource.cachePrepStmts: ${SW_DATA_SOURCE_CACHE_PREP_STMTS:true}
      dataSource.prepStmtCacheSize: ${SW_DATA_SOURCE_PREP_STMT_CACHE_SQL_SIZE:250}
      dataSource.prepStmtCacheSqlLimit: ${SW_DATA_SOURCE_PREP_STMT_CACHE_SQL_LIMIT:2048}
      dataSource.useServerPrepStmts: ${SW_DATA_SOURCE_USE_SERVER_PREP_STMTS:true}
    metadataQueryMaxSize: ${SW_STORAGE_MYSQL_QUERY_MAX_SIZE:5000}
    maxSizeOfArrayColumn: ${SW_STORAGE_MAX_SIZE_OF_ARRAY_COLUMN:20}
    numOfSearchableValuesPerTag: ${SW_STORAGE_NUM_OF_SEARCHABLE_VALUES_PER_TAG:2}
    maxSizeOfBatchSql: ${SW_STORAGE_MAX_SIZE_OF_BATCH_SQL:2000}
    asyncBatchPersistentPoolSize: ${SW_STORAGE_ASYNC_BATCH_PERSISTENT_POOL_SIZE:4}

这里采用的是mysql数据库,也可以选择其他数据库,需要拷贝对应驱动进去,例如mysql,就拷贝mysqlconnector-j-8.0.33.jarapacheskywalkingapmbinoap-libs目录中。

3.2、修改webapp.yml

server:
  port: 9090

spring:
  cloud:
    gateway:
      routes:
        - id: oap-route
          uri: lb://oap-service
          predicates:
            - Path=/graphql/**
    discovery:
      client:
        simple:
          instances:
            oap-service:
              - uri: http://127.0.0.1:12800
            # - uri: http://<oap-host-1>:<oap-port1>
            # - uri: http://<oap-host-2>:<oap-port2>

  mvc:
    throw-exception-if-no-handler-found: true

  web:
    resources:
      add-mappings: true

management:
  server:
    base-path: /manage

 3.3、启动skywalking

进入bin下面,直接启动startup.bat

http://127.0.0.1:9090

四、SkyWalking在springboot中的应用

4.1、引入对应jar

<dependency>
			<groupId>org.apache.skywalking</groupId>
			<artifactId>apm-toolkit-trace</artifactId>
			<version>9.0.0</version>
		</dependency>
		<dependency>
			<groupId>org.apache.skywalking</groupId>
			<artifactId>apm-toolkit-logback-1.x</artifactId>
			<version>9.0.0</version>
		</dependency>

4.2、修改logbackspring.xml配置文件

<configuration scan="true" scanPeriod=" 5 seconds">
	<!-- 默认日志配置 -->
	<springProfile name="default">
		<appender name="console"
			class="ch.qos.logback.core.ConsoleAppender">
			<encoder>
				<pattern>
					%d{yyyy-MM-dd HH:mm:ss.SSS}  [%thread] %-5level %logger{36} - %msg%n
				</pattern>
			</encoder>
		</appender>
		<root level="INFO">
			<appender-ref ref="console" />
		</root>
	</springProfile>

	<!-- SkyWalking配置(注:此处需通过spring.profiles.active=skywalking激活) -->
	<springProfile name="skywalking">
	
		<appender name="STDOUT"
			class="ch.qos.logback.core.ConsoleAppender">
			<encoder
				class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
				<layout
					class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.mdc.TraceIdMDCPatternLogbackLayout">
					<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%X{tid}] [%thread] %-5level %logger{36} -%msg%n</Pattern>
				</layout>
			</encoder>
		</appender>

		<appender name="STDOUT_ASYNC"
			class="ch.qos.logback.classic.AsyncAppender">
			<discardingThreshold>0</discardingThreshold>
			<queueSize>1024</queueSize>
			<neverBlock>true</neverBlock>
			<appender-ref ref="STDOUT" />
		</appender>

		<appender name="DEBUG_FILE"
			class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender">
			<encoder
				class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
				<layout
					class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.mdc.TraceIdMDCPatternLogbackLayout">
					<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%X{tid}] [%thread] %-5level %logger{36} -%msg%n</Pattern>
				</layout>
			</encoder>
		</appender>
		
		<appender name="DEBUG_FILE_ASYNC"
			class="ch.qos.logback.classic.AsyncAppender">
			<discardingThreshold>0</discardingThreshold>
			<queueSize>1024</queueSize>
			<neverBlock>true</neverBlock>
			<appender-ref ref="DEBUG_FILE" />
		</appender>

		<logger name="com.apache.ibatis" level="ERROR" />
		<logger name="com.zaxxer.hikari" level="WARN" />
		<logger name="io.lettuce.core" level="WARN" />
		<logger name="org.hibernate.validator" level="ERROR" />
		<logger name="org.springframework" level="WARN" />
		<logger name="org.mybatis.spring" level="WARN" />
		<logger name="java.sql.Connection" level="ERROR" />
		<logger name="java.sql.Statement" level="WARN" />
		<logger name="java.sql.PreparedStatement" level="DEBUG" />

		<root level="DEBUG">
			<appender-ref ref="STDOUT_ASYNC" />
			<appender-ref ref="DEBUG_FILE_ASYNC" />
		</root>
	</springProfile>
</configuration>

4.3、增加agent

-javaagent:D:workspaceapache-skywalking-java-agent-9.0.0skywalking-agentskywalking-agent.jar -DSW_AGENT_NAME=group -DSW_AGENT_NAME=skywalking-bigdata-system -DSW_AGENT_COLLECTOR_BACKEND_SERVICES=127.0.0.1:11800

4.4、修改application.yml

spring:
  application:
    name: demobigdata
  profiles:
    active: mybatis,skywalking



logging:
  config: classpath:logback-spring.xml

4.5、启动springboot服务

直接启动Application

五、SkyWalking在springcloud应用

5.1、在gateway中的配置

5.1.1、引入jar

<dependency>
			<groupId>org.apache.skywalking</groupId>
			<artifactId>apm-toolkit-trace</artifactId>
			<version>9.0.0</version>
		</dependency>
		<dependency>
			<groupId>org.apache.skywalking</groupId>
			<artifactId>apm-toolkit-logback-1.x</artifactId>
			<version>9.0.0</version>
		</dependency>

5.1.2、修改日志配置

<configuration scan="true" scanPeriod=" 5 seconds">
	<!-- 默认日志配置 -->
	<springProfile name="default">
		<appender name="console"
			class="ch.qos.logback.core.ConsoleAppender">
			<encoder>
				<pattern>
					%d{yyyy-MM-dd HH:mm:ss.SSS}  [%thread] %-5level %logger{36} - %msg%n
				</pattern>
			</encoder>
		</appender>
		<root level="INFO">
			<appender-ref ref="console" />
		</root>
	</springProfile>

	<!-- SkyWalking配置(注:此处需通过spring.profiles.active=skywalking激活) -->
	<springProfile name="skywalking">
	
		<appender name="STDOUT"
			class="ch.qos.logback.core.ConsoleAppender">
			<encoder
				class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
				<layout
					class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.mdc.TraceIdMDCPatternLogbackLayout">
					<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%X{tid}] [%thread] %-5level %logger{36} -%msg%n</Pattern>
				</layout>
			</encoder>
		</appender>

		<appender name="STDOUT_ASYNC"
			class="ch.qos.logback.classic.AsyncAppender">
			<discardingThreshold>0</discardingThreshold>
			<queueSize>1024</queueSize>
			<neverBlock>true</neverBlock>
			<appender-ref ref="STDOUT" />
		</appender>

		<appender name="DEBUG_FILE"
			class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender">
			<encoder
				class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
				<layout
					class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.mdc.TraceIdMDCPatternLogbackLayout">
					<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%X{tid}] [%thread] %-5level %logger{36} -%msg%n</Pattern>
				</layout>
			</encoder>
		</appender>
		
		<appender name="DEBUG_FILE_ASYNC"
			class="ch.qos.logback.classic.AsyncAppender">
			<discardingThreshold>0</discardingThreshold>
			<queueSize>1024</queueSize>
			<neverBlock>true</neverBlock>
			<appender-ref ref="DEBUG_FILE" />
		</appender>

		<logger name="com.apache.ibatis" level="ERROR" />
		<logger name="com.zaxxer.hikari" level="WARN" />
		<logger name="io.lettuce.core" level="WARN" />
		<logger name="org.hibernate.validator" level="ERROR" />
		<logger name="org.springframework" level="WARN" />
		<logger name="org.mybatis.spring" level="WARN" />
		<logger name="java.sql.Connection" level="ERROR" />
		<logger name="java.sql.Statement" level="WARN" />
		<logger name="java.sql.PreparedStatement" level="DEBUG" />

		<root level="DEBUG">
			<appender-ref ref="STDOUT_ASYNC" />
			<appender-ref ref="DEBUG_FILE_ASYNC" />
		</root>
	</springProfile>
</configuration>

5.1.3、修改application.yml

spring:
  application:
    name:  gateway-consumer
  profiles:
    active: dubbo,ext,skywalking
logging:
  config: classpath:logback-spring.xml

5.1.4、增加agent

-javaagent:D:workspaceapache-skywalking-java-agent-9.0.0skywalking-agentskywalking-agent.jar -DSW_AGENT_NAME=group -DSW_AGENT_NAME=skywalking-gateway-system  -DSW_AGENT_COLLECTOR_BACKEND_SERVICES=127.0.0.1:11800

5.1.5、启动网关

GatewayApplication

5.2、在user原则服务中的配置

5.2.1、引入jar

<dependency>
			<groupId>org.apache.skywalking</groupId>
			<artifactId>apm-toolkit-trace</artifactId>
			<version>9.0.0</version>
		</dependency>
		<dependency>
			<groupId>org.apache.skywalking</groupId>
			<artifactId>apm-toolkit-logback-1.x</artifactId>
			<version>9.0.0</version>
		</dependency>

5.2.2、修改日志配置

<configuration scan="true" scanPeriod=" 5 seconds">
	<!-- 默认日志配置 -->
	<springProfile name="default">
		<appender name="console"
			class="ch.qos.logback.core.ConsoleAppender">
			<encoder>
				<pattern>
					%d{yyyy-MM-dd HH:mm:ss.SSS}  [%thread] %-5level %logger{36} - %msg%n
				</pattern>
			</encoder>
		</appender>
		<root level="INFO">
			<appender-ref ref="console" />
		</root>
	</springProfile>

	<!-- SkyWalking配置(注:此处需通过spring.profiles.active=skywalking激活) -->
	<springProfile name="skywalking">
	
		<appender name="STDOUT"
			class="ch.qos.logback.core.ConsoleAppender">
			<encoder
				class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
				<layout
					class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.mdc.TraceIdMDCPatternLogbackLayout">
					<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%X{tid}] [%thread] %-5level %logger{36} -%msg%n</Pattern>
				</layout>
			</encoder>
		</appender>

		<appender name="STDOUT_ASYNC"
			class="ch.qos.logback.classic.AsyncAppender">
			<discardingThreshold>0</discardingThreshold>
			<queueSize>1024</queueSize>
			<neverBlock>true</neverBlock>
			<appender-ref ref="STDOUT" />
		</appender>

		<appender name="DEBUG_FILE"
			class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender">
			<encoder
				class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
				<layout
					class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.mdc.TraceIdMDCPatternLogbackLayout">
					<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%X{tid}] [%thread] %-5level %logger{36} -%msg%n</Pattern>
				</layout>
			</encoder>
		</appender>
		
		<appender name="DEBUG_FILE_ASYNC"
			class="ch.qos.logback.classic.AsyncAppender">
			<discardingThreshold>0</discardingThreshold>
			<queueSize>1024</queueSize>
			<neverBlock>true</neverBlock>
			<appender-ref ref="DEBUG_FILE" />
		</appender>

		<logger name="com.apache.ibatis" level="ERROR" />
		<logger name="com.zaxxer.hikari" level="WARN" />
		<logger name="io.lettuce.core" level="WARN" />
		<logger name="org.hibernate.validator" level="ERROR" />
		<logger name="org.springframework" level="WARN" />
		<logger name="org.mybatis.spring" level="WARN" />
		<logger name="java.sql.Connection" level="ERROR" />
		<logger name="java.sql.Statement" level="WARN" />
		<logger name="java.sql.PreparedStatement" level="DEBUG" />

		<root level="DEBUG">
			<appender-ref ref="STDOUT_ASYNC" />
			<appender-ref ref="DEBUG_FILE_ASYNC" />
		</root>
	</springProfile>
</configuration>

5.2.3、修改application.yml

spring:
  application:
    name: users-provider
  profiles:
    active: dev,mybatis,skywalking
logging:
  config: classpath:logback-spring.xml

5.2.4、增加agent

-javaagent:D:workspaceapache-skywalking-java-agent-9.0.0skywalking-agentskywalking-agent.jar -DSW_AGENT_NAME=group -DSW_AGENT_NAME=skywalking-users-system  -DSW_AGENT_COLLECTOR_BACKEND_SERVICES=127.0.0.1:11800

5.2.5、启动原子服务

UsersApplication

5.3、因为采用的是微服框架,需要启动服务治理框架nacos

六、SkyWalking服务界面

 

 

这样skywalking就启动了,里面细节可以值得深入的研究,也可以研究源代码

原文地址:https://blog.csdn.net/itorac/article/details/134621967

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_27082.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注