使用CURL在InfluxDB中插入行 [英] Insert line in InfluxDB using CURL

查看:639
本文介绍了使用CURL在InfluxDB中插入行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下通过C#完成的POST请求:

I have the following POST request which is done from C#:

POST http://192.168.123.27:8086/write?db=HWDB HTTP/1.1
Content-Type: text/plain; charset=utf-8
Host: 192.168.123.27:8086
Content-Length: 97
Expect: 100-continue
Connection: Keep-Alive

HARDWARE,CPU=1 count=91i 1456298998307783936
HARDWARE,CPU=2 count=92i 1456298998307783936



<我想使用CURL进行相同的请求。我正在使用以下命令:

I want to do the same request using CURL. I'm using the following command:

curl -i -XPOST http://192.168.123.27:8086/write?db=HWDB --data-binary "HARDWARE,CPU="1" value=91, CPU="2" value=92 1422568543702900257"

这将返回错误:

{"error":"unable to parse 'HARDWARE,CPU=1 value=91i, CPU=2 value=92i 1422568543702900257': invalid field format"}

我应该如何更改CURL命令的工作方式?我正在Windows上运行CURL,如果我使用的话:

How should I change the CURL command to work? I'm running CURL from Windows, if I use:

curl -i -XPOST http://192.168.123.27:8086/write?db=HWDB --data-binary "HARDWARE,CPU=1 value=91"

数据已正确插入DB中。还尝试使用InfluxDB文档中的示例从文件插入:

data is correctly inserted in DB. Also tried to insert from file using the example from InfluxDB documentation:

curl -i -XPOST http://192.168.123.27:8086/write?db=HDWB --data-binary @data.txt

这将返回:

{"error":"partial write:\nunable to parse 'cpu_load_short,host=server02 value=0.
67\r': invalid number\nunable to parse    'cpu_load_short,host=server02,region=us-w
est value=0.55 1422568543702900257\r': bad timestamp"}

data.txt的内容:

Content of data.txt:

cpu_load_short,host=server02 value=0.67
cpu_load_short,host=server02,region=us-west value=0.55 1422568543702900257
cpu_load_short,direction=in,host=server01,region=us-west value=2.0 1422568543702900257


推荐答案

关于 data.txt 文件,Windows是此处的关键因素。几乎可以肯定的是,在行尾引入了CRLF,而不仅仅是换行。请参阅

Regarding the data.txt file, Windows is the key factor here. It is almost certainly introducing a CRLF rather than just a linefeed at the end of the lines. See the InfluxDB docs for more.

至于帖子顶部的直接示例:

As for the direct example at the top of your post:

curl -i -XPOST http://192.168.123.27:8086/write?db=HWDB --data-binary "HARDWARE,CPU="1" value=91, CPU="2" value=92 1422568543702900257"

内容不是有效的线路协议格式,并且永远无法正常工作。每个点都必须换行,并且值不能在点之间共享。剥离 curl 语法,这是尝试的写法:

the content is not valid line protocol format and can never work. Each point must be on a new line, and values cannot be shared between points. Stripping out the curl syntax, this is the attempted write:

HARDWARE,CPU="1" value=91, CPU="2" value=92 1422568543702900257

实际的有效语法是:

HARDWARE,CPU="1" value=91 1422568543702900257
HARDWARE,CPU="2" value=92 1422568543702900257

这篇关于使用CURL在InfluxDB中插入行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆