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中展示自定义的数据了

  • 相关阅读:
    空间统计笔记之三(度量地理分布工具集,Measuring Geographic Distributions)
    空间统计笔记之四(空间关系建模工具集,Modeling Spatial Relationships)
    黑苹果WiFi&蓝牙驱动
    Hackintosh问题集结
    macOS读写NTFS磁盘分区
    Windows10 无法打开此计算机上的组策略对象。你可能没有相应的权限
    电脑C盘容量扩容
    Windows配置定时休眠和唤醒
    macOS Windows添加静态路由
    macOS使用技巧
  • 原文地址:https://www.cnblogs.com/FsharpZack/p/13305755.html
Copyright © 2011-2022 走看看