2015-07-13 68 views
0

我正在嘗試寫入openTSDB數據庫,因此我可以使用Bosun分析我的數據。openTSDB REST API不存儲數據

如果我手動添加通過博斯數據接口它工作正常,但是如果我做一個POST請求< docker-ip>/api/put(其中<docker-ip>正確配置)的數據不博斯露面。

如果我從我的Java應用程序發送數據點作爲Java應用程序中的一個JSON,在Bosun中根本沒有任何顯示,但是如果我使用Chrome應用程序'郵遞員'發送請求,那麼度量顯示出來,但是我發送的數據該請求沒有。

這是我送的數據:

try { 
    CloseableHttpClient httpClient = HttpClientBuilder.create().build(); 
    HttpPost request = new HttpPost("http://192.168.59.103:8070/api/put?summary"); 
    StringEntity params = new StringEntity("{\"metric\":\"tester.example\",\"timestamp\":\"" + System.currentTimeMillis() + "\", \"value\": \"22\", \"tags\": { \"host\": \"chrisedwards\", \"dc\": \"lga\" }}"); 
    request.setEntity(params); 
    request.setHeader("Content-Type", "application/json; charset=UTF-8"); 
    HttpResponse response = httpClient.execute(request); 
    System.out.println(response); 
    // handle response here... 
} catch (Exception ex) { 
    ex.printStackTrace(); 
} finally { 
    // httpClient.close(); 
} 

它返回一個200 response code。然後,我使用Postmaster將相同的請求發送到與java應用程序相同的地址,但postmaster請求在Bosun中顯示指標名稱,但沒有數據,並且Java請求甚至沒有顯示指標名稱。

回答

0

試試這個,它曾我的目的:

try { 
      String url = "http://192.168.59.103:8070/api/put"; 
      URL obj = new URL(url); 
      HttpURLConnection con = (HttpURLConnection) obj.openConnection(); 

      //add reuqest header 
      con.setRequestMethod("POST"); 
      con.setRequestProperty("User-Agent", USER_AGENT); 
      con.setRequestProperty("Accept-Language", "en-US,en;q=0.5"); 

      String urlParameters = "{\"metric\":\"tester.example\",\"timestamp\":\"" + System.currentTimeMillis() + "\", \"value\": \"22\", \"tags\": { \"host\": \"chrisedwards\", \"dc\": \"lga\" }}"; 
      // Send post request 
      con.setDoOutput(true); 
      DataOutputStream wr = new DataOutputStream(con.getOutputStream()); 
      wr.writeBytes(urlParameters); 
      wr.flush(); 
      wr.close(); 

      int responseCode = con.getResponseCode(); 
      System.out.println("\nSending 'POST' request to URL : " + url); 
      System.out.println("Post parameters : " + urlParameters); 
      System.out.println("Response Code : " + responseCode); 

      BufferedReader in = new BufferedReader(
        new InputStreamReader(con.getInputStream())); 
      String inputLine; 
      StringBuffer response = new StringBuffer(); 

      while ((inputLine = in.readLine()) != null) { 
       response.append(inputLine); 
      } 
      in.close(); 

      //print result 
      System.out.println(response.toString()); 
     } 
     catch(Exception e) { 
      e.printStackTrace(); 
     }