首页 > 编程知识 正文

docker普罗米修斯,视频监控云服务

时间:2023-05-05 03:36:24 阅读:195139 作者:4832

环境
192.168.254.127 (监控服务器)
192.168.254.128 (被监控机器)

首先在监控服务器安装:
1.安装Node Exporter 来收集硬件信息
所有节点运行以下命令安装Node Exporter 容器
docker run -d -p 9100:9100
-v "/proc:/host/proc"
-v "/sys:/host/sys"
-v "/:/rootfs"
-v "/etc/localtime:/etc/localtime"
--net=host
prom/node-exporter
--path.procfs /host/proc
--path.sysfs /host/sys
--collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)"

注意,这里我们使用了 --net=host,这样 Prometheus Server 可以直接与 Node Exporter 通信
2.安装cAdvisor 来收集容器信息 所有节点运行以下命令来安装cAdvisor
docker run
--volume=/:/rootfs:ro
--volume=/var/run:/var/run:rw
--volume=/sys:/sys:ro
--volume=/var/lib/docker/:/var/lib/docker:ro
--publish=8080:8080
--detach=true
--name=cadvisor
--net=host
-v "/etc/localtime:/etc/localtime"
google/cadvisor:latest

注意,这里我们使用了 --net=host,这样 Prometheus Server 可以直接与 cAdvisor 通信。
在Dockermachine服务器上安装普罗米修斯服务
安装之前需要将普罗米修斯的启动文件创建好, 在/root目录下创建prometheus.yml文件文件内容如下:主要修改highlight部分

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','localhost:8080','localhost:9100','192.168.254.128:8080','192.168.254.128:9100']
指定从哪些 exporter 抓取数据。这里指定了两台 host 上的 Node Exporter 和 cAdviso
另外 localhost:9090 就是 Prometheus Server 自己,可见 Prometheus 本身也会收集自己的监控数据。同样地,我们也可以通

3.运行以下命令安装普罗米修斯服务
docker run -d -p 9090:9090
-v /root/prometheus.yml:/etc/prometheus/prometheus.yml
-v "/etc/localtime:/etc/localtime"
--name prometheus
--net=host
prom/prometheus

注意,这里我们使用了 --net=host,这样 Prometheus Server 可以直接与 Exporter 和 Grafana 通信。

prometheus.yml 是 Prometheus Server 的配置文件
安装完毕后浏览器中打开http://192.168.254.127:9090 点击菜单 status ----> target,状态显示为up,说明普罗米修斯服务能够正常获取监控数据,点击endpoint可以查看收集的详细信息由于没有安装UI 服务器Granfana

4.在DockerMachine上运行Grafana
docker run -d -i -p 3000:3000
-v "/etc/localtime:/etc/localtime"
-e "GF_SERVER_ROOT_URL=http://grafana.server.name"
-e "GF_SECURITY_ADMIN_PASSWORD=admin8888"
--net=host
grafana/grafana

5.现在查看各个Host上都运行了那些容器 Dockermachine: 共4个 Grafana,Prometheus, cadvisor, node-exporter

Grafana启动后,在浏览器中打开http://192.168.254.127:3000 登录界面,登录用admin 密码为刚创建Grafana时的admin8888

6.添加DataSource
添加普罗米修斯服务器,重点看框部分,其它默认即可

点击Save & Test 如果一切顺利该DataSource可以正常工作了,也就是说Grafana可以正常跟Prometheus正常通信了,name怎么展示数据呢,答案是通过dashboard.
7.自己手工创建dashboard有点困难,可以借助开元的力量访问https://grafana.com/dashboards?dataSource=prometheus&search=docker 将会看到很多用于监控 Docker 的 Dashboard。监控模板地址(多种监控模板根据自己需求下载不同的模板)

有些dashboard可以下载后直接导入,而有些需要修改后再导入,需要看dashboard的overview

例如导入Docker and system monitoring dashboard

8.最后监控页面展示

最后说明:
监控服务器 需要安装4个服务
Prometheus Server(普罗米修斯监控主服务器 )
Node Exporter (收集Host硬件和操作系统信息)
cAdvisor (负责收集Host上运行的容器信息)
Grafana (展示普罗米修斯监控界面)

被监控的只有安装2个
Node Exporter (收集Host硬件和操作系统信息)
cAdvisor (负责收集Host上运行的容器信息)

转载于:https://blog.51cto.com/10158955/2165301

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。