SpringCloud ---- Advanced Applications

1, link tracking

  Micro-service architecture is divided by business services, using REST calls. An interface of external exposure, may take many months to complete this collaborative service interface function, if any problems with a service or a network timeout on the link will lead to the formation of the interface call failed. With the continuous expansion of business, call each other between services will become increasingly complex.

 

As more and more services, analysis of the call chain will become increasingly complex. Maybe call the relationship between them as follows:

 

 Face of the above, we need some help understanding the behavior of the system, tools for analyzing performance problems, so the event of failure to quickly locate and solve the problem, which is called the APM (Application Performance Management).

What is SkyWalking

At present, some of APM tools: Cat, Zipkin, Pinpoint, SkyWalking; Apache SkyWalking observational analysis platform and application performance management systems. Provide distributed tracking, telemetry service grid analysis, metrics aggregation and visualization integration solutions.

 

  • Skywalking Agent: JavaAgent done using bytecode implant, no invasive collection, and transmits the data to the SkyWalking Collector via HTTP or gRPC manner.
  • SkyWalking Collector: link data collector, to pass over the agent integrating the data analysis process and store data associated fall.
  • Storage: SkyWalking storage, the change of time, SW iterations have been developed to version 6.x, supports ElasticSearch (support 6.x) In version 6.x, Mysql, TiDB, H2, as a storage medium for data storage.
  • UI: Web visualization platform, used to display landing data.

SkyWalking Features

  • A variety of monitoring tools, probes and language service grid (Service Mesh)
  • Multilingual automatic probe, Java, .NET Core and Node.JS
  • Lightweight and efficient, does not require large data
  • Modular, UI, storage, cluster management a variety of optional mechanisms
  • Support alarm
  • Excellent visualization program

1.1SkyWalking server configuration

Based Docker installation ElasticSearch

docker-compose.yml

version: '3.3'
services:
  elasticsearch:
    image: wutang/elasticsearch-shanghai-zone:6.3.2  //官网elasticsearch启动会报错
    container_name: elasticsearch
    restart: always
    ports:
      - 9200:9200
      - 9300:9300
    environment:
      cluster.name: elasticsearch

 其中,9200 端口号为 SkyWalking 配置 ElasticSearch 所需端口号,cluster.name 为 SkyWalking 配置 ElasticSearch 集群的名称

测试是否启动成功

浏览器访问 http://elasticsearchIP:9200/ ,浏览器返回如下信息即表示成功启动

下载并启动 SkyWalking

官方已经为我们准备好了编译过的服务端版本,下载地址为 http://skywalking.apache.org/downloads/,这里我们需要下载 6.x releases 版本

配置 SkyWalking

下载完成后解压缩,进入 apache-skywalking-apm-incubating/config 目录并修改 application.yml 配置文件

 

这里需要做三件事:

  • 注释 H2 存储方案
  • 启用 ElasticSearch 存储方案
  • 修改 ElasticSearch 服务器地址

启动 SkyWalking

默认占用端口号:8080

修改完配置后,进入 apache-skywalking-apm-incubating\bin 目录,运行 startup.bat 启动服务端

通过浏览器访问 http://localhost:8080 出现如下界面即表示启动成功

  默认的用户名密码为:admin/admin,登录成功后,效果如下图

 

1.2SkyWalking 客户端配置

Java Agent 服务器探针

参考官网给出的帮助 Setup java agent,我们需要使用官方提供的探针为我们达到监控的目的,按照实际情况我们需要实现三种部署方式

  • IDEA 部署探针
  • Java 启动方式部署探针(我们是 Spring Boot 应用程序,需要使用 java -jar 的方式启动应用)
  • Docker 启动方式部署探针(需要做到一次构建到处运行的持续集成效果,本章节暂不提供解决方案,到后面的实战环节再实现)

探针文件在 apache-skywalking-apm-incubating/agent 目录下

IDEA 部署探针

继续之前的案例项目,创建一个名为 hello-spring-cloud-external-skywalking 的目录,并将 agent 整个目录拷贝进来

 

 修改项目的 VM 运行参数,点击菜单栏中的 Run -> EditConfigurations...,此处我们以 nacos-provider 项目为例,修改参数如下

-javaagent:D:\Workspace\Others\hello-spring-cloud-alibaba\hello-spring-cloud-external-skywalking\agent\skywalking-agent.jar
-Dskywalking.agent.service_name=nacos-provider
-Dskywalking.collector.backend_service=localhost:11800

  • -javaagent:用于指定探针路径
  • -Dskywalking.agent.service_name:用于重写 agent/config/agent.config 配置文件中的服务名
  • -Dskywalking.collector.backend_service:用于重写 agent/config/agent.config 配置文件中的服务地址 

Java 启动方式

java -javaagent:/path/to/skywalking-agent/skywalking-agent.jar -Dskywalking.agent.service_name=nacos-provider -Dskywalking.collector.backend_service=localhost:11800 -jar yourApp.jar 

测试监控

启动 nacos-provider 项目,通过观察日志可以发现,已经成功加载探针

 

 访问之前写好的接口 http://localhost:8081/echo/hi 之后再刷新 SkyWalking Web UI,你会发现 Service 与 Endpoint 已经成功检测到了

 

 

 至此,表示 SkyWalking 链路追踪配置成功

SkyWalking Trace 监控

SkyWalking 通过业务调用监控进行依赖分析,提供给我们了服务之间的服务调用拓扑关系、以及针对每个 Endpoint 的 Trace 记录。

调用链路监控

点击 Trace 菜单,进入追踪页

点击 Trace ID 展开详细信息

 

上图展示了一次正常的响应,总响应时间为 185ms 共有一个 Span(基本工作单元,表示一次完整的请求,包含响应,即请求并响应)

Span /echo/{message} 说明如下:

  • Duration:响应时间 185 毫秒
  • component:组件类型为 SpringMVC
  • url:请求地址
  • http.method:请求类型

 

服务性能指标监控

点击 Service 菜单,进入服务性能指标监控页

 选择希望监控的服务

 

 

  • Avg SLA: 服务可用性(主要是通过请求成功与失败次数来计算)
  • CPM: 每分钟调用次数
  • Avg Response Time: 平均响应时间

点击 More Server Details... 还可以查看详细信息

 

 

上图中展示了服务在一定时间范围内的相关数据,包括:

  • 服务可用性指标 SLA
  • 每分钟平均响应数
  • 平均响应时间
  • 服务进程 PID
  • 服务所在物理机的 IP、Host、OS
  • 运行时 CPU 使用率
  • 运行时堆内存使用率
  • 运行时非堆内存使用率
  • GC 情况

 

Guess you like

Origin www.cnblogs.com/yanxiaoge/p/11073706.html