本文主要是介绍opentelemetry实践,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
场景描述
根据 open-telemetry 提供的exampleshttps://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/examples/demo
假设我们有两个服务,一个是demo-server,一个是demo-client,demo-client会周期性调用demo-server,我们希望可以采集到demo-server与demo-client之间的监控数据,包括请求延迟和请求数统计(demo里面也提供了如何把数据接入到分布式调用链系统上,比如jaegre)
服务架构图
基于opentelemetry我们实现的架构图大概如下
如果是我们直接使用Promutheus的话,可能是如下的架构图
如果我们想Demo-Server和Demo-Client使用推数据的方式的话,可以使用PushGateway,如下
这里补充下,那这样的话,使用Opentelemetry的好处式啥呢?其实就是标准化了,比如我们现在想接入jaegre来做分布式调用链分析,如果有Opentelemetry的话,我们也是一样Demo-Server和Demo-Client直接上报给Opentelemetry Collector就可以了,也不用引入新的SDK;没有opentelemetry的话,我们就需要俩套SDK,而且也没有一个标准化
Docker 部署
Opentelemetry项目提供了一个docker-compose的启动方案,具体可以参考:https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/examples/demo
部署之后,我们可以通过访问promutheus,看到相应的数据收集
k8s 部署
基于官网提供的dmeo (https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/examples/demo),适配到k8s。
代码地址:https://github.com/khalid-jobs/khalid.project/tree/main/opentelemetry-k8s
为了方便,下面的服务暴露都使用nodePort进行暴露
1. 在k8s上搭建promutheus + grafna
cd promutheus_grafna
# 部署promutheus
kubectl apply -f prometheus-sa.yaml
kubectl apply -f prometheus-cm.yaml
kubectl apply -f prometheus-deployment.yaml
kubectl apply -f prometheus-service.yaml
# 部署grafna
kubectl apply -f grafna.yaml
kubectl apply -f grafna-service.yaml
2. 在k8s 部署collector
kubectl apply -f otel-collector/deploy.yaml
3. 部署demo-server 和 demo-client
# 部署demo-server
cd server
make image
kubectl apply -f deploy.yaml # 注意配置好节点和镜像地址
# 部署demo-client也是类似
4. promutheus收集collector
参考
1. Opentelemetry Collector的配置和使用 - charlieroro - 博客园 定义的推送
2. 例子说明:https://www.cnblogs.com/charlieroro/p/13883602.html (collector 包含了exporter之类的)
3. Getting Started | OpenTelemetry
4. promutheus+grafana
- 部署 Prometheus 和 Grafana 到 k8s - WeihanLi - 博客园
- K8s 部署 Prometheus + Grafana - LB477 - 博客园
- How To Setup Prometheus Monitoring On Kubernetes Cluster [Tutorial]
这篇关于opentelemetry实践的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!