zoukankan      html  css  js  c++  java
  • 向node_exporter中添加新监控信息

    在使用promethues进行服务器指标监控的时候,有时候需要添加一下自己的监控信息, 下面是本人的做法,记录一下:

    Steps:

    1. 被监控服务器上启动 node-exporter
      •   如: docker run -d --restart=always --net="host" --pid="host" --name=node-exporter_qa -v "/:/host:ro,rslave" quay.io/prometheus/node-exporter --path.rootfs=/host --collector.textfile.directory="/run/prometheus"
      • 注意上面的/run/prometheus目录,我们只需要向此目录中添加 *.prom 文件即可实现添加自定义监控数据
    2. 自定义一个自己的Docker 镜像,将需要的监控指标收集起来,实现如下:
      •   生成收集脚本需要的环境
    FROM centos:latest
    USER root
    ADD ./get_frame.sh /get_frame.sh
    RUN yum -y install wget
    RUN wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    
    RUN rpm -ivh epel-release-latest-7.noarch.rpm
    RUN yum repolist
    RUN yum -y install jq
    
    RUN mkdir -p /run/prometheus/
    RUN chmod 777 /get_frame.sh
    ENTRYPOINT /get_frame.sh
      •  编写收集脚本 
    #!/bin/bash
    
    # Adjust as needed.
    TEXTFILE_COLLECTOR_DIR=/run/prometheus/
    while true;do
    # Your code goes here.
    info_a=`curl -s -X GET http://localhost/xxxxxx`
    info_b=`curl -s -X GET http://localhost/xxxxxx`
    cat << EOF > "$TEXTFILE_COLLECTOR_DIR/frame.prom.$$"
    $info_a
    $info_b
    EOF
    
    # Rename the temporary file atomically.
    # This avoids the node exporter seeing half a file.
    mv "$TEXTFILE_COLLECTOR_DIR/frame.prom.$$" 
      "$TEXTFILE_COLLECTOR_DIR/frame.prom"
    sleep 5
    done
      • 注意收集脚本生成的文本消息格式需要满足一定格式, 如下述示例:

          indicator_a{label_a_a="value_a_a",label_a_b="value_a_b"} 1182

          indicator_b{label_b_a="value_b_a",label_b_b="value_b_b"} 10

      • 注意最后的值必须为 数值,不能是字符串

      3. 接下来就可以在Grafana中展示自定义的数据了

  • 相关阅读:
    RT-Thread can
    scons自动化构建工具
    Android 数据库 SQLiteOpenHelper
    请确保二进制储存在指定的路径中,或者调试他以检查该二进制或相关的DLL文件
    攻防世界misc新手区前三题
    基于session对象实现简单的购物车应用
    MS Excel中的内部日期处理方法
    如何实现对指定日期进行增减日期操作结果的输出
    2020前端大厂最新面试题,这一波我是用“身子换来的”
    字节、拼多多前端面经!
  • 原文地址:https://www.cnblogs.com/FsharpZack/p/13305755.html
Copyright © 2011-2022 走看看