[英]Problems parsing JSON with Telegraf
我想使用 Telegraf 從 swagger API 收集數據
這是我的 Telegraf.conf 中的 DS 定義
[[inputs.httpjson]]
## NOTE This plugin only reads numerical measurements, strings and booleans
## will be ignored.
## Name for the service being polled. Will be appended to the name of the
## measurement e.g. "httpjson_webserver_stats".
##
## Deprecated (1.3.0): Use name_override, name_suffix, name_prefix instead.
name = "ultimaker_status"
## URL of each server in the service's cluster
servers = [
"http://192.168.5.15/api/v1/printer/network",
]
## Set response_timeout (default 5 seconds)
response_timeout = "15s"
## HTTP method to use: GET or POST (case-sensitive)
method = "GET"
## Tags to extract from top-level of JSON server response.
tag_keys = [
"ethernet:connected"
]
## Optional TLS Config
# tls_ca = "/etc/telegraf/ca.pem"
# tls_cert = "/etc/telegraf/cert.pem"
# tls_key = "/etc/telegraf/key.pem"
## Use TLS but skip chain & host verification
# insecure_skip_verify = false
## HTTP Request Parameters (all values must be strings). For "GET" requests, data
## will be included in the query. For "POST" requests, data will be included
## in the request body as "x-www-form-urlencoded".
# [inputs.httpjson.parameters]
# event_type = "cpu_spike"
# threshold = "0.75"
## HTTP Request Headers (all values must be strings).
# [inputs.httpjson.headers]
# X-Auth-Token = "my-xauth-token"
# apiVersion = "v1"
對http://192.168.5.15/api/v1/printer/network的 HTTP 請求返回以下字符串
{“以太網”:{“連接”:真,“啟用”:真},“wifi”:{“連接”:假,“啟用”:假,“模式”:“電纜”,“ssid”:“UM -NO-HOTSPOT-NAME-SET"}, "wifi_networks": []}
Telegraf --test 返回以下內容
httpjson_ultimaker_status,host=dmon-virtual-machine,server= http://192.168.5.15/api/v1/printer/network response_time=7.333277032 1551105770000000000
我希望字符串“連接”不是 1551105770000000000
我怎樣才能得到預期的結果
謝謝你的幫助
在帶有 json 插件的塊開頭的 telegraf.conf 文件中,它說:
“注意此插件僅讀取數值測量值,字符串和布爾值將被忽略。”
除非在 tag_key 或 json_string_fields 選項中指定,否則忽略 JSON 字符串。
也許你可以嘗試,比如
tag_keys = ["ethernet_connected"] json_string_fields = ["ethernet_connected"]
您可以在https://github.com/influxdata/telegraf/tree/master/plugins/parsers/json找到更多信息
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.