使用opentelemetry 可观测监控springboot应用的指标、链路实践,使用zipkin展示链路追踪数据,使用grafana展示指标

1.安装docker,docker-compose

(1)安装依赖包
yum install -y yum-utils device-mapper-persistent-data lvm22.2、部署dockertar  xvf docker-20.10.19.tgz
cp docker/* /usr/bin/vim /usr/lib/systemd/system/docker.service[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.targetsystemctl enable docker
systemctl restart docker vim /etc/docker/daemon.json{"data-root": "/data/docker/ucsp-data/docker "
}
```mkdir -p /data/docker/ucsp-data/docker
cp -r /var/lib/docker/*  /data/docker/ucsp-data/dockersystemctl daemon-reload
systemctl restart docker
docker   version
[root@localhost ~]# docker   version
Client:Version:           20.10.19API version:       1.41Go version:        go1.18.7Git commit:        d85ef84Built:             Thu Oct 13 16:43:07 2022OS/Arch:           linux/amd64Context:           defaultExperimental:      trueServer: Docker Engine - CommunityEngine:Version:          20.10.19API version:      1.41 (minimum version 1.12)Go version:       go1.18.7Git commit:       c964641Built:            Thu Oct 13 16:48:41 2022OS/Arch:          linux/amd64Experimental:     falsecontainerd:Version:          v1.6.8GitCommit:        9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6runc:Version:          1.1.4GitCommit:        v1.1.4-0-g5fd4c4d1docker-init:Version:          0.19.0GitCommit:        de40ad0
[root@localhost ~]#

安装docker-compose

##安装docker-compose
cp ./docker-compose-linux-x86_64 /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

配置docker国内镜像源

##配置DockerHub 国内镜像源
vim /etc/docker/daemon.json 添加如下:
"registry-mirrors": ["https://docker.1ms.run","https://docker.xuanyuan.me"]##查看配置
[root@localhost ~]# cat /etc/docker/daemon.json
{"data-root": "/data/docker/ucsp-data/docker","registry-mirrors": ["https://docker.1ms.run","https://docker.xuanyuan.me"]
}
[root@localhost ~]###重启
systemctl daemon-reload
systemctl restart docker

修改docker-compose.yaml

[root@localhost OpenTelemetry]# cat docker-compose.yml 
version: '3.8'services:# OpenTelemetry Collector (数据收集和转发)otel-collector:image: otel/opentelemetry-collector:latestcontainer_name: otel-collectorcommand: ["--config=/etc/otel-config.yaml"]volumes:- ./otel-config.yaml:/etc/otel-config.yamlports:- "4317:4317"  # OTLP gRPC- "4318:4318"  # OTLP http- "8889:8889"  # Promentheus exporter metricsdepends_on:- prometheus# Prometheus (指标存储)prometheus:image: prom/prometheus:latestvolumes:- ./prometheus.yml:/etc/prometheus/prometheus.yml- ./alertmanager.yml:/etc/alertmanager/alertmanager.ymlports:- "9090:9090"command:- "--config.file=/etc/prometheus/prometheus.yml"- "--web.external-url=http://localhost:9090"depends_on:- alertmanager# Alertmanager (告警管理)alertmanager:image: prom/alertmanager:latestvolumes:- ./alertmanager.yml:/etc/alertmanager/alertmanager.ymlports:- "9093:9093"command:- "--config.file=/etc/alertmanager/alertmanager.yml"# Grafana (可视化)grafana:image: grafana/grafana:latestvolumes:- grafana-storage:/var/lib/grafanaenvironment:- GF_SECURITY_ADMIN_PASSWORD=adminports:- "3000:3000"depends_on:- prometheuszipkin:image: openzipkin/zipkin:latestcontainer_name: zipkinports:- "9411:9411"deploy:resources:limits:memory: 2Genvironment:JAVA_OPTS: "-Xmx1g -Xms1g -XX:+UseG1GC -XX:+HeapDumpOnOutOfMemoryError"redis:image: "redis:6.2"container_name: redishostname: redisrestart: alwaysenvironment:TZ: Asia/Shanghaiports:- "6379:6379"victoriametrics:image: victoriametrics/victoria-metrics:v1.79.12container_name: victoriametricshostname: victoriametricsrestart: alwaysenvironment:TZ: Asia/Shanghaiports:- "8428:8428"command:- "--loggerTimezone=Asia/Shanghai"nightingale:image: flashcatcloud/nightingale:latestcontainer_name: nightingalehostname: nightingalerestart: alwaysenvironment:GIN_MODE: releaseTZ: Asia/ShanghaiWAIT_HOSTS: redis:6379volumes:- ./etc-nightingale:/app/etcports:- "17000:17000"- "20090:20090"depends_on:- redis- victoriametricscommand: >sh -c "/app/n9e"categraf:image: "flashcatcloud/categraf:latest"container_name: "categraf"hostname: "categraf01"restart: alwaysenvironment:TZ: Asia/ShanghaiHOST_PROC: /hostfs/procHOST_SYS: /hostfs/sysHOST_MOUNT_PREFIX: /hostfsWAIT_HOSTS: nightingale:17000, nightingale:20090volumes:- ./etc-categraf:/etc/categraf/conf- /:/hostfsdepends_on:- nightingalevolumes:grafana-storage:

修改otel-config.yaml

[root@localhost OpenTelemetry]# cat otel-config.yaml 
receivers:otlp:protocols:grpc:endpoint: '0.0.0.0:4317'http:endpoint: '0.0.0.0:4318'
processors:batch:exporters:# NOTE: Prior to v0.86.0 use `logging` instead of `debug`.prometheus:endpoint: "0.0.0.0:8889"debug:verbosity: detailedzipkin:endpoint: "http://0.0.0.0:9411/api/v2/spans"service:pipelines:traces:receivers: [otlp]processors: []exporters: [zipkin]metrics:receivers: [otlp]processors: []exporters: [prometheus]logs:receivers: [otlp]exporters: [debug]

修改prometheus.yml

[root@localhost OpenTelemetry]# cat prometheus.yml 
global:scrape_interval: 15sevaluation_interval: 15srule_files:- '/etc/prometheus/alert.rules.yml'alerting:alertmanagers:- static_configs:- targets: ['alertmanager:9093']scrape_configs:- job_name: 'otel-collector'metrics_path: '/metrics'scrape_interval: 5sstatic_configs:- targets: ['otel-collector:8889']- job_name: 'prometheus'static_configs:- targets: ['prometheus:9090']- job_name: 'alertmanager'static_configs:- targets: ['alertmanager:9093']

修改alertmanager.yml

[root@localhost OpenTelemetry]# cat alertmanager.yml 
route:group_by: ['alertname']receiver: 'email-notifications'receivers:
- name: 'email-notifications'email_configs:- to: 'your-email@example.com'from: 'alertmanager@example.com'smarthost: 'smtp.example.com:587'auth_username: 'your-email@example.com'auth_password: 'your-password'send_resolved: true

修改alert.rules.yml

[root@localhost OpenTelemetry]# cat alert.rules.yml 
groups:
- name: examplerules:- alert: HighRequestLatencyexpr: histogram_quantile(0.95, sum(rate(http_server_duration_seconds_bucket[5m])) by (le) > 1for: 10mlabels:severity: criticalannotations:summary: "High request latency on {{ $labels.instance }}"description: "Request latency is {{ $value }} seconds"

修改./etc-nightingale/config.toml

[root@localhost OpenTelemetry]# cat ./etc-nightingale/config.toml 
[Global]
RunMode = "release"[Log]
# log write dir
Dir = "logs"
# log level: DEBUG INFO WARNING ERROR
Level = "INFO"
# stdout, stderr, file
Output = "stdout"
# # rotate by time
# KeepHours = 4
# # rotate by size
# RotateNum = 3
# # unit: MB
# RotateSize = 256[HTTP]
# http listening address
Host = "0.0.0.0"
# http listening port
Port = 17000
# https cert file path
CertFile = ""
# https key file path
KeyFile = ""
# whether print access log
PrintAccessLog = false
# whether enable pprof
PProf = false
# expose prometheus /metrics?
ExposeMetrics = true
# http graceful shutdown timeout, unit: s
ShutdownTimeout = 30
# max content length: 64M
MaxContentLength = 67108864
# http server read timeout, unit: s
ReadTimeout = 20
# http server write timeout, unit: s
WriteTimeout = 40
# http server idle timeout, unit: s
IdleTimeout = 120[HTTP.ShowCaptcha]
Enable = false [HTTP.APIForAgent]
Enable = true 
# [HTTP.APIForAgent.BasicAuth]
# user001 = "ccc26da7b9aba533cbb263a36c07dcc5"[HTTP.APIForService]
Enable = false
[HTTP.APIForService.BasicAuth]
user001 = "ccc26da7b9aba533cbb263a36c07dcc5"[HTTP.JWTAuth]
# unit: min
AccessExpired = 1500
# unit: min
RefreshExpired = 10080
RedisKeyPrefix = "/jwt/"[HTTP.TokenAuth]
Enable = false
HeaderUserTokenKey = "X-User-Token"[HTTP.ProxyAuth]
# if proxy auth enabled, jwt auth is disabled
Enable = false
# username key in http proxy header
HeaderUserNameKey = "X-User-Name"
DefaultRoles = ["Standard"][HTTP.RSA]
# open RSA
OpenRSA = false[DB]
# postgres: DSN="host=127.0.0.1 port=5432 user=root dbname=n9e_v6 password=1234 sslmode=disable"
DSN="nightingale:Nightingale_324@tcp(10.12.12.80:3306)/n9e_v6?charset=utf8mb4&parseTime=True&loc=Local&allowNativePasswords=true"
# enable debug mode or not
Debug = false
# mysql postgres
DBType = "mysql"
# unit: s
MaxLifetime = 7200
# max open connections
MaxOpenConns = 150
# max idle connections
MaxIdleConns = 50
# enable auto migrate or not
# EnableAutoMigrate = false[Redis]
# address, ip:port or ip1:port,ip2:port for cluster and sentinel(SentinelAddrs)
Address = "redis:6379"
# Username = ""
# Password = ""
# DB = 0
# UseTLS = false
# TLSMinVersion = "1.2"
# standalone cluster sentinel
RedisType = "standalone"
# Mastername for sentinel type
# MasterName = "mymaster"
# SentinelUsername = ""
# SentinelPassword = ""[Alert]
[Alert.Heartbeat]
# auto detect if blank
IP = ""
# unit ms
Interval = 1000
EngineName = "default"# [Alert.Alerting]
# NotifyConcurrency = 10[Center]
MetricsYamlFile = "./etc/metrics.yaml"
I18NHeaderKey = "X-Language"[Center.AnonymousAccess]
PromQuerier = false
AlertDetail = false[Pushgw]
# use target labels in database instead of in series
LabelRewrite = true
ForceUseServerTS = true# [Pushgw.DebugSample]
# ident = "xx"
# __name__ = "xx"# [Pushgw.WriterOpt]
# QueueMaxSize = 1000000
# QueuePopSize = 1000[[Pushgw.Writers]] 
# Url = "http://127.0.0.1:8480/insert/0/prometheus/api/v1/write"
Url = "http://victoriametrics:8428/api/v1/write"
# Basic auth username
BasicAuthUser = ""
# Basic auth password
BasicAuthPass = ""
# timeout settings, unit: ms
Headers = ["X-From", "n9e"]
Timeout = 10000
DialTimeout = 3000
TLSHandshakeTimeout = 30000
ExpectContinueTimeout = 1000
IdleConnTimeout = 90000
# time duration, unit: ms
KeepAlive = 30000
MaxConnsPerHost = 0
MaxIdleConns = 100
MaxIdleConnsPerHost = 100
## Optional TLS Config
# UseTLS = false
# TLSCA = "/etc/n9e/ca.pem"
# TLSCert = "/etc/n9e/cert.pem"
# TLSKey = "/etc/n9e/key.pem"
# InsecureSkipVerify = false
# [[Writers.WriteRelabels]]
# Action = "replace"
# SourceLabels = ["__address__"]
# Regex = "([^:]+)(?::\\d+)?"
# Replacement = "$1:80"
# TargetLabel = "__address__"[Ibex]
Enable = true
RPCListen = "0.0.0.0:20090"

springboot 应用启动参数添加

nohup java -server -Xms256m -Xmx512m -javaagent:/路径/opentelemetry-javaagent.jar \
-Dotel.resource.attributes=service.name=myService \
-Dotel.exporter.otlp.endpoint=http://localhost:4318 \
-Dotel.service.name=my-java-app \
-Dotel.traces.exporter=zipkin \
-Dotel.exporter.zipkin.endpoint=http://localhost:9411/api/v2/spans \
-jar springboot_app.jar >test.log 2>&1 &

截图如下:

Prometheus监控

http://ip::9090/graph

grafana监控

http://IP:3000/

zipkin监控

http://IP:9411/

夜莺监控

http://iP:17000

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/bicheng/76595.shtml
繁体地址,请注明出处:http://hk.pswp.cn/bicheng/76595.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

5. 蓝桥公园

题目描述 小明喜欢观景,于是今天他来到了蓝桥公园。 已知公园有 N 个景点,景点和景点之间一共有 M 条道路。小明有 Q 个观景计划,每个计划包含一个起点 stst 和一个终点 eded,表示他想从 stst 去到 eded。但是小明的体力有限&am…

虚幻基础:碰撞帧运算

能帮到你的话,就给个赞吧 😘 文章目录 碰撞碰撞盒线段检测 帧运算:每个程序流就是一帧的计算结果速度过快时(10000),导致每帧移动过大(83),从而导致碰撞盒错过而没有碰撞速度快的碰撞要用线段检测 碰撞 碰撞盒 线段检…

Qt 入门 3 之对话框 QDialog

Qt 入门 3 之对话框 QDialog 本文从以下几点分开讲述: - 对话框的基本原理介绍 - 两种不同类型的对话框 - 一个由多个窗口组成并且窗口间可以相互切换的程序 1.模态和非模态对话框 QDialog 类是所有对话框窗口类的基类。对话框窗口是一个经常用来完成短小任务或者…

数据结构——哈希技术及链地址法

目录 一、哈希的定义 二、哈希冲突定义 三、构造哈希函数的方法 四、四种解决哈希冲突的方法 4.1 开放地址法 4.2 链地址法 4.3 再散列函数法 4.4 公共区溢出法 五、链地址法结构体设计 六、基本操作的实现 6.1 哈希函数 6.2 初始化 6.3 插入值 6.4 删除值 6.5 查…

算法思想之前缀和(二)

欢迎拜访:雾里看山-CSDN博客 本篇主题:算法思想之前缀和(二) 发布时间:2025.4.11 隶属专栏:算法 目录 滑动窗口算法介绍核心思想大致步骤 例题和为 K 的子数组题目链接题目描述算法思路代码实现 和可被 K 整除的子数组题目链接题目…

开源的7B参数OCR视觉大模型:RolmOCR

1. 背景介绍 早些时候,Allen Institute for AI 发布了 olmOCR,这是一个基于 Qwen2-VL-7B 视觉语言模型(VLM)的开源工具,用于处理 PDF 和其他复杂文档的 OCR(光学字符识别)。开发团队对该工具的…

移动端六大语言速记:第14部分 - 数据库操作

移动端六大语言速记:第14部分 - 数据库操作 本文将对比Java、Kotlin、Flutter(Dart)、Python、ArkTS和Swift这六种移动端开发语言在数据库操作方面的特性,帮助开发者理解和掌握各语言的数据库编程能力。 14. 数据库操作 14.1 SQL查询 各语言SQL查询实现方式对比: 特性Ja…

有哪些反爬机制可能会影响Python爬取视频?如何应对这些机制?

文章目录 前言常见反爬机制及影响1. IP 封禁2. 验证码3. 请求头验证4. 动态加载5. 加密与混淆6. 行为分析 应对方法1. 应对 IP 封禁2. 应对验证码3. 应对请求头验证4. 应对动态加载5. 应对加密与混淆6. 应对行为分析 前言 在使用 Python 爬取视频时,会遇到多种反爬…

ESP32开发入门:基于VSCode+PlatformIO环境搭建指南

前言 ESP32作为一款功能强大的物联网开发芯片,结合PlatformIO这一现代化嵌入式开发平台,可以大幅提升开发效率。本文将详细介绍如何在VSCode中搭建ESP32开发环境,并分享实用开发技巧。 一、环境安装(Windows/macOS/Linux&#xf…

DeepSeek:穿透行业知识壁垒的搜索引擎攻防战

DeepSeek:穿透行业知识壁垒的搜索引擎攻防战 文 / 产业智能观察组(人机协同创作) 一、搜索引擎的"认知折叠"危机 2024年Q1数据显示,百度搜索结果前10页中,61.7%的内容存在"伪专业化"现象——看似…

SQL 外键(Foreign Key)详细讲解

1. 什么是外键?​​ ​​定义​​:外键是数据库表中的一列(或一组列),用于​​建立两个表之间的关联关系​​。外键的值必须匹配另一个表的主键(Primary Key)或唯一约束(Unique Con…

5G中的DU和CU的作用

在5G网络架构中,CU(Centralized Unit,集中单元) 和 DU(Distributed Unit,分布单元) 是无线接入网(RAN)的重要组成部分,它们的分工和作用如下: 1.…

深度解析 n8n:强大的开源工作流自动化平台

在数字化时代,企业和个人面临着日益复杂的工作流程和多样化的应用工具,如何高效整合这些资源、实现工作流的自动化成为提升效率的关键。n8n 作为一款开源的工作流自动化平台,凭借其强大的功能、广泛的应用集成能力和灵活的部署方式&#xff0…

ruby超高级语法

以下是 Ruby 中一些 极度硬核 的语法和底层特性,涉及元编程的深渊、虚拟机原理、语法黑魔法等,适用于追求极限的 Ruby 开发者: 高级语法一 一、语法核弹级操作 1. 动态修改继承链 class A; def foo; "A"; end end class B; def …

flutter 获取通话记录和通讯录

Dart SDK version is 3.7.01 dependencies:flutter:sdk: flutterpermission_handler: ^11.0.1 # 权限管理flutter_contacts: ^1.1.92call_log: ^5.0.5cupertino_icons: ^1.0.8dev_dependencies:flutter_test:sdk: flutterflutter_lints: ^5.0.0 2 contact_and_calls_page.da…

bash脚本手动清空mysql表数据

文章目录 1、bash脚本手动清空mysql表数据 1、bash脚本手动清空mysql表数据 #!/bin/bash# 配置区域(修改此处) MYSQL_USER"root" MYSQL_PASSWORD"123456" MYSQL_HOST"localhost" DATABASES("hps-base:base_test_ite…

Spark Core编程

一文读懂Spark Core编程核心要点 最近在学习大数据处理框架Spark,今天来给大家分享一下Spark Core编程中非常重要的内容,包括RDD算子、累加器和广播变量,希望能帮助大家更好地理解和掌握Spark编程。先来说说RDD算子,它是Spark编程…

SDP(一)

SDP(Session Description Protocol)会话描述协议相关参数 Session Description Protocol Version (v): 0 --说明:SDP当前版本号 Owner/Creator, Session Id (o): - 20045 20045 IN IP4 192.168.0.0 --说明:发起者/创建者 会话ID,那么该I…

HarmonyOS:组件布局保存至相册

一,需求背景 有这样一个需求,将页面上的某个自定义组件以图片的形式保存至相册。 二,需求拆解 根据需求分析,可将需求拆解成两步: 1,将组件转换成图片资源; 2,将图片保存到相册…

算法中的数论基础

算法中的数论基础 本篇文章适用于算法考试或比赛之前的临场复习记忆,没有复杂公式推理,基本上是知识点以及函数模版,涵盖取模操作、位运算的小技巧、组合数、概率期望、进制转换、最大公约数、最小公倍数、唯一分解定理、素数、快速幂等知识…