Prometheus+Grafana監控Docker主機

目錄

  1. 爲什麼要監控
  2. Prometheus介紹
  3. Cadvisor介紹
  4. Grafana介紹
  5. Prometheus+Grafana監控Docker

爲什麼要監控

實時反饋系統運行狀態,保證業務持續性進行
監控維度:

硬件監控 溫度,硬件故障等
系統監控 CPU,內存,硬盤,網卡流量,TCP狀態,進程數
應用監控 Nginx、Tomcat、PHP、MySQL、Redis等
日誌監控 系統日誌、服務日誌、訪問日誌、錯誤日誌
安全監控 WAF,敏感文件監控
API監控 可用性,接口請求,響應時間
業務監控 例如電商網站,每分鐘產生多少訂單、註冊多少用戶、多少活躍用戶、推廣活動效果
流量分析 根據流量獲取用戶相關信息,例如用戶地理位置、某頁面訪問狀況、頁面停留時間等

Prometheus介紹

Prometheus(普羅米修斯)是一個最初在SoundCloud上構建的監控系統。自2012年成爲社區開源項目,
擁有非常活躍的開發人員和用戶社區。爲強調開源及獨立維護,Prometheus於2016年加入雲原生雲計算
基金會(CNCF),成爲繼Kubernetes之後的第二個託管項目。
https://prometheus.io
https://github.com/prometheus

Prometheus 特點:

多維數據模型:由度量名稱和鍵值對標識的時間序列數據
PromSQL: 一種靈活的查詢語言,可以利用多維數據完成複雜的查詢
不依賴分佈式存儲,單個服務器節點可直接工作
基於HTTP的pull方式採集時間序列數據
推送時間序列數據通過PushGateway組件支持
通過服務發現或靜態配置發現目標
多種圖形模式及儀表盤支持(grafana)

架構圖:
在這裏插入圖片描述
組件說明:

Prometheus Server 收集指標和存儲時間序列數據,並提供查詢接口
ClientLibrary 客戶端庫
Push Gateway 短期存儲指標數據。主要用於臨時性的任務
Exporters 採集已有的第三方服務監控指標並暴露metrics
Alertmanager 告警
Web UI 簡單的Web控制檯

prometheus安裝:
在這裏插入圖片描述
prometheus配置文件:

# my global config
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
    - targets: ['localhost:9090']
                      

訪問地址:http://192.168.98.90:9090
在這裏插入圖片描述

Cadvisor介紹

用於收集正在運行的容器資源使用情況
github:https://github.com/google/cadvisor

Cadvisor安裝:
在這裏插入圖片描述
訪問地址:http://192.168.98.90:8080/containers/
在這裏插入圖片描述

Grafana介紹

Grafana是一個跨平臺的開源的度量分析和可視化工具,可以通過將採集的數據查詢然後可視化的展示,並及時通知

Grafana安裝:
https://grafana.com/grafana/download?platform=docker
在這裏插入圖片描述

Prometheus+Grafana監控Docker

1)更新配置prometheus.yml配置文件

	#Cadvisor配置地址
  - job_name: 'docker'
    static_configs:
    - targets: ['192.168.98.90:8080']

2)重啓prometheus看到能看到container*的採集標本
在這裏插入圖片描述
3) Grafana配置數據源
在這裏插入圖片描述
在這裏插入圖片描述
4)導入別人製作好的模板,輸入模板id https://grafana.com/grafana/dashboards?orderBy=name&direction=asc
在這裏插入圖片描述
5) 展示docker運行容器資源狀況
在這裏插入圖片描述

至此,基本演示完畢。更多內容後續更新!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章