Cadvisor+prometheus+grafana

2023-03-10,,

部署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
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
13420a47d9bf google/cadvisor:latest "/usr/bin/cadvisor -…" 10 seconds ago Up 9 seconds 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp cadvisor

prometheus

特点:

有多维度的数据模型
有自己的查询语言:PromQL
不依赖分布式存储
支持通过中间网关推送时间序列数据
通过服务发现或静态配置,来发现目标服务对象
支持图标和界面展示

部署Prometheus

[root@localhost ~]# docker pull prom/Prometheus   //下载普罗米修斯
[root@localhost ~]# vim /tmp/prometheus.yml //创建静态普罗米修斯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.
# scrap_timeout is set to the global default (10s). # Alertmanager configuration
Alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093 #Load rules once andpreiodically 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 scrapedfrom 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.200.14:8080'] [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

页面访问端口9090

部署Granafa

[root@localhost ~]# docker run -d --name=granafa -p 3000:3000 grafana/grafana
65f2b78f0d30a27d38e12d728db66a60d9f44fc2ad2ab3ac3fd58c4cb7afd4f6
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
65f2b78f0d30 grafana/grafana "/run.sh" 9 seconds ago Up 8 seconds 0.0.0.0:3000->3000/tcp, :::3000->3000/tcp granafa
dd61dd779dae prom/prometheus "/bin/prometheus --c…" 8 minutes ago Up 4 minutes 0.0.0.0:9090->9090/tcp, :::9090->9090/tcp prometheus
13420a47d9bf google/cadvisor:latest "/usr/bin/cadvisor -…" 46 minutes ago Up 46 minutes 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp cadvisor

Cadvisor+prometheus+grafana的相关教程结束。

《Cadvisor+prometheus+grafana.doc》

下载本文的Word格式文档,以方便收藏与打印。