Docker - Prometheus(普罗米修斯)
简介
Prometheus是一个开源的完整监控解决方案,其对传统监控系统的测试和告警模型进行了彻底的颠覆,形成了基于中央化的规则计算、统一分析和告警的新模型。
组件名称 | 作用说明 |
---|---|
PrometheusServer | 普罗米修斯的主服务器 |
NodeExporter | 负责收集host硬件信息和操作系统信息 |
CAdvisor | 负责收集host上运行的容器信息 |
Grafana | 负责展示普罗米修斯监控界面 |
一、拉取镜像
docker pull prom/prometheus # Prometheus docker pull grafana/grafana # Grafana docker pull prom/node-exporter # NodeExporter docker pull google/cadvisor # Cadvisor
二、执行安装
1. NodeExporter
docker run -d \
--name=nodeexporter \
--restart always \
-p 9002:9100 \
-v /proc:/host/proc:ro \
-v /sys:/host/sys:ro \
-v /:/rootfs:ro \
prom/node-exporter --path.procfs=/host/proc --path.sysfs=/host/sys --path.rootfs=/rootfs \
--collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($$|/)"
2. CAdvisor
docker run -d \
--name=cadvisor \
--restart always \
-p 9003:8080 \
-v /:/rootfs:ro \
-v /var/run:/var/run/:rw \
-v /sys:/sys:ro \
-v /var/lib/docker:/var/lib/docker:ro \
--detach=true \
google/cadvisor
3. PrometheusServer
Ⅰ. 安装前准备
# 创建临时容器,导出配置文件
docker create --name prometheus_temp prom/prometheus \
&& docker cp prometheus_temp:/etc/prometheus/prometheus.yml /data/monitor/prometheus/prometheus.yml \
&& docker rm prometheus_temp
调整刚copy下来的配置文件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: 'consul'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
consul_sd_configs:
- server: '39.105.118.243:8500' # 配置Consul自动发现
relabel_configs:
- source_labels: [__meta_consul_service_port]
regex: ^8300$ # 移除Consul本身
action: drop
- job_name: 'centos'
static_configs:
- targets: ['39.105.118.243:9002']
- job_name: 'cadvisor'
static_configs:
- targets: ['39.105.118.243:9003']
Ⅱ. 调整完配置文件后,运行容器
docker run -d \
--name prometheus \
--restart always \
-p 9004:9090 \ # 映射端口
-v /data/monitor/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \ # 映射刚刚调整的配置文件
prom/prometheus
访问IP:映射端口
,显示如下表示已安装成功
4. Gragana
docker run -d \
--restart always \
--name grafana \
-p 9005:3000 \
-v /data/monitor/grafana:/var/lib/grafana \ # 映射数据文件
-e "GF_SECURITY_ADMIN_PASSWORD=7m4ZajCBxQy5ldzD" \ # 设置访问密码,默认账号:admin
grafana/grafana
访问:IP:映射端口
,显示如下表示已安装完成
三、模板配置
1.添加数据源,填写你的PrometheusServer
服务地址,如:IP:9004
2.添加或导入监控模板dashboard
,推荐我常用的模板ID:8919、10619
四、预警设置
docker cp grafana:/etc/grafana/grafana.ini /data/monitor/grafana/grafana.ini # 将Grafana配置文件copy到磁盘
调整配置文件
# 替换回原文件,可以移除刚新建的Grafana容器重新生成
docker run -d \
--restart always \
--name grafana \
-p 9005:3000 \
-v /data/monitor/grafana:/var/lib/grafana \ # 映射数据文件
-v /data/monitor/grafana/grafana.ini:/etc/grafana/grafana.ini \ # 映射配置文件
-e "GF_SECURITY_ADMIN_PASSWORD=7m4ZajCBxQy5ldzD" \ # 设置访问密码
grafana/grafana
进入需要预警的Panel点击Edit编辑
配置预警阀值
本文链接:https://blog.renzicu.com/2021/microservices/prometheus/index.html
版权声明:本博客所有文章除特别声明外,均采用 CC BY 4.0 许可协议。转载请注明出处!
版权声明:本博客所有文章除特别声明外,均采用 CC BY 4.0 许可协议。转载请注明出处!
THE END
二维码
打赏
文章目录
关闭
共有 0 条评论