skywalking简介下


四:skywalking案例:

• 4.1.halo博客实现链路追踪案例:

java应用示例-java命令运行halo博客并实现链路追踪:

https://docs.halo.run/getting-started/prepare/

image-20221017195944589

halo博客案例-准备skywalking java agent:

image-20221017200118871

halo博客案例-准备skywalking java agent:

1
2
root@skywalking-agent:~# ls /data/apache-skywalking-java-agent- 8.8.0.tgz
/data/apache-skywalking-java-agent-8.8.0.tgz

halo博客案例-部署jdk 11环境:

#Halo 是一款现代化的个人独立博客系统,而且可能是最好的Java博客系统,从 1.4.3 起,版本要求为 11 以上的版本,1.4.3 以下需要 1.8 以上的版本。

1
2
3
4
5
#apt install openjdk-11-jdk
root@skywalking-agent:/apps# java -version
openjdk version "11.0.16" 2022-07-19
OpenJDK Runtime Environment (build 11.0.16+8-post-Ubuntu-0ubuntu118.04)
OpenJDK 64-Bit Server VM (build 11.0.16+8-post-Ubuntu-0ubuntu118.04, mixed mode, sharing)

halo博客案例-skywalking-java-agent部署:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
root@skywalking-agent:/apps/skywalking-agent# tar -xvf apache-skywalking-java-agent
-8.8.0.tgz
root@skywalking-agent:/apps# cd skywalking-agent/
root@skywalking-agent:/apps/skywalking-agent# ls -ltr
total 18852
-rw-rw-r-- 1 1012 1013 19234737 Oct 27 2021 skywalking-agent.jar
-rw-rw-r-- 1 1012 1013 10003 Oct 27 2021 NOTICE
drwxrwxr-x 2 1012 1013 4096 Oct 27 2021 logs
drwxrwxr-x 2 1012 1013 4096 Oct 27 2021 licenses
-rw-rw-r-- 1 1012 1013 12911 Oct 27 2021 LICENSE
drwxrwxr-x 2 1012 1013 4096 Oct 27 2021 config
drwxrwxr-x 2 1012 1013 12288 Oct 27 2021 plugins
drwxrwxr-x 2 1012 1013 4096 Oct 27 2021 activations
drwxrwxr-x 2 1012 1013 4096 Oct 27 2021 bootstrap-plugins
drwxrwxr-x 2 1012 1013 4096 Oct 27 2021 optional-plugins
drwxrwxr-x 2 1012 1013 4096 Oct 27 2021 optional-reporter-plugins

halo博客案例-配置加载 servcie参数:

1
2
3
4
5
6
root@skywalking-agent:/data/skywalking-agent# pwd
/data/skywalking-agent
root@skywalking-agent:/data/skywalking-agent# vim config/agent.config
agent.namespace=${SW_AGENT_NAMESPACE:halo}
agent.service_name=${SW_AGENT_NAME:halo}
collector.backend_service=${SW_AGENT_COLLECTOR_BACKEND_SERVICES:192.168.3.81:11800}

halo博客案例-halo app下载:

1
2
3
4
5
6
7
8
9
https://dl.halo.run/release/
root@skywalking-agent:/apps# pwd
/apps
root@skywalking-agent:/apps# wget https://dl.halo.run/release/halo-1.4.17.jar
root@skywalking-agent:/apps# ll
total 78652
drwxr-xr-x 2 root root 28 Jan 11 09:12 ./
drwxr-xr-x 21 root root 316 Jan 11 09:10 ../
-rw-r--r-- 1 root root 80539453 Mar 18 2021 halo-1.4.7.jar

halo博客案例-启动app:

演示案例:

1
2
3
root@skywalking-agent:/data/skywalking-agent# pwd
/data/skywalking-agent
root@skywalking-agent:/data/skywalking-agent# java -javaagent:./skywalking-agent.jar -jar /apps/halo-1.4.7.jar

生产环境示例:

1
2
3
4
5
# java -javaagent:/skywalking-agent/skywalking-agent.jar \
-DSW_AGENT_NAMESPACE=xyz \
-DSW_AGENT_NAME=abc-application \
-Dskywalking.collector.backend_service=skywalking.abc.xyz.com:11800 \
-jar abc-xyz-1.0-SNAPSHOT.jar

image-20221017210627114

image-20221017210739392

halo博客案例-注册账号:

image-20221017211011994

halo博客案例-编写文章产生访问信息:

image-20221017211224584

halo博客案例-验证skywalking界面:

skywalking仪表盘:

image-20221017211443756

1
2
3
4
5
6
  Apdex全称是(Application Performance Index,应用性能指数),是由Apdex联盟开放的用于评估应用性能的标准,Apdex 联盟起源于2004年,Apdex标准从用户的角度出发,提供了一个统一的测量和报告用户体验的方法,将其量化为范围为0-1的满意度评价,把最终用户的体验和应用性能作为一个完整的指标进行统一度量.
 在网络中运行的任何一个应用(Web服务),它的响应时间决定了用户的满意程度,用户等待所有交互完成时间的长短直接影响了用户对应用的满意程度,这才是对用户有真正意义的“响应时间”,Apdex把完成这样一个任务所用的时间长短称为应用的“响应性”。
 Apdex 定义了应用响应时间的最优门槛为T,另外根据应用响应时间结合T定义了三种不同的性能表现: • Satisfied(满意)-应用响应时间小于或等于Apdex阈值,比如Apdex阈值为1s,则一个耗时0.6s或者1s的响应结果则可以认为是满意
的。
• Tolerating(可容忍)-应用响应时间大于Apdex阈值,但同时小于或等于4倍的Apdex阈值,假设应用设定的Apdex阈值为1s,则4*1=4s为应用响应时间的容忍上限。
• Frustrated(烦躁期)-应用响应时间大于4倍的Apdex阈值。

skywalking仪表盘:

1
2
3
4
 服务(Service)-表示对请求提供相同行为的一系列或一组工作负载(服务名称),在使用Agent或SDK的时候,可以自定义服务的名字, 如果不定义的话,SkyWalking将会使用你在平台(例如说 Istio)上定义的名字。
 服务实例(Instance)-上述的一组工作负载中的每一个工作负载称为一个实例(一个服务运行的节点),一个服务实例可以是一个kubernetes中的pod或者是一个虚拟机甚至是物理机 。
 端点(Endpoint) :对于特定服务所接收的请求路径, 如HTTP的URI路径和gRPC服务的类 +方法签名,如/api/v1/

halo博客案例-验证skywalking界面:

image-20221017213127080

halo博客案例-验证skywalking界面:

skywalking追踪图:

#可以根据traceid来查看某次请求的链路

image-20221017213308512

4.2.Tomcat运行Jenkins并实现链路追踪案例:

https://skywalking.apache.org/docs/skywalking-java/latest/en/setup/service-agent/java-agent/readme/

部署jdk环境: 参考halo示例

部署skywalking java客户端:参考halo示例

tomcat运行Jenkins -部署tomcat:

下载并部署tomcat,https://tomcat.apache.org/

1
2
3
4
5
root@skywalking-agent:/apps# pwd
/apps
root@skywalking-agent:/apps# ls apache-tomcat-8.5.73.tar.gz
apache-tomcat-8.5.73.tar.gz
root@skywalking-agent:/apps# tar xvf apache-tomcat-8.5.73.tar.gz

tomcat运行Jenkins -配置tomcat中的javaagent参数:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
root@skywalking-agent:/apps# pwd
/apps
root@skywalking-agent:/apps# vim /apps/apache-tomcat-8.5.73/bin/catalina.sh
# ----------------------------------------------------------------------------- CATALINA_OPTS="$CATALINA_OPTS -javaagent:/apps/skywalking-agent/skywalking-agent.jar"; exportCATALINA_OPTS

配置service参数:
root@skywalking-agent:~# vim /apps/skywalking-agent/config/agent.config
agent.namespace=${SW_AGENT_NAMESPACE:jenkins}
agent.service_name=${SW_AGENT_NAME:jenkins}
collector.backend_service=${SW_AGENT_COLLECTOR_BACKEND_SERVICES:192.168.3.81:11800}

#tomcat运行Jenkins –app部署及启动
上传Jenkins app:
root@skywalking-agent:/apps# ls /apps/apache-tomcat-8.5.73/webapps/
ROOT docs examples host-manager jenkins.war manager

#启动tomcat:
root@skywalking-agent:/apps/skywalking-agent# pwd
/apps/skywalking-agent
root@skywalking-agent:/apps/skywalking-agent# /apps/apache-tomcat-8.5.73/bin/catalina.sh run

tomcat运行Jenkins-skywalking web界面:

image-20221017223710491

tomcat运行Jenkins-证skywalking web界面:
Service:

image-20221017223800181

tomcat运行Jenkins-证skywalking web界面:

instance:

image-20221017223912283

tomcat运行Jenkins-证skywalking web界面:

Endpoint:

image-20221017224043902

拓扑图

image-20221017224121224

• 4.3.微服务链路追踪案例:

java微服务示例-部署注册中心:

zookeeper注册中心部署:
node: 192.168.3.42
目录:/apps/apache-zookeeper-3.6.3-bin

1.java环境:
root@skywalking-agent:~# java -version
java version “1.8.0_251”
Java(TM) SE Runtime Environment (build 1.8.0_251-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.251-b08, mixed mode)
2:skywalking-agent
/data/skywalking-agent/config/agent.config
18 agent.namespace=${SW_AGENT_NAMESPACE:app}
21 agent.service_name=${SW_AGENT_NAME:dubbo-provider}
93 collector.backend_service=${SW_AGENT_COLLECTOR_BACKEND_SERVICES:192.168.3.81:11800}

3.provider连接zookeeper配置:
/apps/dubbo-demo-provider-2.1.5 #目录
dubbo.registry.address=zookeeper://192.168.3.42:2181 #指定注册中心地址
4.启动provider:
root@skywalking-agent:/apps/skywalking-agent# pwd
/apps/skywalking-agent

1
java -javaagent:/apps/skywalking-agent/skywalking-agent.jar  -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -server -Xms1024m -Xmx1024m -XX:PermSize=128m -XX:SurvivorRatio=2 -XX:+UseParallelGC -classpath /apps/dubbo-demo-provider-2.1.5/conf:/apps/dubbo-demo-provider-2.1.5/lib/cache-api-0.4.jar:/apps/dubbo-demo-provider-2.1.5/lib/commons-codec-1.4.jar:/apps/dubbo-demo-provider-2.1.5/lib/commons-logging-1.1.1.jar:/apps/dubbo-demo-provider-2.1.5/lib/commons-pool-1.5.5.jar:/apps/dubbo-demo-provider-2.1.5/lib/dubbo-2.1.5.jar:/apps/dubbo-demo-provider-2.1.5/lib/dubbo-demo-2.1.5.jar:/apps/dubbo-demo-provider-2.1.5/lib/dubbo-demo-provider-2.1.5.jar:/apps/dubbo-demo-provider-2.1.5/lib/fastjson-1.1.8.jar:/apps/dubbo-demo-provider-2.1.5/lib/gmbal-api-only-3.0.0-b023.jar:/apps/dubbo-demo-provider-2.1.5/lib/grizzly-core-2.1.4.jar:/apps/dubbo-demo-provider-2.1.5/lib/grizzly-framework-2.1.4.jar:/apps/dubbo-demo-provider-2.1.5/lib/grizzly-portunif-2.1.4.jar:/apps/dubbo-demo-provider-2.1.5/lib/grizzly-rcm-2.1.4.jar:/apps/dubbo-demo-provider-2.1.5/lib/hessian-4.0.7.jar:/apps/dubbo-demo-provider-2.1.5/lib/hibernate-validator-4.2.0.Final.jar:/apps/dubbo-demo-provider-2.1.5/lib/httpclient-4.1.2.jar:/apps/dubbo-demo-provider-2.1.5/lib/httpcore-4.1.2.jar:/apps/dubbo-demo-provider-2.1.5/lib/javassist-3.15.0-GA.jar:/apps/dubbo-demo-provider-2.1.5/lib/jedis-2.0.0.jar:/apps/dubbo-demo-provider-2.1.5/lib/jetty-6.1.26.jar:/apps/dubbo-demo-provider-2.1.5/lib/jetty-util-6.1.26.jar:/apps/dubbo-demo-provider-2.1.5/lib/jline-0.9.94.jar:/apps/dubbo-demo-provider-2.1.5/lib/log4j-1.2.16.jar:/apps/dubbo-demo-provider-2.1.5/lib/management-api-3.0.0-b012.jar:/apps/dubbo-demo-provider-2.1.5/lib/mina-core-1.1.7.jar:/apps/dubbo-demo-provider-2.1.5/lib/netty-3.2.5.Final.jar:/apps/dubbo-demo-provider-2.1.5/lib/servlet-api-2.5-20081211.jar:/apps/dubbo-demo-provider-2.1.5/lib/slf4j-api-1.6.2.jar:/apps/dubbo-demo-provider-2.1.5/lib/spring-2.5.6.SEC03.jar:/apps/dubbo-demo-provider-2.1.5/lib/validation-api-1.0.0.GA.jar:/apps/dubbo-demo-provider-2.1.5/lib/zookeeper-3.3.3.jar: com.alibaba.dubbo.container.Main

java微服务示例-consumer部署:

1.java环境:
root@skywalking-agent:~# java -version
java version “1.8.0_251”
Java(TM) SE Runtime Environment (build 1.8.0_251-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.251-b08, mixed mode)
2:skywalking-agent
/apps/skywalking-agent/config/agent.config
18 agent.namespace=${SW_AGENT_NAMESPACE:app}
21 agent.service_name=${SW_AGENT_NAME:dubbo-consumer}
93 collector.backend_service=${SW_AGENT_COLLECTOR_BACKEND_SERVICES:192.168.3.81:11800}

java微服务示例-consumer部署:
3.provider连接zookeeper配置: /apps/dubbo-demo-consumer-2.1.5
dubbo.registry.address=zookeeper://192.168.3.43:2181

4.启动consumer

1
root@skywalking-agent2:~# java -javaagent:/data/skywalking-agent/skywalking-agent.jar -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -server -Xmx2g -Xms2g - Xmn256m -XX:PermSize=128m -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection - XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 -classpath /apps/dubbo-demo- consumer-2.1.5/conf:/apps/dubbo-demo-consumer-2.1.5/lib/cache-api-0.4.jar:/apps/dubbo-demo-consumer-2.1.5/lib/commons-codec-1.4.jar:/apps/dubbo-demo-consumer- 2.1.5/lib/commons-logging-1.1.1.jar:/apps/dubbo-demo-consumer-2.1.5/lib/commons-pool-1.5.5.jar:/apps/dubbo-demo-consumer-2.1.5/lib/dubbo-2.1.5.jar:/apps/dubbo-demo- consumer-2.1.5/lib/dubbo-demo-2.1.5.jar:/apps/dubbo-demo-consumer-2.1.5/lib/dubbo-demo-consumer-2.1.5.jar:/apps/dubbo-demo-consumer-2.1.5/lib/fastjson- 1.1.8.jar:/apps/dubbo-demo-consumer-2.1.5/lib/gmbal-api-only-3.0.0-b023.jar:/apps/dubbo-demo-consumer-2.1.5/lib/grizzly-core-2.1.4.jar:/apps/dubbo-demo-consumer- 2.1.5/lib/grizzly-framework-2.1.4.jar:/apps/dubbo-demo-consumer-2.1.5/lib/grizzly-portunif-2.1.4.jar:/apps/dubbo-demo-consumer-2.1.5/lib/grizzly-rcm-2.1.4.jar:/apps/dubbo-demo- consumer-2.1.5/lib/hessian-4.0.7.jar:/apps/dubbo-demo-consumer-2.1.5/lib/hibernate-validator-4.2.0.Final.jar:/apps/dubbo-demo-consumer-2.1.5/lib/httpclient-4.1.2.jar:/apps/dubbo- demo-consumer-2.1.5/lib/httpcore-4.1.2.jar:/apps/dubbo-demo-consumer-2.1.5/lib/javassist-3.15.0-GA.jar:/apps/dubbo-demo-consumer-2.1.5/lib/jedis-2.0.0.jar:/apps/dubbo-demo- consumer-2.1.5/lib/jetty-6.1.26.jar:/apps/dubbo-demo-consumer-2.1.5/lib/jetty-util-6.1.26.jar:/apps/dubbo-demo-consumer-2.1.5/lib/jline-0.9.94.jar:/apps/dubbo-demo-consumer- 2.1.5/lib/log4j-1.2.16.jar:/apps/dubbo-demo-consumer-2.1.5/lib/management-api-3.0.0-b012.jar:/apps/dubbo-demo-consumer-2.1.5/lib/mina-core-1.1.7.jar:/apps/dubbo-demo- consumer-2.1.5/lib/netty-3.2.5.Final.jar:/apps/dubbo-demo-consumer-2.1.5/lib/servlet-api-2.5-20081211.jar:/apps/dubbo-demo-consumer-2.1.5/lib/slf4j-api-1.6.2.jar:/apps/dubbo- demo-consumer-2.1.5/lib/spring-2.5.6.SEC03.jar:/apps/dubbo-demo-consumer-2.1.5/lib/validation-api-1.0.0.GA.jar:/apps/dubbo-demo-consumer-2.1.5/lib/zookeeper-3.3.3.jar: com.alibaba.dubbo.container.Main

java微服务示例-dubbo provider请求验证:

java微服务示例-skywalking web验证:

• 4.4.Python服务链路追踪案例-手动注册:

python应用示例-手动注册:

https://skywalking.apache.org/docs/skywalking-python/v0.7.0/en/setup/installation/

image-20221019170719168

1
2
3
4
5
6
root@ubuntu:~/skywalking-agent# apt install python3-pip
root@ubuntu:~/skywalking-agent# pip3 install "apache-skywalking"
>>> from skywalking import agent, config
>>> config.init(collector_address='192.168.3.81:11800', service_name='python-app')
>>> agent.start()
#这一步主要是安装agent并且启动skywalking agent

python应用示例-验证服务:

image-20221019181130835

4.5.Python服务链路追踪案例-自动注册:

python 应用-自动注册并实现链路追踪:

https://github.com/apache/skywalking-python

python 应用案例-准备django运行环境:

1
2
3
4
5
6
7
8
9
10
11
root@skywalking-agent:/apps# pwd
/apps
root@skywalking-agent:/apps# ll django-test.tgz
-rw-r--r-- 1 root root 18388321 Jan 11 15:09 django-test.tgz
root@skywalking-agent:/apps# tar xvf django-test.tgz
root@skywalking-agent:/apps# cd django-test/
root@skywalking-agent:/apps/django-test# ls
bin include lib pyvenv.cfg requirements.txt
安装依赖模块:
# apt install python3-pip
# pip3 install -r requirements.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
创建django项目mysite
# django-admin startproject mysite
创建应用
# cd mysite
# python3 manage.py startapp myapp
初始化数据库
# python3 manage.py makemigrations
# python3 manage.py migrate
创建管理员,用于登录admin
# python3 manage.py createsuperuser
Username (leave blank to use 'root'): root
Email address: 1391253474@qq.com
Password: Password (again): Superuser created successfully.

python 应用案例-环境变量及app配置:

1
2
3
4
5
6
7
8
9
skywarking环境变量: 
root@skywalking-agent:/apps/django-test/mysite# pwd
/apps/django-test/mysite
export SW_AGENT_NAME='python-app1'
export SW_AGENT_NAMESPACE='python-app1'
export SW_AGENT_COLLECTOR_BACKEND_SERVICES='192.168.3.81:11800'
修改配置:
# vim mysite/settings.py
ALLOWED_HOSTS = ['127.0.0.1','192.168.3.82']

python 应用案例-启动项目:

1
2
3
启动app服务
# sw-python -d run python3 manage.py runserver 192.168.3.82:80
访问:http://192.168.3.82:80/admin/

python 应用案例-验证django web页面:

image-20221019193144440

python 应用案例-验证skywalking web界面:

image-20221019193506491

python 应用案例-验证elasticsearch索引数据:

image-20221019193713501

五.skywalking 告警:

https://github.com/apache/skywalking/blob/master/docs/en/setup/backend/backend-alarm.md

skywalking 告警-指标:

1
2
3
4
5
6
7
8
9
10
11
# cat config/oal/core.oal
service_resp_time #服务的响应时间
service_sla #服务的http请求成功率SLA,比如99%等。
service_cpm #表示每分钟的调用次数/访问次数.
service_apdex : 应用性能指数是0.8是0.x
service_percentile: 指定最近多少数据范围内的响应时间百分比,即p99, p95, p90, p75, p50在内的数据统计结果
endpoint_relation_cpm #端点的调用次数/访问次数
endpoint_relation_resp_time #端点的响应时间
endpoint_relation_sla #端点的http请求成功率SLA,比如99%等。
endpoint_relation_percentile ##端点的最近多少数据范围内的响应时间百分比,即p99、p95、p90、p75、p50
在内的数据统计结果

skywalking 告警-指标:

更多指标和规则:
https://github.com/apache/skywalking/blob/master/docs/en/setup/backend/backendalarm.md#list-of-all-potential-metrics-name

skywalking 告警:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# vim alarm-settings.yml
rules: #定义rule规则
service_cpm_rule: #唯一的规则名称,必须以_rule结尾
# Metrics value need to be long, double or int
metrics-name: service_cpm #指标名称
op: ">" #操作符,>, >=, <, <=, ==
threshold: 1 #指标阈值
# The length of time to evaluate the metrics
period: 2 #评估指标的间隔周期
# How many times after the metrics match the condition, will trigger alarm
count: 1 #匹配成功多少次就会触发告警
# How many times of checks, the alarm keeps silence after alarm triggered, default as same as period. #silence-period: 3
silence-period: 2 #触发告警后的静默时间
message: dubbo-provider service_cpm 大于1了 #告警信息
1
2
3
4
5
6
7
8
dingtalkHooks:
textTemplate: |-
{
"msgtype": "text", "text": {
"content": "Apache SkyWalking Alarm: \n %s."
}
}
webhooks: - url: https://oapi.dingtalk.com/robot/send?access_token=b317849c09c2c1dcb5b426c343f696fdadb5aaf087b39144721ebdfcaee8cc83

skywalking 告警-验证:

image-20221019210834642


Author: 西伯利亚狼
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint policy. If reproduced, please indicate source 西伯利亚狼 !
  TOC