日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Prometheus部署监控容器

發布時間:2025/3/15 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Prometheus部署监控容器 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Prometheus架構描述

? ? Prometheus 是一個非常優秀的監控工具。準確的說,應該是監控方案。Prometheus 提供了監控數據搜集、存儲、處理、可視化和告警一套完整的解決方案

? ??Prometheus 最大的亮點和先進性是它的多維數據模型

? ?

? Prometheus Server

? ? ? ??Prometheus Server 負責從 Exporter 拉取和存儲監控數據,并提供一套靈活的查詢語言(PromQL)供用戶使用

? Exporter

? ? ? ??Exporter 負責收集目標對象(host, container…)的性能數據,并通過 HTTP 接口供 Prometheus Server 獲取

?可視化組件

? ? ?監控數據的可視化展現對于監控方案至關重要。以前 Prometheus 自己開發了一套工具,不過后來廢棄了,因為開源社區出現了更為優秀的產品 Grafana。Grafana 能夠與 Prometheus 無縫集成,提供完美的數據展示能力

?Alertmanager

? ? ?用戶可以定義基于監控數據的告警規則,規則會觸發告警。一旦 Alermanager 收到告警,會通過預定義的方式發出告警通知。支持的方式包括 Email、PagerDuty、Webhook 等.

?

Prometheus數據存儲模型

? ? ?Prometheus 只需要定義一個全局的指標?container_memory_usage_bytes,然后通過添加不同的維度數據來滿足不同的業務需求

? ??

?

?

? 1.通過維度對數據進行說明,附加更多的業務信息,進而滿足不同業務的需求.同時維度是可以動態添加的,比如再給數據加上一個?user?維度,就可以按用戶來統計容器內存使用量了

? 2.Prometheus 豐富的查詢語言能夠靈活、充分地挖掘數據的價值.前面示例中的 avg、sum、by 只是查詢語言中很小的一部分功能.Prometheus 對多維數據進行分片、聚合的強大能力

?

Prometheus搭建實例

? ? 1. Prometheus Server

? ? ? ? ?Prometheus Server 本身也將以容器的方式運行在 host 192.168.11.133 上

? ? 2. Exporter

? ? ? ? ?Prometheus 有很多現成的 Exporter,完整列表請參考?https://prometheus.io/docs/instrumenting/exporters/

? ? ? ? 使用:

? ? ? ? ? ? ? ? Node Exporter? ?負責收集 host 硬件和操作系統數據

? ? ? ? ? ? ? ? cAdvisor? ? ? ? ? ? 負責收集容器數據

? ? 3.Grafana

? ? ? ? 顯示多維數據,Grafana 本身也將以容器方式運行在 host 192.168.11.133 上

?

1.安裝node Exporter收集主機數據? ?需要在每個主機上都安裝

docker run -d -p 9100:9100 \ -v "/proc:/host/proc" \ -v "/sys:/host/sys" \ -v "/:/rootfs" \ --net=host \ prom/node-exporter \ --path.procfs /host/proc \ --path.sysfs /host/sys \ --collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)"#Node Exporter 啟動后,將通過 9100 提供 host 的監控數據 http://192.168.11.133:9100/metrics node exporter安裝

?

2.安裝cAdvisor收集容器數據? 每個跑容器的主機上都需要安裝

docker run \ --volume=/:/rootfs:ro \ --volume=/var/run:/var/run:rw \ --volume=/sys:/sys:ro \ --volume=/var/lib/docker/:/var/lib/docker:ro \ --publish=8080:8080 \ --detach=true \ --name=cadvisor \ --net=host \ google/cadvisor:latest[root@node3 ~]# mount -o remount,rw '/sys/fs/cgroup' [root@node3 ~]# ln -s /sys/fs/cgroup/cpu,cpuacct /sys/fs/cgroup/cpuacct,cpu cAdvisor安裝

?

3.選擇一臺主機安裝Prometheus Server

docker run -d -p 9090:9090 \ -v /root/prometheus.yml:/etc/prometheus/prometheus.yml \ --name prometheus \ --net=host \ prom/prometheus Prometheus server安裝 global:scrape_interval: 15s # By default, scrape targets every 15 seconds.# Attach these labels to any time series or alerts when communicating with# external systems (federation, remote storage, Alertmanager).external_labels:monitor: 'codelab-monitor'# 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'# Override the global default and scrape targets from this job every 5 seconds.scrape_interval: 5sstatic_configs:- targets: ['localhost:9090','localhost:8080','localhost:9100','192.168.11.134:8080','192.168.11.134:9100'] prometheus.yml

?static_configs:? ?指定從哪些 exporter 抓取數據.這里指定了兩臺 host 上的 Node Exporter 和 cAdvisor

?

?

? ?所有?Target?的?State?都是?UP,說明 Prometheus Server 能夠正常獲取監控數據

?

4.安裝Grafana? 選擇和Prometheus Server同一臺主機

docker run -d -i -p 3000:3000 \ -e "GF_SERVER_ROOT_URL=http://grafana.server.name" \ -e "GF_SECURITY_ADMIN_PASSWORD=secret" \ --net=host \ grafana/grafana-e "GF_SECURITY_ADMIN_PASSWORD=secret 指定了 Grafana admin用戶密碼 secret grafana安裝

?

5.使用Grafana展示Prometheus Server的數據

?

1.添加data source

2.下載dashboard

? ? 訪問??https://grafana.com/dashboards?dataSource=prometheus&search=docker??下載這些現成的 Dashboard 每個Dashboard就是一個json文件

? ??

3.添加dashboard

?

?

?

轉載于:https://www.cnblogs.com/yxh168/p/9646554.html

總結

以上是生活随笔為你收集整理的Prometheus部署监控容器的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。