Grafana與Prometheus實戰

🌟Grafana的Dashboard的權限管理

創建團隊

創建用戶

設置團隊權限

🌟Prometheus啟用https及認證功能

自建ca的證書

準備證書目錄

mkdir /app/tools/prometheus-2.53.4.linux-amd64/certs
cd /app/tools/prometheus-2.53.4.linux-amd64/certs

生成ca的私鑰

openssl genrsa -out ca.key 4096

生成ca的自簽名證書

openssl req -x509 -new -nodes -sha512 -days 3650 \-subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=zhubl.xyz" \-key ca.key \-out ca.crt

基于自建CA證書生成Prometheus服務端證書

準備證書存放目錄

mkdir server

生成prometheus主機的私鑰

openssl genrsa -out server/prometheus.zhubl.xyz.key 4096

生成prometheus主機的證書申請

openssl req -sha512 -new \-subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=prometheus.zhubl.xyz" \-key server/prometheus.zhubl.xyz.key \-out server/prometheus.zhubl.xyz.csr

生成x509 v3擴展文件

cat > v3.ext <<-EOF
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt_names[alt_names]
DNS.1=zhubl.xyz
DNS.2=zhubl
DNS.3=prometheus.zhubl.xyz
EOF

使用"v3.ext"給prometheus主機簽發證書

openssl x509 -req -sha512 -days 3650 \-extfile v3.ext \-CA ca.crt -CAkey ca.key -CAcreateserial \-in server/prometheus.zhubl.xyz.csr \-out server/prometheus.zhubl.xyz.crt

將crt文件轉換為cert客戶端證書文件

openssl x509 -inform PEM -in server/prometheus.zhubl.xyz.crt -out server/prometheus.zhubl.xyz.cert

生成認證初始用戶(可跳過)

方式一

python3 -c 'import bcrypt; print("k8s: " + bcrypt.hashpw("zhubl".encode(), bcrypt.gensalt(rounds=10)).decode())'

方式二

[root@prometheus-server31 ~]# apt-get update
[root@prometheus-server31 ~]# apt-get -y install apache2-utils
[root@prometheus-server31 ~]# htpasswd -Bbn k8s zhubl
k8s:$2y$05$cwtXieUbCkQSFK0EiCPPr.49/JO8MwD6zbTS0IEArl2K9EyyWFbtq[root@prometheus-server31 ~]# 

準備Prometheus的認證文件

vim /app/tools/prometheus-2.53.4.linux-amd64/auth.yml 
tls_server_config:cert_file: /app/tools/prometheus-2.53.4.linux-amd64/certs/server/prometheus.zhubl.xyz.crtkey_file: /app/tools/prometheus-2.53.4.linux-amd64/certs/server/prometheus.zhubl.xyz.key
# 下面的認證信息可以注釋,若啟用,則訪問https頁面時需要指定認證信息喲~
basic_auth_users:k8s: $2b$10$LRfmdrmUBOfL3GrAvCp69ep36rDgpqfKNbO7/u/jjOTJraBgWS3f2

修改Prometheus的啟動腳本添加’–web.config.file’參數指定認證文件

vim /etc/systemd/system/prometheus-server.service
...
[Service]
...
ExecStart=/bin/bash -c "/app/tools/prometheus-2.53.4.linux-amd64/prometheus --web.config.file=/app/tools/prometheus-2.53.4.linux-amd64/auth.yml ....

重啟Prometheus服務

1.加載服務配置文件
systemctl daemon-reload2.重啟服務
systemctl restart prometheus-server.service3.檢查
ss -ntl | grep 9090

訪問測試

?使用認證文件的用戶配置即可。

?溫馨提示: 生產環境中,如果使用權威機構證書,可跳過前2個步驟。

🌟Prometheus基于文件的服務發現案例

靜態配置:(static_configs)

  • 修改Prometheus的配置文件時需要熱加載配置文件或者重啟服務生效。

動態配置:(*_sd_config)

  • 無需重啟或熱加載服務,可以監聽本地的文件,或者通過注冊中心,服務發現中心發現要監控的目標。

參考鏈接:

https://prometheus.io/docs/prometheus/latest/configuration/configuration/#file_sd_config

修改配置文件

[root@prometheus-server31 ~]# vim /app/tools/prometheus-2.53.4.linux-amd64/prometheus.yml 
...- job_name: "file-sd"file_sd_configs:- files:- /tmp/xixi.json- /tmp/haha.yaml

熱加載配置文件

[root@promethues-server31 prometheus-2.53.4.linux-amd64]# curl -X POST https://10.0.0.31:9090/-/reload -k -u k8s:zhubl
[root@promethues-server31 prometheus-2.53.4.linux-amd64]# 
[root@promethues-server31 prometheus-2.53.4.linux-amd64]#  ./promtool check config prometheus.yml
Checking prometheus.ymlWARNING: file "/tmp/xixi.json" for file_sd in scrape job "file-sd" does not existWARNING: file "/tmp/haha.yaml" for file_sd in scrape job "file-sd" does not existSUCCESS: prometheus.yml is valid prometheus config file syntax

修改json格式文件

[root@prometheus-server31 /app/tools/prometheus-2.53.4.linux-amd64]# cat > /tmp/xixi.json <<EOF
[{"targets": [ "10.0.0.41:9100" ],"labels": {"haha": "xixi", "xixi": "xixi-json"}}
]
EOF

驗證是否自動監控目標

https://10.0.0.31:9090/targets?search=

再次編寫yaml文件

[root@prometheus-server31 /app/tools/prometheus-2.53.4.linux-amd64]# cat > /tmp/haha.yaml <<EOF
- targets:- '10.0.0.42:9100' - '10.0.0.43:9100' labels:address: ShaHeClassRoom: haha
EOF
[root@promethues-server31 prometheus-2.53.4.linux-amd64]# ./promtool check config prometheus.yml
Checking prometheus.ymlSUCCESS: prometheus.yml is valid prometheus config file syntax

驗證是否自動監控目標

https://10.0.0.31:9090/targets?search=

Grafana導入模板ID

1860

🌟基于consul的服務發現案例

官方文檔:

https://www.consul.io/

https://developer.hashicorp.com/consul/install#linux

部署consul集群

下載consul(41-43節點)

wget https://releases.hashicorp.com/consul/1.21.4/consul_1.21.4_linux_amd64.zip

解壓consul

[root@node-exporter41 ~]# unzip consul_1.21.4_linux_amd64.zip  -d /usr/local/bin/[root@node-exporter41 ~]# scp /usr/local/bin/consul 10.0.0.42:/usr/local/bin/
[root@node-exporter41 ~]# scp /usr/local/bin/consul 10.0.0.43:/usr/local/bin/

運行consul 集群

服務端43:
[root@node-exporter43 ~]# consul agent -server -bootstrap -bind=10.0.0.43 -data-dir=/app/tools/consul -client=10.0.0.43 -ui客戶端42:
[root@node-exporter42 ~]# consul agent -server -bind=10.0.0.42 -data-dir=/app/tools/consul -client=10.0.0.42 -ui -retry-join=10.0.0.43客戶端41:
[root@node-exporter41 ~]# consul agent -server -bind=10.0.0.41 -data-dir=/app/tools/consul -client=10.0.0.41 -ui -retry-join=10.0.0.43

查看各節點的監聽端口

ss -ntl | egrep "8300|8500"

訪問console服務的WebUI

http://10.0.0.43:8500/ui/dc1/nodes

使用consul實現自動發現

修改prometheus的配置文件

[root@prometheus-server31 ~]# vim /app/tools/prometheus-2.53.4.linux-amd64/prometheus.yml- job_name: "consul-seriver-discovery"# 配置基于consul的服務發現consul_sd_configs:# 指定consul的服務器地址,若不指定,則默認值為"localhost:8500".- server: 10.0.0.43:8500- server: 10.0.0.42:8500- server: 10.0.0.41:8500relabel_configs:# 匹配consul的源標簽字段,表示服務名稱- source_labels: [__meta_consul_service]# 指定源標簽的正則表達式,若不定義,默認值為"(.*)"regex: consul# 執行動作為刪除,默認值為"replace",有效值有多種#   https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_actionaction: drop

檢查配置文件是否正確

[root@prometheus-server31 ~]# cd /app/tools/prometheus-2.53.4.linux-amd64/
[root@prometheus-server31 prometheus-2.53.4.linux-amd64]# 
[root@prometheus-server31 prometheus-2.53.4.linux-amd64]# ./promtool check config ./prometheus.yml
Checking ./prometheus.ymlSUCCESS: ./prometheus.yml is valid prometheus config file syntax

重新加載配置

[root@prometheus-server31 ~]# curl -X POST https://10.0.0.31:9090/-/reload -k -u k8s:zhubl

被監控節點注冊到console集群

1 注冊節點
curl -X PUT -d '{"id":"prometheus-node42","name":"prometheus-node42","address":"10.0.0.42","port":9100,"tags":["node-exporter"],"checks": [{"http":"http://10.0.0.42:9100","interval":"5m"}]}' http://10.0.0.43:8500/v1/agent/service/registercurl -X PUT -d '{"id":"prometheus-node43","name":"prometheus-node43","address":"10.0.0.43","port":9100,"tags":["node-exporter"],"checks": [{"http":"http://10.0.0.43:9100","interval":"5m"}]}' http://10.0.0.43:8500/v1/agent/service/register

被監控節點注銷

curl -X PUT http://10.0.0.43:8500/v1/agent/service/deregister/prometheus-node42

TODO—> 目前有個坑

你注冊時找得哪個節點,那么注銷時也要找這個節點注銷,待解決…

🌟Prometheus監控https實戰案例

參考鏈接:

https://prometheus.io/docs/prometheus/2.54/configuration/configuration/#scrape_config

https://prometheus.io/docs/prometheus/2.54/configuration/configuration/#tls_config

修改Prometheus的配置文件

[root@prometheus-server31 ~]# vim /app/tools/prometheus-2.53.4.linux-amd64/prometheus.yml - job_name: "prometheus"# 指定要使用的協議scheme: 'https'# 配置https證書相關信息tls_config:ca_file: certs/ca.crtcert_file: certs/server/prometheus.zhubl.xyz.crtkey_file: certs/server/prometheus.zhubl.xyz.keyinsecure_skip_verify: true# 認證相關的信息basic_auth:username: k8spassword: zhubl

熱加載配置

[root@prometheus-server31 ~]# curl -X POST https://10.0.0.31:9090/-/reload -k -u k8s:zhubl

Prometheus的WebUI驗證

https://10.0.0.31:9090/targets?search=

🌟node-exporter的黑白名單

參考鏈接:

https://github.com/prometheus/node_exporter

停止服務

systemctl stop node-exporter.service 

配置黑名單

./node_exporter --no-collector.cpu

配置白名單

./node_exporter --collector.disable-defaults --collector.cpu --collector.uname

相關指標測試

node_cpu_seconds_total----》 cpunode_uname_info----》 uname

🌟Prometheus server實現黑白名單

黑名單

修改配置文件

vim /app/tools/prometheus-2.53.4.linux-amd64/prometheus.yml- job_name: "k8s_exporter"params:exclude[]:- cpu                                                                                                                      static_configs:- targets: ["10.0.0.42:9100"]

過濾方式

node_cpu_seconds_total{job="k8s_exporter"}

白名單

修改配置文件

vim /app/tools/prometheus-2.53.4.linux-amd64/prometheus.yml- job_name: "dba_exporter"params:collect[]:- unamestatic_configs:- targets: ["10.0.0.41:9100"]

過濾方式

node_uname_info{job="dba_exporter"}

🌟Prometheus的標簽管理

什么是標簽

標簽用于對數據分組和分類,利用標簽可以將數據進行過濾篩選

標簽管理的常見場景

  • 刪除不必要的指標
  • 從指標中刪除敏感或不需要的標簽
  • 添加,編輯或修改指標的標簽值或標簽格式

標簽的分類

默認標簽

		Prometheus自身內置的標簽,格式為"__LABLE__"。如上圖所示,典型點如下所示:- "__metrics_path__"- "__address__"- "__scheme__"- "__scrape_interval__"- "__scrape_timeout__"- "instance"- "job"

應用標簽

		應用本身內置,尤其是監控特定的服務,會有對應的應用標簽,格式一般為"__LABLE"如下圖所示,以consul服務為例,典型點如下所示:- "__meta_consul_address"- "__meta_consul_dc"- ...

自定義標簽

指的是用戶自定義的標簽,我們在定義targets可以自定義。

標簽主要有兩種表現形式

私有標簽

以"__*“樣式存在,用于獲取監控目標的默認元數據屬性,比如"scheme”,“address”,"metrics_path"等。

普通標簽

對監控指標進行各種靈活管理操作,常見的操作有刪除不必要敏感數據,添加,編輯或修改指標標簽紙或者標簽格式等。

Prometheus對數據處理的流程

  • 1.服務發現: 支持靜態發現和動態發現,主要是找打到對應的target。
  • 2.配置: 加載"scheme",“address”,"metrics_path"等信息。
  • 3.重新標記: relabel_configs,主要針對要監控的target的標簽。
  • 4.抓取: 開始抓取數據。
  • 5.重新標記: metric_relabel_configs,主要針對已經抓取回來的metrics的標簽的操作。

為targets自定義打標簽案例

vim /app/tools/prometheus-2.53.4.linux-amd64/prometheus.yml- job_name: "node-exporter-lable"static_configs:- targets: ["10.0.0.41:9100","10.0.0.42:9100","10.0.0.43:9100"]labels:auther: zhuhaha: hahahaxixi: xixixi

查看webUI

https://10.0.0.31:9090/targets?search=

🌟relabel_configs替換標簽replace案例

修改prometheus的配置文件

vim /app/tools/prometheus-2.53.4.linux-amd64/prometheus.yml
...- job_name: "node-exporter-relabel_configs"static_configs:- targets: ["10.0.0.41:9100","10.0.0.42:9100","10.0.0.43:9100"]labels:auther: zhublog: zhubaolin.blog.csdn.netrelabel_configs:# 指定正則表達式匹配成功的label進行標簽管理的列表- source_labels:- __scheme__- __address__- __metrics_path__# 表示source_labels對應Label的名稱或值進行匹配此處指定的正則表達式。# 此處我們對數據進行了分組,后面replacement會使用"${1}"和"$2"進行引用。regex: "(http|https)(.*)" # 指定用于連接多個source_labels為一個字符串的分隔符,若不指定,默認為分號";"。# 假設源數據如下:# 	__address__="10.0.0.31:9100"#		__metrics_path__="/metrics"#		__scheme__="http"# 拼接后操作的結果為: "http10.0.0.31:9100/metrics"separator: ""# 在進行Label替換的時候,可以將原來的source_labels替換為指定修改后的label。# 將來會新加一個標簽,標簽的名稱為"prometheus_ep",值為replacement的數據。target_label: "prometheus_ep"# 替換標簽時,將target_label對應的值進行修改成此處的值replacement: "${1}://${2}"# 對Label或指標進行管理,場景的動作有replace|keep|drop|lablemap|labeldrop等,默認為replace。action: replace

熱加載配置

curl -X POST https://10.0.0.31:9090/-/reload -k -u k8s:zhubl

webUI驗證

https://10.0.0.31:9090/targets?search=

總結

相對來說,relabel_configs和labels的作用類似,也是為實例打標簽,只不過relabel_configs的功能性更強。我們可以基于標簽來對監控指標進行過濾。

🌟relabel_configs新增標簽映射labelmap案例

修改prometheus的配置文件

vim /app/tools/prometheus-2.53.4.linux-amd64/prometheus.yml- job_name: "node-exporter-relabel_configs-labeldrop"static_configs:- targets: ["10.0.0.31:9100","10.0.0.41:9100","10.0.0.42:9100","10.0.0.43:9100"]relabel_configs:- regex: "(job|app)"replacement: "${1}_labelmap_kubernetes"action: labelmap- regex: "(job|app)"# 刪除regex匹配到的標簽action: labeldrop

熱加載配置

curl -X POST https://10.0.0.31:9090/-/reload -k -u k8s:zhubl

webUI驗證

https://10.0.0.31:9090/targets?search=

🌟metric_relabel_configs修改metric標簽案例

修改prometheus的配置文件

vim /app/tools/prometheus-2.53.4.linux-amd64/prometheus.yml- job_name: "node-exporter-metric_relabel_configs"static_configs:- targets: ["10.0.0.31:9100","10.0.0.41:9100","10.0.0.42:9100","10.0.0.43:9100"]metric_relabel_configs:- source_labels:- __name__regex: "node_cpu_.*"action: drop

熱加載配置

curl -X POST https://10.0.0.31:9090/-/reload -k -u k8s:zhubl

webUI驗證

https://10.0.0.31:9090/targets?search=

🌟部署blackbox-exporter黑盒監控

blackbox-exporter概述

一般用于監控網站是否監控,端口是否存活,證書有效期等。

blackbox exporter支持基于HTTP, HTTPS, DNS, TCP, ICMP, gRPC協議來對目標節點進行監控。

比如基于http協議我們可以探測一個網站的返回狀態碼為200判讀服務是否正常。

比如基于TCP協議我們可以探測一個主機端口是否監聽。

比如基于ICMP協議來ping一個主機的連通性。

比如基于gRPC協議來調用接口并驗證服務是否正常工作。

比如基于DNS協議可以來檢測域名解析。

下載blackbox-exporter

wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.27.0/blackbox_exporter-0.27.0.linux-amd64.tar.gz

解壓軟件包

[root@node-exporter43 ~]# tar xf blackbox_exporter-0.27.0.linux-amd64.tar.gz  -C /usr/local/
[root@node-exporter43 ~]# cd /usr/local/blackbox_exporter-0.27.0.linux-amd64/

啟動blackbox服務

[root@node-exporter43 blackbox_exporter-0.27.0.linux-amd64]# ./blackbox_exporter

訪問blackbox的WebUI

http://10.0.0.43:9115/

http://10.0.0.43:9115/probe?target=prometheus.io&module=http_2xx

🌟Prometheus server整合blackbox實現網站監控

修改Prometheus的配置文件

vim /app/tools/prometheus-2.53.4.linux-amd64/prometheus.yml# 指定作業的名稱,生成環境中,通常是指一類業務的分組配置。- job_name: 'blackbox-exporter-http'# 修改訪問路徑,若不修改,默認值為"/metrics"metrics_path: /probe# 配置URL的相關參數params:# 此處表示使用的是blackbox的http模塊,從而判斷相應的返回狀態碼是否為200module: [http_2xx]# 靜態配置,需要手動指定監控目標static_configs:# 需要監控的目標- targets:# 支持https協議- https://www.zhubl.xyz/# 支持http協議- http://10.0.0.41# 支持http協議和自定義端口- http://10.0.0.31:9090# 對目標節點進行重新打標簽配置relabel_configs:# 指定源標簽,此處的"__address__"表示內置的標簽,存儲的是被監控目標的IP地址- source_labels: [__address__]# 指定目標標簽,其實就是在"Endpoint"中加了一個target字段(用于指定監控目標),target_label: __param_target# 指定需要執行的動作,默認值為"replace",常用的動作有: replace, keep, and drop。# 但官方支持十幾種動作: https://prometheus.io/docs/prometheus/2.45/configuration/configuration/# 將"__address__"傳遞給target字段。action: replace- source_labels: [__param_target]target_label: instance- target_label: __address__# 指定要替換的值,此處我指定為blackbox exporter的主機地址replacement: 10.0.0.43:9115

熱加載配置

curl -X POST https://10.0.0.31:9090/-/reload -k -u k8s:zhubl

驗證webUI

https://10.0.0.31:9090/targets?search=

導入grafana的模板ID

7587
13659

🌟prometheus基于blackbox的ICMP監控目標主機是否存活

修改Prometheus配置文件

vim /app/tools/prometheus-2.53.4.linux-amd64/prometheus.yml- job_name: 'blackbox-exporter-icmp'metrics_path: /probeparams:# 如果不指定模塊,則默認類型為"http_2xx",不能亂寫!亂寫監控不到服務啦!module: [icmp]static_configs:- targets:- 10.0.0.41- 10.0.0.42relabel_configs:- source_labels: [__address__]target_label: __param_target- source_labels: [__param_target]# 指定注意的是,如果instance不修改,則instance和"__address__"的值相同# target_label: iptarget_label: instance- target_label: __address__replacement: 10.0.0.43:9115

檢查配置文件是否正確

cd /app/tools/prometheus-2.53.4.linux-amd64/
./promtool check config prometheus.yml

熱加載配置

curl -X POST https://10.0.0.31:9090/-/reload -k -u k8s:zhubl

訪問prometheus的WebUI

http://10.0.0.31:9090/targets

訪問blackbox的WebUI

http://10.0.0.41:9115/

grafana過濾jobs數據

基于"blackbox-exporter-icmp"標簽進行過濾。

🌟prometheus基于blackbox的TCP案例監控端口是否存活

修改Prometheus配置文件

vim /app/tools/prometheus-2.53.4.linux-amd64/prometheus.yml- job_name: 'blackbox-exporter-tcp'metrics_path: /probeparams:module: [tcp_connect]static_configs:- targets:- 10.0.0.41:80- 10.0.0.42:22- 10.0.0.31:9090relabel_configs:- source_labels: [__address__]target_label: __param_target- source_labels: [__param_target]target_label: instance- target_label: __address__replacement: 10.0.0.43:9115

檢查配置文件是否正確

./promtool check config prometheus.yml

熱加載配置

curl -X POST https://10.0.0.31:9090/-/reload -k -u k8s:zhubl

訪問prometheus的WebUI

http://10.0.0.31:9090/targets

訪問blackbox exporter的WebUI

http://10.0.0.41:9115/

使用grafana查看數據

基于"blackbox-exporter-tcp"標簽進行過濾。

🌟pushgateway組件實現自定義監控直播人數案例

什么是pushgateway

說白了,就是Prometheus官方用來短期自定義監控指標。

如果長期監控的組件建議運維開發人員編寫相應的exporters。

部署pushgateway

wget https://github.com/prometheus/pushgateway/releases/download/v1.11.1/pushgateway-1.11.1.linux-amd64.tar.gz

解壓軟件包

[root@node-exporter42 ~]# tar xf pushgateway-1.11.1.linux-amd64.tar.gz -C /usr/local/bin/ pushgateway-1.11.1.linux-amd64/pushgateway --strip-components=1

運行pushgateway

[root@node-exporter42 ~]# pushgateway --web.telemetry-path="/metrics" --web.listen-address=:9091 --persistence.file=/data/pushgateway.data

訪問pushgateway的WebUI

http://10.0.0.42:9091/#

模擬直播在線人數統計

使用curl工具推送測試數據pushgateway

[root@node-exporter43 ~]# echo "zhibo_online 35" | curl --data-binary @-  http://10.0.0.42:9091/metrics/job/zhibo/instance/10.0.0.43

pushgateway查詢數據是否上傳成功

[root@node-exporter43 ~]# curl -s http://10.0.0.42:9091/metrics | grep zhibo_online

Prometheus server監控pushgateway

修改prometheus的配置文件

vim /app/tools/prometheus-2.53.4.linux-amd64/prometheus.yml- job_name: "pushgateway"# 采集數據標簽沖突是,遠程的標簽會覆蓋本地Prometheus server的標簽。# 默認值為false,有沖突時,則會使用源標簽前加一個"exported_*"的前綴標簽。honor_labels: truestatic_configs:- targets: - 10.0.0.42:9091

熱加載配置

[root@prometheus-server31 ~]# curl -X POST https://10.0.0.31:9090/-/reload -k -u k8s:zhubl

驗證配置是否生效

http://10.0.0.31:9090/targets?search=

查詢特定指標

zhibo_online

Grafana出圖展示

模擬直播間人數的變化

[root@node-exporter41 ~]# echo "zhibo_online $RANDOM" | curl --data-binary @-  http://10.0.0.42:9091/metrics/job/zhibo/instance/10.0.0.43[root@node-exporter41 ~]# echo "zhibo_online $RANDOM" | curl --data-binary @-  http://10.0.0.42:9091/metrics/job/zhibo/instance/10.0.0.43

🌟使用pushgateway監控TCP的十二種狀態

編寫監控腳本

#!/bin/bash
pushgateway_url="http://10.0.0.42:9091/metrics/job/tcp_status"state="SYN-SENT SYN-RECV FIN-WAIT-1 FIN-WAIT-2 TIME-WAIT CLOSE CLOSE-WAIT LAST-ACK LISTEN CLOSING ESTAB UNKNOWN"for i in $statedocount=`ss -tan |grep $i |wc -l`echo tcp_connections{state=\""$i"\"} $count >> /tmp/tcp.txt
done;cat /tmp/tcp.txt | curl --data-binary @- $pushgateway_url
rm -rf  /tmp/tcp.txt

調用腳本

bash /usr/local/bin/tcp_status.sh

Prometheus查詢數據

tcp_connections

Grafana出圖展示

自定義變量

添加儀表盤

tcp_connections{state="$state"}

🌟網絡的丟包率監控

編寫監控腳本

#!/bin/bash
host="www.zhubl.xyz"loss=`ping $host -c 10 | grep packet | awk '{print $6}' | tr -d '%'`echo loss_packet $loss | curl --data-binary @-  http://10.0.0.42:9091/metrics/job/loss_packet/instance/10.0.0.41

發送測試數據

bash /usr/local/bin/loss_packet.sh

Grafana出圖展示

🌟監控ES集群索引數量

編寫監控腳本

#!/bin/bashpushgateway_url="http://10.0.0.42:9091/metrics/job/indices"indices=`curl -s https://10.0.0.91:9200/_cat/indices?v -u elastic:123456 -k | wc -l`echo indices_num $indices | curl --data-binary @-  $pushgateway_url

發送數據

bash /usr/local/bin/es_index_num.sh

grafana出圖展示

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/96804.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/96804.shtml
英文地址,請注明出處:http://en.pswp.cn/web/96804.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

FPGA交通燈設計報告(源碼+管腳約束+實物圖+設計報告)

基于FPGA的交通燈設計 摘要 本設計采用FPGA技術實現了一個智能交通燈控制系統。系統以Verilog HDL為設計語言,在FPGA平臺上實現了交通燈的自動控制、數碼管倒計時顯示、緊急情況處理等功能。通過合理的狀態機設計和模塊化編程,系統具有良好的實時性、可靠性和可擴展性,能夠…

技術論文分析分析論文《計算機病毒判定專家系統原理與設計》思考其在游戲中的應用

論文原文的引言主要有兩大部分的內容&#xff1a;介紹計算機病毒&#xff0c;明確本文使用的病毒分類方式&#xff1b;分析傳統計算機病毒檢測存在的弊端。對于計算機病毒的定義&#xff0c;文中給出的定義比較嚴謹&#xff0c;我自己查了一下現在百度百科的定義&#xff0c;兩…

《Unity項目實戰:動態加載引發的顯存危機全鏈路排查與重構實踐》

從動態光影那流光溢彩、仿佛賦予虛擬世界真實質感的絢麗效果—這得益于Unity引擎強大的HDRP管線對光照路徑的精準模擬,到物理引擎驅動的物體碰撞精準到毫厘的物理反饋—依托Unity Physics模塊對剛體動力學的毫秒級計算,再到能夠依據不同設備性能自動適配的畫質表現—通過Unit…

智慧水庫綜合管理系統平臺御控物聯網解決方案

一、行業背景與痛點分析水庫作為防洪、灌溉、供水、發電及生態保護的核心基礎設施&#xff0c;其管理效率直接關系到區域水資源安全與可持續發展。然而&#xff0c;傳統水庫管理模式存在四大核心痛點&#xff1a;數據孤島嚴重&#xff1a;水位、雨量、水質、設備狀態等數據分散…

使用nvm安裝Node.js18以下報錯解決方案——The system cannot find the file specified.

使用 nvm 安裝 Node.js 18以下 報錯解決方案 在前端開發過程中&#xff0c;常常需要針對不同項目切換 Node.js 版本。nvm&#xff08;Node Version Manager&#xff09;是最常用的工具。但最近在嘗試安裝 Node.js 14 版本時&#xff0c;遇到了奇怪的錯誤。 問題描述 使用 nv…

在Excel和WPS表格中快速復制上一行內容

有的時候我們在Excel和WPS表格中想復制上一行對應單元格、連續區域或整行的內容&#xff0c;只需要在當前行拖動鼠標左鍵選中相關區域&#xff0c;然后按CtrlD鍵即可將上一行對應位置的內容復制過來——需要注意的是&#xff0c;如果當前行有數據&#xff0c;這些數據會直接被覆…

408學習之c語言(遞歸與函數)

今天主要學習了遞歸與函數的相關內容&#xff0c;下面將我今天所學知識與所寫代碼分享給大家 遞歸核心要點 遞歸三要素 基準條件&#xff08;明確終止條件&#xff09; 遞歸調用&#xff08;逐步分解問題&#xff09; 收斂性&#xff08;確保每次遞歸都向基準條件靠近&#xff…

swVBA自學筆記016、Solidworks API Help 幫助文檔的(三大版塊)

目錄1. Namespace (命名空間) 版塊2. Interface (接口) 版塊3. Members (接口成員) 版塊4、總結關系5、如果你感覺上面說的過于簡單&#xff0c;請往下看!6、示例鏈接→SOLIDWORKS API Help 20197、需要注意的是&#xff0c;帶“I”的對象表示&#xff1a;接口1. Namespace (命…

通俗易懂地講解JAVA的BIO、NIO、AIO

理解Java的I/O模型&#xff08;BIO、NIO、AIO&#xff09;對于構建高性能網絡應用至關重要 &#x1f9e0; 通俗理解&#xff1a;快遞站的故事 想象一個快遞站&#xff1a; ? BIO&#xff1a;就像快遞站為每一個包裹都安排一位專員。專員從接到包裹到處理完&#xff08;簽收、…

LabVIEW 泵輪檢測系統

在汽車行業&#xff0c;泵輪作為液力變矩器關鍵部件&#xff0c;其質量檢測極為重要。傳統手工檢測泵輪效率低且誤差大&#xff0c;為此構建基于 LabVIEW 與西門子硬件結合的泵輪檢測系統。 應用場景 聚焦汽車零部件生產車間&#xff0c;對泵輪總成進行出廠前檢測。在液力變矩…

2025年8月月賽 T2 T3

一. 七天假日 T2原思路&#xff1a;直接計算左右括號的數量&#xff0c;然后直接輸出他們的差改進思路&#xff1a; 用d值記錄截止到當前位置&#xff0c;還需要多少個右括號可以滿足非法要求cur&#xff1a;截止到當前位置&#xff0c;已經有多少個右括號sum是右括號位置的前綴…

數據結構----棧的順序存儲(順序棧)

棧的特點&#xff1a;先進后出棧的操作&#xff1a;用數組進行存儲&#xff08;1&#xff09;初始化&#xff1a;//棧 typedef struct {int *data;//指針模擬分配數組int top;//棧“頂”指針 }Stack; //初始化 Stack InitStack(){Stack s;//給數組分配空間s.data (int*)malloc…

React Hooks原理深度解析與高級應用模式

React Hooks原理深度解析與高級應用模式 引言 React Hooks自16.8版本引入以來&#xff0c;徹底改變了我們編寫React組件的方式。然而&#xff0c;很多開發者僅僅停留在使用層面&#xff0c;對Hooks的實現原理和高級應用模式了解不深。本文將深入探討Hooks的工作原理、自定義Hoo…

兼職網|基于SpringBoot和Vue的蝸牛兼職網(源碼+數據庫+文檔)

項目介紹 : SpringbootMavenMybatis PlusVue Element UIMysql 開發的前后端分離的蝸牛兼職網&#xff0c;項目分為管理端和用戶端和企業端。 項目演示: 基于SpringBoot和Vue的蝸牛兼職網 運行環境: 最好是java jdk 1.8&#xff0c;我們在這個平臺上運行的。其他版本理論上也可…

TDengine 聚合函數 LEASTSQUARES 用戶手冊

LEASTSQUARES 函數用戶手冊 函數定義 LEASTSQUARES(expr, start_val, step_val)功能說明 LEASTSQUARES() 函數對指定列的數據進行最小二乘法線性擬合&#xff0c;返回擬合直線的斜率&#xff08;slope&#xff09;和截距&#xff08;intercept&#xff09;。該函數基于線性回…

Redis最佳實踐——安全與穩定性保障之高可用架構詳解

全面詳解 Java 中 Redis 在電商應用的高可用架構設計一、高可用架構核心模型 1. 多層級高可用體系 #mermaid-svg-anJ3iQ0ymhr025Jn {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-anJ3iQ0ymhr025Jn .error-icon{fil…

ABAP 屏幕在自定義容器寫多行文本框

文章目錄變量定義容器等邏輯屏幕效果變量定義 CONSTANTS: GC_TEXT_LINE_LENGTH TYPE I VALUE 72. TYPES: TEXT_TABLE_TYPE(GC_TEXT_LINE_LENGTH) TYPE C OCCURS 0. DATA: GV_SPLITTER TYPE REF TO CL_GUI_EASY_SPLITTER_CONTAINER. DATA: GV_CUSTOM_CONTAINER TYPE REF TO CL_…

昆山精密機械公司8個Solidworks共用一臺服務器

在當今高度信息化的制造業環境中&#xff0c;昆山精密機械公司面臨著如何高效利用SolidWorks這一核心設計工具的現實挑戰。隨著企業規模的擴大和設計團隊的分散&#xff0c;傳統的單機授權模式已無法滿足協同設計需求。通過引入云飛云共享云桌面解決方案&#xff0c;該公司成功…

【WebSocket?】入門之旅(三):WebSocket 的實戰應用

本篇文章將通過構建一個簡單的實時聊天應用&#xff0c;演示如何在前端和后端搭建 WebSocket 系統&#xff0c;完成實時消息傳輸。通過實戰&#xff0c;幫助你更好地理解 WebSocket 在實際項目中的應用。 目錄 搭建 WebSocket 服務器WebSocket 客戶端實現實時聊天應用示例常見…

CentOS 8-BClinux8.2更換為阿里云鏡像源:保姆級教程

還在為 CentOS 8 官方源訪問緩慢或不可用而煩惱嗎&#xff1f;更換為國內鏡像源&#xff0c;如阿里云&#xff0c;可以顯著提升軟件包下載速度和穩定性。本文將帶你一步步完成 CentOS 8 鏡像源的更換&#xff0c;讓你的系統管理更順暢。 準備工作 在進行任何系統配置更改之前…