更新时间:2022-07-19 GMT+08:00
分享

配置参数

  1. 执行样例代码前,必须在样例代码工程“resources”目录下的opentsdb.properties中修改如下参数:

    tsd_hostname = node-ana-coreYQnTx
    tsd_port = 4242
    tsd_protocol = https
    • tsd_hostname:修改为连接OpenTSDB服务的TSD实例的主机名或IP。
      • 若当前运行环境与OpenTSDB安装环境处于同一个VPC网络中,使用连接的TSD实例IP或主机名均可。
      • 若当前运行环境与OpenTSDB安装环境位于不同VPC中,仅可使用主机名进行访问。同时需在连接的TSD实例上绑定EIP,并把该EIP及该TSD实例的主机名配置到hosts中,linux环境需修改文件位置为“/etc/hosts”,Windows环境需修改的文件位置为“C:\Windows\System32\drivers\etc\hosts”

      例如,访问的TSD实例主机名为node-ana-corexxqm,其对应绑定的EIP为100.94.10.10,则需录入如下配置:

      100.94.10.10 node-ana-coreYQnTx
    • tsd_port:TSD端口,默认使用4242。
    • tsd_protocol:请求协议,默认使用https。

  2. (可选)如果不使用样例工程,可在自己工程的pom.xml文件中添加依赖如下:

    • guava
      <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
      <dependency>
          <groupId>com.google.guava</groupId>
          <artifactId>guava</artifactId>
          <version>18.0</version>
      </dependency>
    • gson
      <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
      <dependency>
          <groupId>com.google.code.gson</groupId>
          <artifactId>gson</artifactId>
          <version>2.2.4</version>
      </dependency>
    • httpcore
      <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore -->
      <dependency>
          <groupId>org.apache.httpcomponents</groupId>
          <artifactId>httpcore</artifactId>
          <version>4.4.4</version>
      </dependency>
    • httpclient
      <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
      <dependency>
          <groupId>org.apache.httpcomponents</groupId>
          <artifactId>httpclient</artifactId>
          <version>4.5.2</version>
      </dependency>

  3. 每个HTTP请求都应该设置超时间,设置超时时间的方法如下:

    public static void addTimeout(HttpRequestBase req) {
      RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(5000)
          .setConnectionRequestTimeout(10000).setSocketTimeout(60000).build();
      req.setConfig(requestConfig);
    }

分享:

    相关文档

    相关产品