1

我有一个下面格式的 json 响应,我试图通过 Telegraf 的 input.http 插件解析它。

https://docs.influxdata.com/influxdb/v1.7/tools/api/#examples-2

{
    "data": {
        "results": [
            {
                "series": [
                    {
                        "columns": [
                            "time",
                            "tag_1",
                            "tag_2",
                            "tag_3",
                            "tag_4",
                            "tag_5",
                            "field_1",
                            "field_2",
                            "field_3",
                            "tag_6",
                            "tag_7",
                            "field_4",
                            "tag_8",
                            "field_5",
                            "tag_9",
                            "tag_10"
                        ],
                        "name": "measurement_name",
                        "values": [
                            [
                                1593068400,
                                "01",
                                "01",
                                "0072",
                                "07",
                                "PLACEHOLDER",
                                "PLACEHOLDER",
                                0,
                                0,
                                "0072-01-01-07",
                                "PLACEHOLDER",
                                0,
                                "AB",
                                3,
                                "PLACEHOLDER",
                                "2.2"
                            ],
                            [
                                1593068400,
                                "01",
                                "01",
                                "0072",
                                "09",
                                "PLACEHOLDER",
                                "PLACEHOLDER",
                                0,
                                0,
                                "0072-01-01-09",
                                "PLACEHOLDER",
                                0,
                                "BC",
                                4,
                                "PLACEHOLDER",
                                "2.2"
                            ],
                            [
                                1593068400,
                                "01",
                                "01",
                                "0072",
                                "10",
                                "PLACEHOLDER",
                                "PLACEHOLDER",
                                0,
                                0,
                                "0072-01-01-10",
                                "PLACEHOLDER",
                                0,
                                "AB",
                                4,
                                "PLACEHOLDER",
                                "2.2"
                            ]
                    ]
                }
            ],
            "statement_id": 0
        }
    ]
}
}

如果标签/字段是 json 对象的键,我看到的所有文档都显示了如何解析 json。例如,https://github.com/influxdata/telegraf/tree/master/plugins/parsers/json

如何解析一个 json 对象,其中标签/字段和值被分成单独的列表?

以下是到目前为止我的 Telegraf 配置文件的相关部分。

[[inputs.http]]
  #URL 
  urls = ["url"]

  #http method
  method = "POST"

  #Parse `values` array only
  json_query = "data.results.0.series.0"

  #Exclude url and host items from tags
  tagexclude = ["url", "host"]

  #Overwrite measurement name from default `http` to `measurement_name`
  name_override = "measurement_name"

  ## Optional HTTP headers
  headers = {"cache-control" =  "no-cache","content-type" =  "application/json"}

  ## HTTP entity-body to send with POST/PUT requests.
  body = "{\"measurement\":\"measurement_name\", \"time_filter\":[1593068400, 1593068800]}"

  #Data from HTTP in JSON format
  data_format = "json"
4

0 回答 0