使用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
英文地址,請注明出處:http://en.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,將圖片保存到相冊…

算法中的數論基礎

算法中的數論基礎 本篇文章適用于算法考試或比賽之前的臨場復習記憶,沒有復雜公式推理,基本上是知識點以及函數模版,涵蓋取模操作、位運算的小技巧、組合數、概率期望、進制轉換、最大公約數、最小公倍數、唯一分解定理、素數、快速冪等知識…