IP1上以容器的方式运行织云服务,自监控方案采用Prometheus监控 IP1 ,监控host和织云服务容器两个层次的数据。
使用Prometheus官方Node Exporter收集host硬件和操作系统数据,使用Google的cAdvisor收集容器数据,并使用Grafana进行展示。
在IP2上运行Prometheus Server和Grafana,在host上运行Node Exporter和cAdvisor。
这里采用下载二进制文件安装运行在IP1的9100端口
按照 https://github.com/prometheus/node_exporter 文档步骤,没有遇到什么坑
这里使用docker方式安装运行在IP1的8080端口。https://github.com/google/cadvisor,
由于内网不能联网,通过在本地Windows上连接外网后,在Boot2Docker里面把对应的镜像拉到本地然后save成tar包,在上传到服务器上load后运行容器。
在Boot2Docker中:
docker pull google/cadvisor:latest docker images # 找到镜像id docker save 镜像id > ./cadvisor.tar
然后上传至对应的host中:
docker load < cadvisor.tar docker images # 找到镜像id docker tag 镜像id docker.oa.com/ashinchen/cadvisor:latest # run 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 --volume=/cgroup:/cgroup:ro --publish=8080:8080 -d --net=host --name=cadvisor --privileged=true docker.oa.com/ashinchen/cadvisor:latest
tlinux上报错Failed to start container manager: inotify_add_watch /sys/fs/cgroup/cpuacct,cpu: no such file or directory
,解决办法:
mount -o remount,rw '/sys/fs/cgroup' ln -s /sys/fs/cgroup/cpu,cpuacct /sys/fs/cgroup/cpuacct,cpu
这里采用下载二进制文件安装运行在IP2的9090端口,https://github.com/prometheus/prometheus,也没有遇到什么坑。在配置文件prometheus.yml中新增scrape_configs:
- job_name: 'prometheus' # metrics_path defaults to '/metrics' # scheme defaults to 'http'. static_configs: - targets: ['localhost:9090'] - job_name: 'IP1' static_configs: - targets: ['IP1:9100', 'IP1:8080']
采用二进制包下载安装 http://docs.grafana.org/installation/rpm/,安装完成后启动服务
service grafana-server start
默认是3000端口,账号密码为admin:admin,没有遇到什么坑。
第一次登录grafana后会引导配置数据源,点击add data source,设置name,Type选Prometheus,URL默认是prometheus server地址其他保持默认,点击保存。
在Grafana官网有很多dashboard,可以下载这些现成的import到Grafana就可以直接使用。访问https://grafana.com/dashboards?dataSource=prometheus&search=docker 可以查到很多用于监控Docker的dashboard。
下载其JSON,在Grafana的/dashboard/import页面上传,然后选择刚才新建的数据源后点击Import就能看到曲线了,可以按自己需求重新编辑查询条件。
下载alertmanager二进制文件,修改yml配置中global的邮件服务器配置和receivers后,在IP2运行
./alertmanager --config.file=simple.yml
邮件服务器不支持tls,可以在receivers的to下加上require_tls: false
新建一个rules配置222_rules.yml:
groups: - name: 222 rules: - alert: zy_monitor_mem expr: container_memory_usage_bytes{name="zy_monitor"} > 1000000000 for: 10m annotations: summary: High memory of zy_monitor
修改prometheus配置alerting和rule_files,重启
alerting: alertmanagers: - static_configs: - targets: - localhost:9093 rule_files: - "222_rules.yml"
网友220.*.*.110[北京]2021-04-19 11:28
网友77.*.*.164[捷克]2021-04-19 11:21
网友116.*.*.34[火星]2021-04-19 11:06
网友66.*.*.81[华盛顿州]2021-04-19 11:02
发表评论
亲~ 评论内容是必须的哟! o(∩_∩)o
昵称
邮箱
主页
评论