欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

通過prometheus監(jiān)控Tomcat運(yùn)行狀態(tài)的操作流程

 更新時(shí)間:2025年02月08日 08:56:15   作者:景天科技苑  
文章介紹了如何安裝和配置Tomcat,并使用Prometheus和Tomcat Exporter來監(jiān)控Tomcat的運(yùn)行狀態(tài),文章詳細(xì)講解了Tomcat的常用指標(biāo),如連接、請求、會話和線程指標(biāo),并提供了具體的計(jì)算方法和示例,需要的朋友可以參考下

Tomcat安裝配置以及prometheus監(jiān)控Tomcat

Tomcat本身無法對外提供Prometheus所兼容的Metrics,因此需要借助第三方exporter來提供:tomcat-exporter
https://github.com/nlighten/tomcat_exporter

在這里插入圖片描述

一. 安裝并配置tomcat

1、安裝tomcat

yum install tomcat tomcat-webapps -y

在這里插入圖片描述

2、然后下載依賴包

我們可以看到官方介紹,需要很多依賴包

在這里插入圖片描述

wget https://search.maven.org/remotecontent?filepath=io/prometheus/simpleclient/0.12.0/simpleclient-0.12.0.jar
wget https://search.maven.org/remotecontent?filepath=io/prometheus/simpleclient_common/0.12.0/simpleclient_common-0.12.0.jar
wget https://search.maven.org/remotecontent?filepath=io/prometheus/simpleclient_hotspot/0.12.0/simpleclient_hotspot-0.12.0.jar
wget https://search.maven.org/remotecontent?filepath=io/prometheus/simpleclient_servlet/0.12.0/simpleclient_servlet-0.12.0.jar
wget https://search.maven.org/remotecontent?filepath=io/prometheus/simpleclient_servlet_common/0.12.0/simpleclient_servlet_common-0.12.0.jar
wget https://search.maven.org/remotecontent?filepath=nl/nlighten/tomcat_exporter_client/0.0.15/tomcat_exporter_client-0.0.15.jar
wget https://search.maven.org/remotecontent?filepath=nl/nlighten/tomcat_exporter_servlet/0.0.15/tomcat_exporter_servlet-0.0.15.war

當(dāng)然也可以一次性全部下載

git clone https://github.com/littlefun91/tomcat-exporter.git

在這里插入圖片描述

在這里插入圖片描述

3、將jar包和war包分別拷貝至對應(yīng)的目錄下

[root@jingtian03 tomcat_exporter ]#cp *.jar /usr/share/tomcat/lib/
[root@jingtian03 tomcat_exporter ]#cp *.war /usr/share/tomcat/webapps/

啟動后,metrics.war自動解壓

在這里插入圖片描述

4、啟動Tomcat

systemctl start tomcat.service

查看運(yùn)行狀態(tài)

在這里插入圖片描述

5、訪問tomcat的metrics

http://10.10.0.32:8080/metrics/

在這里插入圖片描述

6、配置prometheus

編輯prometheus配置文件,將Tomcat納入監(jiān)控

  - job_name: "tomcat"
    static_configs:
      - targets: ["jingtian03:8080"]

重新加載prometheus配置文件

curl -X POST http://localhost:9090/-/reload

檢查Prometheus的Status->Targets頁面,驗(yàn)證Tomcat是否已經(jīng)成功納入監(jiān)控中

在這里插入圖片描述

可以看到Tomcat相關(guān)指標(biāo)

在這里插入圖片描述

二. Tomcat常用指標(biāo)與示例

對于 Tomcat,我們通常會使用RED 方法,監(jiān)控請求速率(Rate)、請求失敗數(shù)(Errors)、請求延遲(Duration)來評估當(dāng)前服務(wù)的質(zhì)量。

1.Tomcat連接相關(guān)指標(biāo)

在這里插入圖片描述

最大連接數(shù)可以修改

在這里插入圖片描述

在/usr/share/tomcat/conf/server.xml中修改

在這里插入圖片描述

在這里插入圖片描述

重啟tomcat,再看下

在這里插入圖片描述

案例:計(jì)算Tomcat的最大活動連接數(shù)的飽和度,計(jì)算公式:當(dāng)前活躍連接數(shù)/ 最大活躍連接數(shù) * 100

tomcat_connections_active_total / tomcat_connections_active_max * 100

在這里插入圖片描述

2. Tomcat請求相關(guān)指標(biāo)

在這里插入圖片描述

在這里插入圖片描述

tomcat_requestprocessor_time_seconds Tomcat服務(wù)器處理請求所花費(fèi)的總時(shí)間(單位是秒)雖然顯示是gauge類型指標(biāo),但它的值卻是不斷累加的

在這里插入圖片描述

案例1:計(jì)算Tomcat最近5分鐘,Http請求的錯(cuò)誤率占比Http請求總數(shù)的比率。計(jì)算公式: 每5分鐘的錯(cuò)誤請求數(shù) / 每5分鐘的總請求數(shù) * 100

rate(tomcat_requestprocessor_error_count_total[5m]) / rate(tomcat_requestprocessor_request_count_total[5m]) * 100

案例2:計(jì)算Tomcat最近5分鐘,處理每個(gè)請求所需要花費(fèi)的時(shí)間。
這個(gè)本來標(biāo)注的是gauge類型的數(shù)據(jù),但是其值是一直在增大的,因此可以使用irate()來求最近5分鐘內(nèi),每個(gè)請求所花費(fèi)的時(shí)間

irate(tomcat_requestprocessor_time_seconds[5m])

在這里插入圖片描述

3.Tomcat會話相關(guān)指標(biāo)

在這里插入圖片描述

在這里插入圖片描述

案例1:計(jì)算Tomcat創(chuàng)建會話的速率。

sum (rate(tomcat_session_created_total[5m])) by (instance,job,host)

案例2:計(jì)算被拒絕創(chuàng)建的會話占總創(chuàng)建會話的比率。計(jì)算公式:( 拒絕的會話數(shù) / (創(chuàng)建的會話數(shù) + 拒絕會話數(shù)) * 100 )

(tomcat_session_rejected_total / ( tomcat_session_created_total + tomcat_session_rejected_total )) * 100

4.Tomcat線程相關(guān)指標(biāo)

在這里插入圖片描述

允許的最大線程數(shù),也是可以配置的

在這里插入圖片描述

默認(rèn)是200

在這里插入圖片描述

案例1:計(jì)算Tomcat活躍的請求線程數(shù)占總請求的線程數(shù)比率。計(jì)算公式:當(dāng)前活躍線程數(shù) / 最大的線程數(shù) * 100

(tomcat_threads_active_total / tomcat_threads_max) * 100

三. Tomcat告警規(guī)則文件

1、具體告警規(guī)則示例文件(可以根據(jù)公司實(shí)際情況進(jìn)行調(diào)整)

cat /etc/prometheus/rules/tomcat_rules.yml
groups:
- name: tomcat告警規(guī)則
  rules:
  - alert: Tomcat活躍連接數(shù)過高
    expr: tomcat_connections_active_total / tomcat_connections_active_max* 100 >=80
    for: 1m
    labels:
      severity: warning
    annotations:
      summary: "Tomcat服務(wù)器活躍連接數(shù)過高, 實(shí)例:{{ $labels.instance }}"
      description:
        Tomcat最大連接數(shù)是 {{ printf `tomcat_connections_active_max{instance="%s",job="%s",name="%s"}` $labels.instance $labels.job $labels.name | query | first | value }} Tomcat目前連接數(shù)是 {{ printf `tomcat_connections_active_total{instance="%s",job="%s",name="%s"}` $labels.instance $labels.job $labels.name | query | first | value }} Tomcat活躍連接數(shù)已超過最大活躍連接數(shù)的80%, 當(dāng)前值為 {{ $value }}%
  - alert: Tomcat處理請求超過5秒
    expr: rate(tomcat_requestprocessor_time_seconds[5m]) > 5
    for: 5m
    labels:
      severity: warning
    annotations:
      summary: "Tomcat處理請求時(shí)間過長, 實(shí)例:{{ $labels.instance }}"
      description: "Tomcat在過去5分鐘的平均處理請求時(shí)間超過5秒,當(dāng)前值 {{ $value}}。"
  - alert: "Tomcat會話拒絕率超過20%"
    expr: (tomcat_session_rejected_total / (tomcat_session_created_total +tomcat_session_rejected_total)) * 100 > 20
    for: 5m
    labels:
      severity: critical
    annotations:
      summary: "Tomcat會話拒絕率過高, 實(shí)例:{{ $labels.instance }}"
      description: "Tomcat在Host:{{ $labels.host }} 的 {{ $labels.context}} 的上下文中的會話拒絕率超過20%,當(dāng)前值 {{ $value }}。"

  - alert: "Tomcat線程使用率過高"
    expr: (tomcat_threads_active_total / tomcat_threads_max) * 100 > 80
    for: 5m
    labels:
      severity: warning
    annotations:
      summary: "Tomcat線程使?率過?, 實(shí)例:{{ $labels.instance }}"
      description: Tmcat最大線程數(shù)是 {{ printf `tomcat_threads_max{instance="%s",job="%s",name="%s"}` $labels.instance $labels.job $labels.name | query | first| value }} Tomcat目前線程數(shù)是 {{ printf `tomcat_threads_active_total{instance="%s",job="%s",name="%s"}` $labels.instance $labels.job $labels.name | query | first | value }} Tomcat線程數(shù)已超過最大活躍連接數(shù)的80%, 當(dāng)前值為 {{ $value }}%

2、驗(yàn)證告警規(guī)則

在這里插入圖片描述

3、導(dǎo)入Tomcat圖形

1、下載對應(yīng)的dashboard
https://github.com/nlighten/tomcat_exporter/blob/master/dashboard/example.json
下載下來導(dǎo)入

在這里插入圖片描述

在這里插入圖片描述

在這里插入圖片描述

以上就是通過prometheus監(jiān)控Tomcat運(yùn)行狀態(tài)的操作流程的詳細(xì)內(nèi)容,更多關(guān)于prometheus監(jiān)控Tomcat運(yùn)行狀態(tài)的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論