zoukankan      html  css  js  c++  java
  • 监控生产线上服务器的docker容器及主机

    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.测试成功

  • 相关阅读:
    【POJ1961】period
    主席树入门
    noip模拟【tea】
    noip模拟【service】
    noip模拟【noname】
    clearfix清除浮动
    九大内置对象
    2017/10/10 jar包错误
    mybatis案例源码详解
    自动类型转换
  • 原文地址:https://www.cnblogs.com/mushou/p/10063787.html
Copyright © 2011-2022 走看看