influxdata / influxdata/telegraf

JSON_v2 object: Index as tag

Open
#12,374 3 comments 6 reactions 0 assignees View on GitHub
area/json feature request plugin/parser
Dominant language
Go
Stars
17.8k
Forks
5.8k
Avg merge
1d 20h
Merged PRs (30d)
161

Description

### Use Case

I have the following json result and I want to mark each array entry of `emeters`. The array does not change its order.

```json
{
"emeters":[
{
"power":364.48,
"pf":0.88,
"current":1.76,
"voltage":232.23,
"is_valid":true,
"total":8635.9,
"total_returned":0.0
},
{
"power":35.52,
"pf":0.47,
"current":0.32,
"voltage":234.53,
"is_valid":true,
"total":1716.6,
"total_returned":0.0
},
{
"power":62.94,
"pf":0.92,
"current":0.29,
"voltage":237.38,
"is_valid":true,
"total":2164.8,
"total_returned":0.0
}
],
"total_power":462.94,
"emeter_n":{
"current":0.00,
"ixsum":1.77,
"mismatch":false,
"is_valid":false
}
}
```

Telegraf configuration example:

```toml
[[inputs.http]]
urls = [
"http://192.168.0.22/status"
]
interval = "5s"
timeout = "1s"
data_format = "json_v2"

[[inputs.http.json_v2]]
measurement_name = "shelly3em"

[[inputs.http.json_v2.object]]
path = "emeters"
index_as_tag = true
```

### Expected behavior

A tag like `index=0`, `index=1`, `index=2`

```
> shelly3em,index=0 current=1.76,is_valid=true,pf=0.88,power=364.48,total=8635.9,total_returned=0,voltage=232.23 1670322270000000000
> shelly3em,index=1 current=0.32,is_valid=true,pf=0.47,power=35.52,total=1716.6,total_returned=0,voltage=234.53 1670322270000000000
> shelly3em,index=2 current=0.29,is_valid=true,pf=0.92,power=62.94,total=2164.8,total_returned=0,voltage=237.38 1670322270000000000
```

### Actual behavior

Output without tag, so its not really usable by grafana.

```
> shelly3em current=1.76,is_valid=true,pf=0.88,power=364.48,total=8635.9,total_returned=0,voltage=232.23 1670322270000000000
> shelly3em current=0.32,is_valid=true,pf=0.47,power=35.52,total=1716.6,total_returned=0,voltage=234.53 1670322270000000000
> shelly3em current=0.29,is_valid=true,pf=0.92,power=62.94,total=2164.8,total_returned=0,voltage=237.38 1670322270000000000
```

### Additional info

_No response_

Contributor guide

Open the contributing guide

Research direction

Start at the HTTP input's json_v2 object configuration and trace how the emeters array is emitted as measurements. Use the provided JSON and index_as_tag configuration as the reproduction; done means the output contains index=0, index=1, and index=2 tags for the array entries.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
data, observability
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.