英文:
Selection expression using GJSON syntax, as in the example with jq
问题
我正在尝试使用Telegraf配置HTTP输入插件,但我需要使用选择表达式选择特定的指标,并将它们写入特定的Influxdb数据库。我知道如何使用jq进行选择,但我无法使用GJSON请求来实现。
我的输出如下所示:
[
{
"properties": {
"headers": {
"database": "telegraf"
},
"content_type": "text/plain"
},
"payload": "net,cluster_id=cluster01,dc=dc02,host=specific_host01,instance=instance-00107205 network_write_packets=15100740,network_write_drops=0 1628285530000000000\n",
"payload_encoding": "string"
},
{
"properties": {
"headers": {
"database": "stats"
},
"content_type": "text/plain"
},
"payload": "dsk_stats,Region=Q3,host=specific_host01 disk_usage=8.344534641 1628285530000000000\n",
"payload_encoding": "string"
}
]
为了通过stats选择指标,我使用jq命令:
curl -s -H "content-type:application/json" localhost:8080 |jq '.[] | select(.properties.headers.database=="stats") | "\(.payload)"'
dsk_stats,Region=Q3,host=specific_host01 disk_usage=8.344534641 1628285530000000000\n
是否可能使用GJSON语法进行这样的JSON选择?
英文:
I am trying to configure the HTTP input plugin using Telegraf, but I need to select certain metrics using the select expression and write them to a specific Influxdb database. I know how to select using jq, but I can't do it using a GJSON request.
My output look like this:
[
{
"properties": {
"headers": {
"database": "telegraf"
},
"content_type": "text/plain"
},
"payload": "net,cluster_id=cluster01,dc=dc02,host=specific_host01,instance=instance-00107205 network_write_packets=15100740,network_write_drops=0 1628285530000000000\n",
"payload_encoding": "string"
},
{
"properties": {
"headers": {
"database": "stats"
},
"content_type": "text/plain"
},
"payload": "dsk_stats,Region=Q3,host=specific_host01 disk_usage=8.344534641 1628285530000000000\n",
"payload_encoding": "string"
}
]
For choosing metrics by stats I'm using jq:
curl -s -H "content-type:application/json" localhost:8080 |jq '.[] | select(.properties.headers.database=="stats") | "\(.payload)"
dsk_stats,Region=Q3,host=specific_host01 disk_usage=8.344534641 1628285530000000000\n
Is it possible to make such json selection using the GJSON syntax?
答案1
得分: 2
给你这个:
#(properties.headers.database=="stats").payload
https://play.golang.org/p/7bXY6F2MQeZ
英文:
Here you go
#(properties.headers.database=="stats").payload
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论