当前位置: 移动技术网 > 科技>操作系统>Linux > 监控生产线上服务器的docker容器及主机

监控生产线上服务器的docker容器及主机

2018年12月04日  | 移动技术网科技  | 我要评论

三雄极光中签号,姚劲波的老婆,上海瑜伽馆

1. 部署cadvisor容器,用来收集host上的容器信息,该容器部署在需要收集容器信息的每一个主机上部署;

docker run -v  /:/rootfs:ro -v /var/run:/var/run:rw -v /sys:/sys:ro -v /var/lib/docker:/var/lib/docker:ro -v /dev/disk:/dev/disk:ro -p 8080:8080 --detach=true --name cadvisor google/cadvisor

2.部署grafana容器,用于将收集的主机容器数据显示到浏览器

docker run -d -p 3000:3000 --name grafana  --net=host grafana/grafana

3.部署prometheus server ,选定一台服务器

docker run -d -p 9090:9090 -v /root/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml -v /root/prometheus/alert.rules:/etc/prometheus/alert.rules  -v /root/prometheus/conf.d:/etc/prometheus/conf.d  --name prometheus  --net=host  prom/prometheus

更改static_configs:

4.部署node-exporter

docker run -d -p 9100:9100 -v /proc:/host/proc -v /sys:/host/sys  -v /:/rootfs  --name node-exporter --net=host prom/node-exporter --path.procfs /host/proc --path.sysfs /host/sys --collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)"

5.部署告警(钉钉告警)

打开 prometheus.yml文件,配置规则

rule_files:

  - "alert.rules"

创建alert.rules 文件

在文件中定义了两个告警规则

-    alert: instancedown   如果有实例down了,alert 的状态会由 ok变为pending,达到5分,触发告警

-    alert: apihighrequestlatency

本例prometheus为容器应用,重启容器,也就是重新加载prometheus.yml文件和alert.rules文件

docker run -d -p 9090:9090 -v /root/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml -v /root/prometheus/alert.rules:/etc/prometheus/alert.rules  --name prometheus  --net=host  prom/prometheus

6.部署alertmanager告警管理程序

docker run -d -p 9093:9093 --name alertmanager -v /root/alertmanager/alertmanager.yml:/etc/alertmanager/alertmanager.yml prom/alertmanager

使用9093端口工作

更改prometheus.yml文件,加入

alerting:

  alertmanagers:

  - scheme: http

    static_configs:

    - targets:

      - "ip:9093"

主要是发生了 alert ,将报警信息发到ip:9093这个服务器的9093端口上

配置alertmanager.yml配置文件

receivers:

- name: webhook

  webhook_configs:

  - url: http://ip:8060/dingtalk/ops_dingding/send

send_resolved: true

其中url: http://localhost:8060/dingtalk/ops_dingding/send为安装的prometheus-webhook-dingtalk.git  发生了 alert  发给http://localhost:8060

告警信息加入钉钉

在钉钉中加入机器人,通讯录-我的群组-软件研发-群机器人-自定义-添加-机器人名字/添加到群组,会生成一个url地址,将该地址url: https://oapi.dingtalk.com/robot/send?access_token=a7b646af2ff248da9a3fdf7e236438e641a11853fcb5c8c20f12037591c04e26复制

将钉钉接入 prometheus alertmanager webhook

7.安装 alertmanager webhook    

mkdir -p /usr/lib/golang/src/github.com/timonwong/

cd  /usr/lib/golang/src/github.com/timonwong/

git clone https://github.com/timonwong/prometheus-webhook-dingtalk.git

cd prometheus-webhook-dingtalk

make(出错不要管他)

会生成 prommetheus-webhook-dingtalk执行程序

执行nohup ./prometheus-webhook-dingtalk --ding.profile="ops_dingding= https://oapi.dingtalk.com/robot/send?access_token=fd0ff6f99a4253279262f924e04a40b8e88f5aa7fefa8360c7a568e355e1ddbb"   2>&1 >dingding.log &

--ding.profile 可以在命令行中指定多次

该处的 https地址为在钉钉里加入机器人时产生的url地址

8.测试成功

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网