docker部署Prometheus+Grafana
一、安装Prometheus
# 创建目录
mkdir -p /data/prometheus/prometheus-data
cd /data/prometheus/
# 拉取prometheus镜像
docker pull prom/prometheus
# 初次启动cp配置文件
docker run -d --name prometheus prom/prometheus
# 拷贝配置文件到 /data/prometheus/目录
docker cp prometheus:/etc/prometheus/prometheus.yml .
# 配置权限
chmod -R 775 /data/prometheus
# 启动服务
docker run --name prometheus -p 9090:9090 -v /data/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml -v /data/prometheus/prometheus-data:/prometheus -d prom/prometheus
二、配置node-exporter监控主机、google/cadvisor监控docker
1、主机监控node-exporter
docker run -d -p 9100:9100 -v /proc:/host/proc -v /sys:/host/sys -v /:/rootfs prom/node-exporter --path.procfs /host/proc --path.sysfs /host/sys --collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)"
2、docker监控
docker run -v /:/rootfs:ro -v /var/run:/var/run/:rw -v /sys:/sys:ro -v /var/lib/docker:/var/lib/docker:ro -p 8080:8080 --detach=true --name=cadvisor google/cadvisor
3、配置prometheus监控(就是第一步配置的服务)
# 修改配置文件
cd /data/prometheus
vim 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:
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
scrape_configs:
- job_name: "prometheus"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["localhost:9090"]
- job_name: '被监控主机主机名'
static_configs:
- targets: ["主机IP:8080","主机IP:9100"]
# 配置文件保存后重启prometheus容器重载配置
docker restart prometheus
三、安装Grafana
# 拉取镜像
docker pull grafana/grafana
# 启动grafana
docker run --name grafana -d -p 3000:3000 grafana/grafana
访问地址:主机IP地址加3000端口
默认用户名密码:admin/admin
输入prometheus访问地址端口连接,然后点击Save & test 按钮
导入主机监控模板,官方有很多监控模板,我这里选择了ID为8919的模板
可以自定义名称,选择prometheus,点击导入
效果图
导入docker监控模板,导入方式相同,模板ID:11600
模板效果图
正文到此结束
评论
登录后才能发表评论 登录/注册
0评论