Prometheus+Grafana實踐基於SpringBoot-2.x監控告警系統

# Prometheus+Grafana實踐基於SpringBoot 2。x監控告警系統

## 目錄

第1章 課程介紹

第2章 微服務與雲原生背景下的監控圖景

第3章 Prometheus監控實踐

第4章 SpringBoot 2。X整合Prometheus

第5章 Prometheus告警實踐

第6章 Prometheus高階拓展

第7章 課程總結及後續學習方法分享

Prometheus+Grafana實踐基於SpringBoot-2.x監控告警系統

# 使用Prometheus實踐基於Spring Boot監控告警體系

## 第1章 課程介紹

### 本章介紹課程重點,展示本次課程的課程特色及專案。

### 1-1 課程引導 (03:16)

-

課程重點

- ◆監控的意義。

- ◆Metrics Driven Development : MDD理念

- ◆CNCF第二個畢業專案Prometheus剖析

- ◆Prometheus + Grafana監控實戰

- ◆SpringBoot2基於Prometheus支付場景監控與告警實戰

- ◆Prometheus深度探討

-

課程特色

- ◆深入淺出,通俗易懂,比喻和配圖豐富形象

- ◆章節編排邏輯性強,知識非常系統,層層遞進

- ◆程式碼用例豐富 ,幾乎每個知識點都會用程式碼演示

## 第2章 微服務與雲原生背景下的監控圖景

### 2-1 微服務與雲原生背景下的監控圖景 (13:58)

-

監控目的

Prometheus+Grafana實踐基於SpringBoot-2.x監控告警系統

- ◆長期趨勢分析

- ◆對照分析

- ◆告警

- ◆>故障分析與定位

-

Prometheus :監控領域的獨孤九劍

- ◆破劍式:監控微服務

- ◆破刀式: node_ exporter監控作業系統

- ◆破槍式: mysqld_ exporter監控MySQL

- ◆破鞭式:監控Redis

- ◆破索式:監控Flink

- ◆破掌式:監控RabbitMQ/Kafka

- ◆破箭式: Prometheus Operator監控etcd

- ◆破氣式:監控K8S

- ◆總決式:有種種變化,用以體演總訣,共有三百六十種變化。

-

監控的意義

Prometheus+Grafana實踐基於SpringBoot-2.x監控告警系統

-

監控的分類

Prometheus+Grafana實踐基於SpringBoot-2.x監控告警系統

-

MDD

Prometheus+Grafana實踐基於SpringBoot-2.x監控告警系統

- ◆軟體研發:實時感知應用各項指標、聚焦應用最佳化

- ◆運維人員:實時感知系統各項指標、快速定位問題

- ◆產品經理、商務人士:實時掌控業務各項指標、資料驅動決策

-

Prometheus歷史

- Google Borg-> Kubernetes

- Google Borgmon -> Prometheus

## 第3章 Prometheus監控實踐

### 3-1 Prometheus介紹和架構 (12:38)

-

Prometheust介紹

- ◆Go語言實現

- ◆多維度(標籤)

- ◆拉模式為主

- ◆黑盒白盒支援

- ◆單機效能強勁:上千targets ,每秒百萬級時間序列

Prometheus+Grafana實踐基於SpringBoot-2.x監控告警系統

Prometheus+Grafana實踐基於SpringBoot-2.x監控告警系統

-

架構圖

Prometheus+Grafana實踐基於SpringBoot-2.x監控告警系統

-

整體流程

### 3-2 Prometheus環境搭建 (14:35)

-

動態更新配置

。/prometheus ——config。file=prometheus。yml ——web。enable lifecycle

-

Mac安裝

brew install prometheus

-

安裝結果

When run from `brew services`, `prometheus` is run from`prometheus_brew_services` and uses the flags in:/usr/local/etc/prometheus。argsTo have launchd start prometheus now and restart at login:brew services start prometheusOr, if you don‘t want/need a background service you can just run:prometheus ——config。file=/usr/local/etc/prometheus。yml==> Summary /usr/local/Cellar/prometheus/2。26。0: 21 files, 158。6MB

-

啟動

prometheus ——config。file=/usr/local/etc/prometheus。yml

### 3-3 Prometheus環境檔案及儲存解析 (07:23)

Prometheus+Grafana實踐基於SpringBoot-2.x監控告警系統

Prometheus+Grafana實踐基於SpringBoot-2.x監控告警系統

Prometheus+Grafana實踐基於SpringBoot-2.x監控告警系統

Prometheus+Grafana實踐基於SpringBoot-2.x監控告警系統

### 3-4 Grafana環境搭建 (03:55)

Prometheus+Grafana實踐基於SpringBoot-2.x監控告警系統

-

環境搭建

- $ cd “$(brew ——repo)” && git remote set-url origin- https://git。coding。net/homebrew/homebrew。git- $ cd $home && brew update- 清華映象源:· git://mirrors。tuna。tsinghua。edu。cn/homebrew。git- 中科大映象源: http://mirrors。ustc。edu。cn/homebrew。git- 搭建問題- 解決brew報錯 : Another active Homebrew update process is already in progress- 解決辦法 : rm -rf /usr/locai/var/homebrew/locks

-

Mac安裝完成

To have launchd start grafana now and restart at login:brew services start grafanaOr, if you don’t want/need a background service you can just run:grafana-server ——config=/usr/local/etc/grafana/grafana。ini ——homepath /usr/local/share/grafana ——packaging=brew cfg:default。paths。logs=/usr/local/var/log/grafana cfg:default。paths。data=/usr/local/var/lib/grafana cfg:default。paths。plugins=/usr/local/var/lib/grafana/plugins==> Summary /usr/local/Cellar/grafana/7。5。1: 2,663 files, 179。5MB

### 3-5 Grafana整合Prometheus實戰 (10:25)

-

◆建立資料來源

-

◆建立dashboard

Prometheus+Grafana實踐基於SpringBoot-2.x監控告警系統

-

◆建立Panel

Prometheus+Grafana實踐基於SpringBoot-2.x監控告警系統

-

◆視覺化大盤

## 第4章 SpringBoot 2。X整合Prometheus

### 4-1 SpringBoot Micrometer (06:36)

- ◆MeterBinder介面實現bind方法註冊到MeterRegistry

- ◆業務程式碼邏輯更新Metrics

- ◆使用並驗證Metrics

### 4-2 Promtheus分層監控結構實驗 (05:45)

-

分級監控

- http://localhost:8080/actuator

- http://localhost:8080/actuator/metrics

- http://localhost:8080/actuator/metrics/tomcat。global。request。max

### 4-3 SpringBoot、Prometheus、Grafana鏈路打通 (06:59)

Prometheus+Grafana實踐基於SpringBoot-2.x監控告警系統

Prometheus+Grafana實踐基於SpringBoot-2.x監控告警系統

Prometheus+Grafana實踐基於SpringBoot-2.x監控告警系統

Prometheus+Grafana實踐基於SpringBoot-2.x監控告警系統

## 第5章 Prometheus告警實踐

### 5-1 Prometheus告警實戰 (06:29)

-

Prometheus告警三個狀態

- ◆inactive :表示當前報警資訊即不是firing狀態也不是pending狀態

- ◆pending :表示在設定的閾值時間範圍內被啟用的

- ◆firing :表示超過設定的閾值時間被啟用的

-

Prometheus

- 1。 Prometheusmr

- 2、超出持續時間

- 3。 AlertManager

- ◆4、 分組|抑制靜默

- ◆5、媒體型別

- 6、郵件、釘釘、微信等告警

## 第6章 Prometheus高階拓展

### 6-1 Prometheus高階拓展 (13:57)

-

Prometheus叢集

- ◆簡單HA

Prometheus+Grafana實踐基於SpringBoot-2.x監控告警系統

- ◆基本HA+ 遠端儲存

Prometheus+Grafana實踐基於SpringBoot-2.x監控告警系統

- ◆基本HA+ 遠端儲存+聯邦叢集

Prometheus+Grafana實踐基於SpringBoot-2.x監控告警系統

-

Promethues原始架構缺點

- ◆查詢時間有限

- ◆查詢範圍有限

- ◆告警範圍有限

-

Promethues聯邦叢集架構問題

- ◆拆分之痛

- ◆全域性查詢

- ◆資料去重

-

Thanos架構優勢

Prometheus+Grafana實踐基於SpringBoot-2.x監控告警系統

- ◆高可用Prometheus

- ◆全域性檢視

- ◆不受限制的歷史查詢

Prometheus+Grafana實踐基於SpringBoot-2.x監控告警系統

-

Prometheus的坑

- ◆AlertManager掛掉Dead Man‘s Switch

- ◆自監控,交叉監控

- ◆準確性與運維簡易性的權衡

-

Prometheus的九個坑

- ◆先rate再sum,不能先sum再rate順序問題牢記!

- ◆沒有提供管理配置的API介面, Prometheus Operator

- ◆警報和歷史趨勢圖示未必Match

- ◆叢集儲存方案

-

三大架構和Thanos

- ◆儘早幹掉維度過高的壞指標, 28原則

- ◆任何版本的Prometheus都不支援NFS

- ◆從2。0。0到2。14。0重大變遷說明

- ◆注意版本變遷,一些版本中是不可以降級的,比入Docker File、WAL實現、儲存BUG等

- ◆建議,儘量使用新版本,版本的升級和降級- -定要謹慎。新功能的引入也同樣會引|入風險。

## 第7章 課程總結及後續學習方法分享

### 7-1 課程總結 (06:46)

-

監控的意義

- Metrics Driven Development : MDD

- Prometheus架構及儲存解析

- Prometheus

- Grafana

- SpringBootTIH5i :Micrometer。 JVM。 Actuator

- Prometheus。 Grafana。 SpringBoot2監控

- Prometheus告警實戰

- Prometheus高階拓展

-

後續學習方法分享

- ◆Prometheus原始碼研究

- ◆技術部落格輸出

- ◆貢獻程式碼給CNCF Prometheus

## 參考資料

-

[使用Prometheus實踐基於Spring Boot監控告警體系](https://www.imooc.com/learn/1231)

- [阿里雲Prometheus監控](https://help.aliyun.com/document_detail/122123.html)