Cadvisor +Prometheus+Grafana
1.1、Cadvisor產(chǎn)品簡介
????????Cadvisor是Google開源的一款用于展示和分析容器運行狀態(tài)的可視化工具。通過在主機上運行Cadvisor用戶可以輕松的獲取到當前主機上容器的運行統(tǒng)計信息,并以圖表的形式向用戶展示。
1.2、安裝docker-ce
[root@localhost ~]# iptables -F
[root@localhost ~]# setenforce 0
setenforce: SELinux is disabled
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost ~]# wget http://mirrors.aliyun.com/repo/Centos-7.repo
[root@localhost ~]# yum -y install yum-utils device-mapper-persistent-data lvm2
[root@localhost ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@localhost ~]# yum -y install docker-ce
[root@localhost ~]# systemctl start docker
[root@localhost ~]# systemctl enable docker
[root@localhost ~]# docker version
Client: Docker Engine - Community
Version: 24.0.5
API version: 1.43
Go version: go1.20.6
Git commit: ced0996
Built: Fri Jul 21 20:39:02 2023
OS/Arch: linux/amd64
Context: default
Server: Docker Engine - Community
Engine:
Version: 24.0.5
API version: 1.43 (minimum version 1.12)
Go version: go1.20.6
Git commit: a61e2b4
Built: Fri Jul 21 20:38:05 2023
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.21
GitCommit: 3dce8eb055cbb6872793272b4f20ed16117344f8
runc:
Version: 1.1.7
GitCommit: v1.1.7-0-g860f061
docker-init:
Version: 0.19.0
GitCommit: de40ad0
阿里云鏡像加速器
阿里云登錄 - 歡迎登錄阿里云,安全穩(wěn)定的云計算服務(wù)平臺歡迎登錄阿里云,全球領(lǐng)先的云計算及人工智能科技公司,阿里云為200多個國家和地區(qū)的企業(yè)、開發(fā)者和政府機構(gòu)提供云計算基礎(chǔ)服務(wù)及解決方案。阿里云云計算、安全、大數(shù)據(jù)、人工智能、企業(yè)應(yīng)用、物聯(lián)網(wǎng)等云計算服務(wù)。https://cr.console.aliyun.com/
[root@localhost ~]# cat << END > /etc/docker/daemon.json
{
"registry-mirrors":[ "https://nyakyfun.mirror.aliyuncs.com" ]
}
END
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker
?下載組件鏡像
[root@localhost ~]# docker pull tutum/influxdb
Using default tag: latest
latest: Pulling from tutum/influxdb
a3ed95caeb02: Pull complete
23efb549476f: Pull complete
aa2f8df21433: Pull complete
ef072d3c9b41: Pull complete
c9f371853f28: Pull complete
a248b0871c3c: Pull complete
749db6d368d0: Pull complete
db2492acfcc3: Pull complete
b7e7d2e12d53: Pull complete
4272a53eef10: Pull complete
9b2fefdb5321: Pull complete
Digest: sha256:5b7c5e318303ad059f3d1a73d084c12cb39ae4f35f7391b79b0ff2c0ba45304b
Status: Downloaded newer image for tutum/influxdb:latest
docker.io/tutum/influxdb:latest
[root@localhost ~]# docker pull google/cadvisor
Using default tag: latest
latest: Pulling from google/cadvisor
ff3a5c916c92: Pull complete
44a45bb65cdf: Pull complete
0bbe1a2fe2a6: Pull complete
Digest: sha256:815386ebbe9a3490f38785ab11bda34ec8dacf4634af77b8912832d4f85dca04
Status: Downloaded newer image for google/cadvisor:latest
docker.io/google/cadvisor:latest
[root@localhost ~]# docker pull grafana/grafana
Using default tag: latest
latest: Pulling from grafana/grafana
97518928ae5f: Pull complete
5b58818b7f48: Pull complete
d9a64d9fd162: Pull complete
4e368e1b924c: Pull complete
867f7fdd92d9: Pull complete
387c55415012: Pull complete
07f94c8f51cd: Pull complete
ce8cf00ff6aa: Pull complete
e44858b5f948: Pull complete
4000fdbdd2a3: Pull complete
Digest: sha256:18d94ae734accd66bccf22daed7bdb20c6b99aa0f2c687eea3ce4275fe275062
Status: Downloaded newer image for grafana/grafana:latest
docker.io/grafana/grafana:latest
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
grafana/grafana latest 9b957e098315 20 months ago 275MB
google/cadvisor latest eb1210707573 4 years ago 69.6MB
tutum/influxdb latest c061e5808198 6 years ago 290MB
?創(chuàng)建自定義網(wǎng)絡(luò)
[root@localhost ~]# docker network create monitor
bfe09a56d338b3173da008204dac13e46873ab8c46601683bba6457178e7dbcc
[root@localhost ~]# docker network ls
NETWORK ID NAME DRIVER SCOPE
dbe5fb2353e8 bridge bridge local
fc4521838733 host host local
bfe09a56d338 monitor bridge local
4e2c57eec484 none null local
?
1.3、部署Cadvisor
被監(jiān)控主機上部署Cadvisor容器
[root@localhost ~]# docker run -d \
> --volume=/:/rootfs:ro \
> --volume=/var/run:/var/run:ro \
> --volume=/sys:/sys:ro \
> --volume=/var/lib/docker/:/var/lib/docker:ro \
> --volume=/dev/disk/:/dev/disk:ro \
> --publish=8080:8080 \
> --detach=true \
> --name=cadvisor \
> google/cadvisor:latest
39067a18d264733e884272d932cd1d2bf1ae279092729aca01cfc0f12fa2571d
1.4、訪問cAdvisor頁面
訪問http://192.168.2.118:8080?cAdvisor頁面可以看到收集到的數(shù)據(jù)
?
?
1.5、Prometheus產(chǎn)品簡介
????????Prometheus是一個最初在SoundCloud上構(gòu)建的開源系統(tǒng)監(jiān)視和警報工具包。自2012年成立以來,很多公司和組織都采用了Prometheus,該項目擁有非?;钴S的開發(fā)者和用戶社區(qū)。 它現(xiàn)在是一個獨立的開源項目,可以獨立于任何公司進行維護。 為了強調(diào)這一點,并闡明項目的治理結(jié)構(gòu),Prometheus于2016年加入Cloud Native Computing Foundation(云原生基金會),作為繼Kubernetes之后的第二個托管項目。
Prometheus的主要特征有:
- 多維度數(shù)據(jù)模型-由指標鍵值對標識的時間序列數(shù)據(jù)組成
- PromQL,一種靈活的查詢語言
- 不依賴分布式存儲; 單個服務(wù)器節(jié)點是自治的
- 以HTTP方式,通過pull模型拉取時間序列數(shù)據(jù)
- 支持通過中間網(wǎng)關(guān)推送時間序列數(shù)據(jù)
- 通過服務(wù)發(fā)現(xiàn)或者靜態(tài)配置,來發(fā)現(xiàn)目標服務(wù)對象
- 支持多種多樣的圖表和界面展示
1.6、部署Prometheus?
[root@localhost ~]# docker pull prom/prometheus
Using default tag: latest
latest: Pulling from prom/prometheus
3cb635b06aa2: Pull complete
34f699df6fe0: Pull complete
33d6c9635e0f: Pull complete
f2af7323bed8: Pull complete
c16675a6a294: Pull complete
827843f6afe6: Pull complete
3d272942eeaf: Pull complete
7e785cfa34da: Pull complete
05e324559e3b: Pull complete
170620261a59: Pull complete
ec35f5996032: Pull complete
5509173eb708: Pull complete
Digest: sha256:cb9817249c346d6cfadebe383ed3b3cd4c540f623db40c4ca00da2ada45259bb
Status: Downloaded newer image for prom/prometheus:latest
docker.io/prom/prometheus:latest
先準備配置
[root@localhost ~]# vim /tmp/prometheus.yml
# 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']
- job_name: 'docker' ##定義一個叫docker的組
static_configs:
- targets: ['192.168.2.118:8080'] ##填寫一個或多個cadvisor的主機地址用逗號隔開
運行容器
[root@localhost ~]# docker run -d \
--name=prometheus -p 9090:9090 \
-v /tmp/prometheus.yml:/etc/prometheus/prometheus.yml \
-v /etc/localtime:/etc/localtime \
prom/prometheus
402b019bb5fd489911f925ae717e87994e68ec7b836f37bc106de8f3c2801cbc
#如果起不來就重啟一下docker,再用docker restart $(docker ps -qa) 重啟所有容器
1.7、訪問prometheus頁面
http://192.168.2.118:9090
?
?
?
看到docker組狀態(tài)up為正常
查詢項是可以查到數(shù)據(jù)的
?1.8、部署Granfana
[root@localhost ~]# docker run -d \
> --name=grafana \
> -p 3000:3000 \
> grafana/grafana
42b131dbf96ac1b613c6b8ac305c94eb322b8cf6b320f48990ad059bba5ba0d6
1.9、配置Granfana
訪問http://192.168.2.118:3000默認賬戶admin 密碼 admin首次登陸需要修改密碼
?
?配置數(shù)據(jù)源
?
?
?
?
?
?導入模板
?
?選擇對應(yīng)的數(shù)據(jù)源,點擊導入,就可以看到被監(jiān)控主機的數(shù)據(jù)
?準備測試容器
[root@localhost ~]# docker run --name=nginx -d -p 80:80 nginx
d2000b50c5a035fde255c5f488fde43653733806a36167c4b73460a0c74d27f6
?
?文章來源:http://www.zghlxwxcb.cn/news/detail-634102.html
?到此Cadvisor +Prometheus+Grafana基本架構(gòu)部署完畢文章來源地址http://www.zghlxwxcb.cn/news/detail-634102.html
到了這里,關(guān)于構(gòu)建Docker容器監(jiān)控系統(tǒng)(Cadvisor +Prometheus+Grafana)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!