• 3.Telegraf自定义脚本模块


    官网:https://github.com/influxdata/telegraf/tree/master/plugins/inputs/exec

    通过exec自定义模块可以很方便的将自定义脚本输出的内容同步到influxdb。

    telegraf.conf 开启自定义插件:

    [[inputs.exec]]
      ## Commands array
      commands = [
        "/tmp/test.sh",
        "/usr/bin/mycollector --foo=bar",
        "/tmp/collect_*.sh"
      ]
    
      ## Timeout for each command to complete.
      timeout = "5s"
    
      ## measurement name suffix (for separating different commands)
      name_suffix = "_mycollector"
    
      ## Data format to consume.
      ## Each data format has its own unique set of configuration options, read
      ## more about them here:
      ## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md
      data_format = "influx"
    

    脚本输出格式如下:

    #!/bin/sh
    echo 'example,tag1=a,tag2=b i=42i,j=43i,k=44i'
    

    示例:

    [root@szpbs-nonerp-uat-mysql02 telegraf]# cat telegraf.d/collect_ip.conf 
    [[inputs.exec]]
    ##Commands array
    commands = ["bash /etc/telegraf/exec/collect_ip.sh",]
    timeout='5s'
    ##measurements的后缀
    name_suffix="_exec"
    data_format="influx"
    
    #!/bin/bash
    addr=$(/usr/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep 10|grep -v inet6|awk '{print $2}'|tr -d "addr:"|head -1)
    host=$(hostname)
    echo 'systeminfo,addr='$addr' hostname="'$host'",area="深圳鹏博士",item="AI测试2",env="moni"'(注意这里$addr和$host的区别)
    echo 'measurement,tag1=a,tag2=b  field1="str1",field2=1231'(经测试,tag字段可以不加双引号输出,filed字段,值非数字需要双引号)
    
  • 相关阅读:
    关于guava实现线程池
    结构化方法与面向对象方法的比较
    敏捷开发与传统开发方式的比较
    C# 事件的使用方法
    C# 泛型反射的调用
    RPC 知识科普一下
    C#枚举(Enum)小结
    C#图片添加文字水印
    C#索引器
    C#隐式转换与显示转换
  • 原文地址:https://www.cnblogs.com/unsigned1995/p/14216744.html
Copyright © 2020-2023  润新知