# 实验环境: 阿里云 ECS 主机 https://www.aliyun.com/product/ecs (两台),CentOS 7.4
一, Prometheus 简介
1.1 关于 Prometheus
Prometheus 是由 SoundCloud 开发的开源监控系统的开源版本. 2016 年, 由 Google 发起的云原生基金会 CNCF (Cloud Native Computing Foundation) 将其纳入为其第二大开源项目(第一大开源项目是 Kubernetes).Prometheus 提供了一整套的包括监控数据搜集, 存储, 处理, 可视化和告警的完整解决方案.
Prometheus 官网地址: https://prometheus.io/
Prometheus GitHub: https://github.com/prometheus/prometheus/
1.2 Prometheus 架构
Prometheus 在其官方 GitHub 上贴出的其架构图如下:
为了更容易理解这个架构, 这里我们采用园友 Cloud Man https://yq.aliyun.com/articles/311400 (他也是本文参考资料《每天 5 分钟玩转 Docker》作者)总结的下图, 它去掉了一些部分, 只保留了最重要的组件, 可以帮助我们避免注意力分散.
从上图看来, 我们着重需要关注以下几个核心组件:
(1)Prometheus Server: 负责从 Exporter 中拉取和存储监控数据, 并提供一套查询语言 (PromQL) 供用户使用.
(2)Exporter: 负责收集目标对象 (如 Host 或 Container) 的性能数据, 并通过 HTTP 接口供 Prometheus Server 获取.
(3)可视化组件 Grafana: 获取 Prometheus Server 提供的监控数据并通过 web UI 的方式完美展现数据.
(4)AlertManager: 负责根据告警规则和预定义的告警方式发出例如 Email,Webhook 之类的告警.
1.3 Prometheus 数据模型
Prometheus 中存储的数据为时间序列, 是由 metric 的名字和一系列的标签 (键值对) 唯一标识的, 不同的标签则代表不同的时间序列.
metric 名字: 该名字应该具有语义, 一般用于表示 metric 的功能, 例如: http_requests_total, 表示 http 请求的总数. 其中, metric 名字由 ASCII 字符, 数字, 下划线, 以及冒号组成, 且必须满足正则表达式 [a-zA-Z_:][a-zA-Z0-9_:]*.
- 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)($|/)"
- docker run \
- --volume=/:/rootfs:ro \
- --volume=/var/run:/var/run:rw \
- --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
- docker run -d -p 9090:9090 \
- -v /edc/prometheus/prometheus.YAML:/etc/prometheus/prometheus.YAML \
- --name prometheus \
- prom/prometheus
- global:
- scrape_interval: 15s
- evaluation_interval: 15s
- external_labels:
- monitor: 'edc-lab-monitor'
- alerting:
- alertmanagers:
- - static_configs:
- - targets:
- # - alertmanager:9093
- rule_files:
- # - "first.rules"
- # - "second.rules"
- scrape_configs:
- - job_name: 'prometheus'
- static_configs:
- - targets: ['47.102.140.100:9090']
- - job_name: 'host'
- static_configs:
- - targets: ['47.102.140.100:9100','47.102.140.101:9100']
- - job_name: 'container'
- static_configs:
- - targets: ['47.102.140.100:8080','47.102.140.101:8080']
- docker run -d -i -p 3000:3000 \
- -e "GF_SERVER_ROOT_URL=http://grafana.server.name" \
- -e "GF_SECURITY_ADMIN_PASSWORD=secret" \
- grafana/grafana
来源: https://www.cnblogs.com/edisonchou/p/docker_monitor_introduction_part3.html