A (sort of - it's not directly to do with C#) related question in SO is: How to insert data in OpenTSDB (Time Series Database); as mentioned there, the basic shell command which easily works (in linux) is as follows:
echo "put mymetric.data_1 1295643636 48 a=foo" | nc -w 15 tsdHost tsdPort
My question is has anyone written a collector in C# for OpenTSDB? The issue I am facing is that although I can open a Socket to the tsd instance/port and I write the following to its stream, nothing seems to happen.
put mymetric.data_1 1295643636 48 a=foo
I am creating an InterNetwork, Stream based TCP Socket, and tried sending the above string as ASCII, UTF-8,-16 and -32 encoded bytes, all in vain.
Any pointers in what kind of Socket and what kind of encoded bytes I need to use will really help. The Java
code sample for the same thing I am trying to achieve is:
Socket sock = new Socket("tsd.server.com", 4242);
String point = "put my.metric 1314137008 60 host=someplace.net foo=1\n";
sock.getOutputStream().write(point.getBytes());
sock.close();
I just realized the string that I was sending did not have the newline character at the end. In the Java code sample, the newline is there explicitly.
Adding a newline at the end resolved the problem.
Sample code where you add the newline explicitly:
string message = "put mymetric.data_1 1295643636 48 a=foo";
IPAddress ip = IPAddress.Parse("xxx.xxx.xxx.xxx"); // tsdb deamon host ip
IPEndPoint endPoint = new IPEndPoint(ip, 4242); // tsdb deamon port
using (Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
{
s.Connect(endPoint);
s.Send(new ASCIIEncoding().GetBytes(message + Environment.NewLine));
s.Close();
}