Skip to content
LUYONGQIANG edited this page Dec 3, 2019 · 8 revisions

http://opentsdb.net/docs/build/html/api_http/put.html


When using HTTP for puts, you may need to enable support for chunks if your HTTP client automatically breaks large requests into smaller packets. For example, CURL will break up messages larger than 2 or 3 data points and by default, OpenTSDB disables chunk support. Enable it by setting tsd.http.request.enable_chunked to true in the config file.

C# Code

class Program {
  static void Main(string[] args)
   {
    Console.WriteLine("Init Api Url");
    ApiUrlConfig.ChangeBaseUrl("http://192.168.1.22:4242/");
    Test test = new Test();
    test.Run();
    Console.ReadKey();
   }
}

class Test {
 public async void Run()
  {
    OpenTsdbClient apiClient=new OpenTsdbClient();
    var list = new List<DataPoint<float>>();
    DataPoint<float> dataPoint = new DataPoint<float>();
    dataPoint.Metric = "bridge";
    dataPoint.Timestamp = ConvertDateTimeInt(DateTime.Now);
    dataPoint.Value = 23.4f;
    dataPoint.Tags.Add("host", "YL-01-01");
    dataPoint.Tags.Add("dc", "lga");
    list.Add(dataPoint);
    var result = await apiClient.PostAsync<dynamic>("api/put?summary", list);
    Console.WriteLine(result);
    var result2 = await apiClient.PostAsync<dynamic>
                 ("/api/put/?details&sync&sync_timeout=60000", list);
    Console.WriteLine(result2);
  }

 public static int ConvertDateTimeInt(System.DateTime time)
 {
   System.DateTime startTime =new DateTime(1970, 1, 1);
   return (int)(time - startTime).TotalSeconds;
  }
 }

Result

{
"success":1,
"failed":0
}

Clone this wiki locally