极客时间运维进阶训练营第八周作业
作者:9527
- 2022-12-16 加拿大
本文字数:4330 字
阅读完需:约 14 分钟
Mandatory Assignment
基于 docker-compose 或二进制部署 SkyWalking
实现单体服务 Halo 博客和 Jenkins 的请求链路跟踪
实现 Dubbo 微服务实现链路跟踪案例
实现 skywalking 的钉钉告警
Dapper
What is tracing
Dapper
Dapper design
Dapper span
How Dapper works
Dapper data collection
Current situation
Dapper cost
SkyWalking
What is APM
APM tools
Opentracing
What is SkyWalking
SkyWalking components
Install with docker-compose
Preparation
$ mkdir -pv /data/elasticsearch
mkdir: created directory ‘/data’
mkdir: created directory ‘/data/elasticsearch’
$ chown 1000.1000 -R /data/elasticsearch
$ mkdir /data/skywalking-9.3-docker-composefile -pv
mkdir: created directory ‘/data/skywalking-9.3-docker-composefile’
复制代码
Docker compose file
version: '3.8'
services:
elasticsearch:
image: elasticsearch:8.4.2
container_name: elasticsearch
ports:
- "9200:9200"
healthcheck:
test: [ "CMD-SHELL", "curl --silent --fail localhost:9200/_cluster/health || exit 1" ]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
environment:
discovery.type: single-node
ingest.geoip.downloader.enabled: "false"
bootstrap.memory_lock: "true"
ES_JAVA_OPTS: "-Xms512m -Xmx512m"
xpack.security.enabled: "false"
ulimits:
memlock:
soft: -1
hard: -1
oap:
image: apache/skywalking-oap-server:9.3.0
container_name: oap
depends_on:
elasticsearch:
condition: service_healthy
links:
- elasticsearch
ports:
- "11800:11800"
- "12800:12800"
healthcheck:
test: [ "CMD-SHELL", "/skywalking/bin/swctl ch" ]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
environment:
SW_STORAGE: elasticsearch
SW_STORAGE_ES_CLUSTER_NODES: elasticsearch:9200
SW_HEALTH_CHECKER: default
SW_TELEMETRY: prometheus
JAVA_OPTS: "-Xms2048m -Xmx2048m"
ui:
image: apache/skywalking-ui:9.3.0
container_name: ui
depends_on:
oap:
condition: service_healthy
links:
- oap
ports:
- "8080:8080"
environment:
SW_OAP_ADDRESS: http://oap:12800
healthcheck:
test: ["CMD-SHELL", "curl -sf http://localhost:8080 || exit 1" ]
interval: 60s
timeout: 10s
retries: 3
start_period: 60s
复制代码
Install
$ # docker-compose up -d
[+] Running 28/28
⠿ ui Pulled 35.3s
⠿ e96e057aae67 Pull complete 15.0s
⠿ 4ced2591451d Pull complete 18.8s
⠿ df8f874ae8c0 Pull complete 23.2s
⠿ 111b6c748642 Pull complete
...
[+] Running 4/4
⠿ Network skywalking_default Created 0.1s
⠿ Container elasticsearch Healthy 39.8s
⠿ Container oap Healthy 63.7s
⠿ Container ui Started
复制代码
Verify
$ CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
53c091003cf8 apache/skywalking-ui:9.3.0 "bash docker-entrypo…" 2 minutes ago Up About a minute (healthy) 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp ui
484c1157c4ef apache/skywalking-oap-server:9.3.0 "bash docker-entrypo…" 2 minutes ago Up 2 minutes (healthy) 0.0.0.0:11800->11800/tcp, :::11800->11800/tcp, 1234/tcp, 0.0.0.0:12800->12800/tcp, :::12800->12800/tcp oap
871ff4a14426 elasticsearch:8.4.2 "/bin/tini -- /usr/l…" 2 minutes ago Up 2 minutes (healthy) 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 9300/tcp elasticsearch
复制代码
Access UI:
SkyWalking Use Case Demo
Python
Install pacakages:
# Install the latest version, using the default gRPC protocol to report data to OAP
$ pip install "apache-skywalking"
# Install the latest version, using the http protocol to report data to OAP
$ pip install "apache-skywalking[http]"
复制代码
Setup Python agent
from skywalking import agent, config
config.init(collector='127.0.0.1:11800', service='your awesome service')
agent.start()
复制代码
Create spans
from skywalking import Component
from skywalking.trace.context import SpanContext, get_context
from skywalking.trace.tags import Tag
context: SpanContext = get_context() # get a tracing context
# create an entry span, by using `with` statement,
# the span automatically starts/stops when entering/exiting the context
with context.new_entry_span(op='https://github.com/apache') as span:
span.component = Component.Flask
# the span automatically stops when exiting the `with` context
with context.new_exit_span(op='https://github.com/apache', peer='localhost:8080') as span:
span.component = Component.Flask
with context.new_local_span(op='https://github.com/apache') as span:
span.tag(Tag(key='Singer', val='Nakajima'))
复制代码
Decorators
from time import sleep
from skywalking import Component
from skywalking.decorators import trace, runnable
from skywalking.trace.context import SpanContext, get_context
from skywalking.trace.ipc.process import SwProcess
@trace() # the operation name is the method name('some_other_method') by default
def some_other_method():
sleep(1)
@trace(op='awesome') # customize the operation name to 'awesome'
def some_method():
some_other_method()
@trace(op='async_functions_are_also_supported')
async def async_func():
return 'asynchronous'
@trace()
async def async_func2():
return await async_func()
@runnable() # cross thread propagation
def some_method():
some_other_method()
from threading import Thread
t = Thread(target=some_method)
t.start()
# When another process is started, agents will also be started in other processes,
# supporting only the process mode of spawn.
p1 = SwProcess(target=some_method)
p1.start()
p1.join()
context: SpanContext = get_context()
with context.new_entry_span(op=str('https://github.com/apache/skywalking')) as span:
span.component = Component.Flask
some_method()
复制代码
Dubbo
Use case
Check Java version
$ java --version
openjdk 11.0.16 2022-07-19 LTS
OpenJDK Runtime Environment (Red_Hat-11.0.16.0.8-1.amzn2.0.1) (build 11.0.16+8-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-11.0.16.0.8-1.amzn2.0.1) (build 11.0.16+8-LTS, mixed mode, sharing)
复制代码
Install Zookeeper
$ mkdir /apps && cd /apps
$ wget https://dlcdn.apache.org/zookeeper/zookeeper-3.7.1/apache-zookeeper-3.7.1-bin.tar.gz
--2022-12-15 21:13:10-- https://dlcdn.apache.org/zookeeper/zookeeper-3.7.1/apache-zookeeper-3.7.1-bin.tar.gz
Resolving dlcdn.apache.org (dlcdn.apache.org)... 151.101.2.132, 2a04:4e42::644
Connecting to dlcdn.apache.org (dlcdn.apache.org)|151.101.2.132|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 12649765 (12M) [application/x-gzip]
Saving to: ‘apache-zookeeper-3.7.1-bin.tar.gz’
100%[=========================================================================================================================================>] 12,649,765 70.8MB/s in 0.2s
2022-12-15 21:13:10 (70.8 MB/s) - ‘apache-zookeeper-3.7.1-bin.tar.gz’ saved [12649765/12649765]
$ tar xzvf apache-zookeeper-3.7.1-bin.tar.gz
$ cp /apps/apache-zookeeper-3.7.1-bin/conf/zoo_sample.cfg /apps/apache-zookeeper-3.7.1-bin/conf/zoo.cfg
$ ll /apps/apache-zookeeper-3.7.1-bin/conf/zoo.cfg
-rw-r--r-- 1 root root 1148 Dec 15 21:14 /apps/apache-zookeeper-3.7.1-bin/conf/zoo.cfg
$ /apps/apache-zookeeper-3.7.1-bin/bin/zkServer.sh start
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /apps/apache-zookeeper-3.7.1-bin/bin/../conf/zoo.cfg
$ ss -tlnp | grep 2181
LISTEN 0 50 *:2181 *:* users:(("java",pid=6350,fd=53))
复制代码
划线
评论
复制
发布于: 刚刚阅读数: 4
版权声明: 本文为 InfoQ 作者【9527】的原创文章。
原文链接:【http://xie.infoq.cn/article/7aaff611ede7194807162ecba】。文章转载请联系作者。
9527
关注
还未添加个人签名 2020-04-22 加入
还未添加个人简介
评论