Issues writing multiple points

time-series
influxdb
#1

Hey, I’ve been having issues writing multiple points to influxdb using the command prompt on windows. I’m able to write it on linux but I have to press the enter key and then continue adding points which is okay but then I need to automate this behavior using a script or directly send the data in from my sensor.
I’ve opened up an issue on GitHub. Here’s the link:


Please have a look at it and help me out here. I’d appreciate any help.
Thank you!

#2

Bump. Any suggestions? How does everyone here make use curl to make a HTTP call and write multiple points? I’n not able to add a new line which makes the write fail. Any suggestions would be helpful as I’ve got a lot of data to insert and I’d like to automate it.

#3

If you wrote all the lines to a file, say, line_protocol.txt, then you should be able to POST with curl along the lines of

curl -XPOST 'http://localhost:8086/write?db=mydb' -d @line_protocol.txt

See also: https://stackoverflow.com/questions/3007253/send-post-xml-file-using-curl-command-line

#4

Correction: that should be --data-binary instead of -d (or --data). Using -d seems to eliminate newlines, creating invalid line protocol.

#5

Thank you for the reply. While this may work, it will still cause a bottleneck as I have to write it to a file first and curl will have to read from it again. I’m sure there’s a lag there. Also, I don’t think I can use this as File I/O on a micro-controller might not be pretty fast. Can you think of something else?

#6

In bash, I just write multiple newlines inside a quoted string:

curl -XPOST localhost:8086/write?db=junk --data-binary 'm,tag=a n=1
m,tag=b n=2
m,tag=c n=3
'

I don’t know what you have to do to use a multi-line string literal in a Windows command prompt.

#7

To use stdin as the post body for curl, use --data-binary @-:

(for i in $(seq 4096); do echo "ctr,s=$i n=$i"; done) |
  curl -i -XPOST localhost:8086/write?db=junk --data-binary @-
#8

I tried it on both Linux and windows and the issue is the same. I don’t think you’re understanding my PoV. You’re entering the newlines yourself by pressing enter. That works even on my end. What I’m saying is that I need to enter thousands of rows of data and I cannot do them manually since the sensor is sending that data to me. I need to enter a newline programatically. Like how we’ve got “\n” in C. Makes sense?

As for your script, how does it work exactly? Do I have to pass the data as command line arguments? Because that didn’t work for me neither did echoing it and the piping it to the script. Would you please clear that out for me?