我想使用 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”:{“已连接”:假,“已启用”:假,“模式”:“CABLE”,“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响应时间=7.333277032 1551105770000000000
我希望字符串“connected”不是 1551105770000000000
怎样才能得到预期的结果
谢谢你的帮助
最佳答案
在带有 json 插件的 block 开头的 telegraf.conf 文件中,它说:
“注意此插件仅读取数值测量值,字符串和 bool 值将被忽略。”
关于json - 使用 Telegraf 解析 JSON 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54868741/