[英]Is there a way for me to extract request information from headers/body using telegraf
所以我在我們的一個 ec2 實例上安裝了 telegraf。 在實例上,我們安裝了一個 Spring Boot 應用程序,為 POST 請求提供服務並轉發它們。
我想知道是否可以從進入此服務的請求中提取信息,例如來自 json 主體的標頭信息或鍵值對,然后將此信息轉發到電報?
然后 Telegraf 會將這些信息推送到 influxdb。
我們的想法是我們將提取這些信息並使用 grafana 顯示,以便我們可以看到有多少請求來自哪里。
我知道有一些像 http_listener 這樣的插件,但是我無法從自述文件中判斷這是否可行,或者是否有更好的方法可以使其正常工作?
感謝您提前提供的任何信息!
您可以嘗試使用此 示例。 示例代碼可以是:
[[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 來更新您的配置。 快樂編碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.