我有没有办法使用telegraf从标头/身体中提取请求信息

发布于 2025-02-07 01:42:30 字数 311 浏览 3 评论 0原文

因此,我将Telegraf安装在我们的EC2实例之一上。在此实例中,我们有一个安装了Spring Boot应用程序,并将其转发给它们。

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

然后将将此信息推向infuxdb。

这个想法是我们将提取此信息并使用Grafana显示,以便我们可以看到来自哪里的请求。

我知道有一些插件,例如HTTP_LISTENER,但我无法从Readme中分辨出它是否可以工作,或者是否有更好的方法可以使此工作?

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

So I have telegraf installed on one of our ec2 instances. And on the instance we have a spring boot application installed servicing POST requests and forwarding them on.

I was wondering if it is possible to extract information from requests coming into this service such as header information or key value pairs from a json body and then forward this information onto telegraf?

Telegraf would be then push this information to influxdb.

The idea is that we will extract this information and display using grafana so we can visualise how many requests are coming from where.

I know there are some plugins like http_listener but I can't tell from the readme if this could possibly work or if there is a better way to get this working?

Thanks for any information you can provide in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

意中人 2025-02-14 01:42:30

您可以尝试使用此 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

http json响应

{
   "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播放以更新配置。愉快的编码。

You could try work with this sample. The sample code could be:

[[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

An excerpt of original HTTP JSON response is:

{
   "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
}

Above Telegraf script will turn the JSON into following line protocol:

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

You could play with the sample JSON with Telegraf to update your configurations. Happy coding.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文