【问题标题】:Is there a way for me to extract request information from headers/body using telegraf有没有办法让我使用 telegraf 从标头/正文中提取请求信息
【发布时间】:2022-12-11 02:04:01
【问题描述】:

所以我在我们的一个 ec2 实例上安装了 telegraf。在实例上,我们安装了一个 spring boot 应用程序来服务 POST 请求并转发它们。

我想知道是否可以从进入此服务的请求中提取信息,例如来自 json 主体的标头信息或键值对,然后将此信息转发到 telegraf?

然后 Telegraf 会将此信息推送到 influxdb。

我们的想法是,我们将提取这些信息并使用 grafana 进行显示,这样我们就可以直观地看到有多少请求来自哪里。

我知道有一些像 http_listener 这样的插件,但我无法从自述文件中判断这是否可行,或者是否有更好的方法来实现它?

感谢您提前提供的任何信息!

【问题讨论】:

    标签: rest monitoring influxdb telegraf


    【解决方案1】:

    您可以尝试使用这个sample。示例代码可以是:

    [[inputs.http]]
    # URL for your data in JSON format
    urls = ["https://yourURL/sample.json"]
    
    # Overwrite measurement name from default `http` to `someOtherMeasurement`
    name_override = "someOtherMeasurement"
    
    # Data from HTTP in JSON format
    data_format = "json_v2"
    
          # Add a subtable to use the `json_v2` parser
          [[inputs.http.json_v2]]
    
              # Add an object subtable for to parse a JSON object
              [[inputs.http.json_v2.object]]
    
                  # Parse data in `data.stations` path only
                  path = "data.stations"
    
                  #Set station metadata as tags
                  tags = ["yourTags"]
    
                  # Latest station information reported at `last_reported`
                  timestamp_key = "theTimeStamp"
    
                  # Time is reported in unix timestamp format
                  timestamp_format = "unix"
                  
                  # all other json key-value pairs will be turned into fields
    

    original HTTP JSON response 的摘录是:

    {
       "data":{
          "stations":[
             {
                "last_reported":1655171050,
                "is_renting":1,
                "num_bikes_available":21,
                "is_installed":1,
                "legacy_id":"72",
                "station_status":"active",
                "num_ebikes_available":2,
                "is_returning":1,
                "eightd_has_available_keys":false,
                "num_docks_disabled":0,
                "station_id":"72",
                "num_bikes_disabled":1,
                "num_docks_available":32
             },
             "..."
          ]
       },
       "last_updated":1655171085,
       "ttl":5
    }
    

    以上 Telegraf 脚本会将 JSON 转换为以下行协议:

    someOtherMeasurement,station_id=72 eightd_has_available_keys=false,is_installed=1,is_renting=1,is_returning=1,legacy_id="72",num_bikes_available=21,num_bikes_disabled=1,num_docks_available=32,num_docks_disabled=1,num_ebikes_available=2,station_status="active" 1655171050000000000
    

    您可以使用带有 Telegraf 的示例 JSON 来更新您的配置。快乐的编码。

    【讨论】:

      猜你喜欢
      • 2010-11-01
      • 1970-01-01
      • 2014-09-13
      • 2020-09-20
      • 1970-01-01
      • 2019-12-06
      • 2021-10-31
      • 1970-01-01
      • 2022-07-18
      相关资源
      最近更新 更多