예제 #1
0
  // 一般需要统计时间 方法等调用此API
  public static void collect(String consumerName, String providerName, long start) {
    try {
      Date date = new Date(start);
      if (start - LoggerInit.logFileGenStartTime > LoggerInit.logFileGenIntervalTime) {
        LoggerInit.initOK = false;
        LoggerInit.initLogger();
      }
      String localHost = NetUtils.getLocalHost();
      long timestamp = System.currentTimeMillis();
      long elapsed = timestamp - start; // 计算调用耗时

      URL url =
          new URL(
              Constants.KEY_COUNT_PROTOCOL,
              localHost,
              0,
              Constants.KEY_CONSUMER_APP,
              consumerName,
              Constants.KEY_PROVIDER_APP,
              providerName,
              Constants.KEY_SUCCESS,
              "1",
              Constants.KEY_ELAPSED,
              String.valueOf(elapsed),
              Constants.KEY_ERROR_CODE,
              "0",
              Constants.KEY_COLLECT_TYPE,
              String.valueOf(Constants.COLLECT_TYPE_LOCAL),
              Constants.KEY_TIMESTAMP,
              DateFormatUtils.toString(date, DateFormatUtils.pattern12));
      collect(url);
    } catch (Exception e) {

    }
  }
예제 #2
0
  // 信息采集
  public static void collect(
      String consumerName,
      String providerName,
      String providerAddress,
      String service,
      String method,
      long start,
      boolean error,
      String errorCode) {
    try {
      Date date = new Date(start);
      if (start - LoggerInit.logFileGenStartTime > LoggerInit.logFileGenIntervalTime) {
        LoggerInit.initOK = false;
        LoggerInit.initLogger();
      }
      String localHost = NetUtils.getLocalHost();
      // ---- 服务信息获取 ----
      long timestamp = System.currentTimeMillis();
      long elapsed = timestamp - start; // 计算调用耗时

      URL url =
          new URL(
              Constants.KEY_COUNT_PROTOCOL,
              localHost,
              0,
              Constants.KEY_CONSUMER_APP,
              consumerName,
              Constants.KEY_INTERFACE,
              service,
              Constants.KEY_METHOD,
              method,
              Constants.KEY_PROVIDER_APP,
              providerName,
              Constants.KEY_PROVIDER_ADD,
              providerAddress,
              error ? Constants.KEY_FAILURE : Constants.KEY_SUCCESS,
              "1",
              Constants.KEY_ELAPSED,
              String.valueOf(elapsed),
              Constants.KEY_ERROR_CODE,
              errorCode,
              Constants.KEY_COLLECT_TYPE,
              String.valueOf(Constants.COLLECT_TYPE_CONSUMER),
              Constants.KEY_TIMESTAMP,
              DateFormatUtils.toString(date, DateFormatUtils.pattern12));
      collect(url);
    } catch (Exception e) {

    }
  }
예제 #3
0
  // 一般需要统计次数不需要统计 方法等调用此API
  public static void collect(
      String consumerName, String providerName, boolean error, String errorCode) {
    try {
      Date date = new Date();
      long timestamp = date.getTime();

      if (timestamp - LoggerInit.logFileGenStartTime > LoggerInit.logFileGenIntervalTime) {
        LoggerInit.initOK = false;
        LoggerInit.initLogger();
      }
      String localHost = NetUtils.getLocalHost();
      // ---- 服务信息获取 ----

      URL url =
          new URL(
              Constants.KEY_COUNT_PROTOCOL,
              localHost,
              0,
              Constants.KEY_CONSUMER_APP,
              consumerName,
              Constants.KEY_PROVIDER_APP,
              providerName,
              error ? Constants.KEY_FAILURE : Constants.KEY_SUCCESS,
              "1",
              Constants.KEY_ELAPSED,
              String.valueOf(0),
              Constants.KEY_ERROR_CODE,
              errorCode,
              Constants.KEY_COLLECT_TYPE,
              String.valueOf(Constants.COLLECT_TYPE_LOCAL),
              Constants.KEY_TIMESTAMP,
              DateFormatUtils.toString(date, DateFormatUtils.pattern12));

      collect(url);
    } catch (Exception e) {

    }
  }
예제 #4
0
파일: URL.java 프로젝트: yungoo/apple-qos
 public boolean isLocalHost() {
   return NetUtils.isLocalHost(host) || getParameter(Constants.LOCALHOST_KEY, false);
 }
예제 #5
0
파일: URL.java 프로젝트: yungoo/apple-qos
 /**
  * 获取IP地址.
  *
  * <p>请注意: 如果和Socket的地址对比, 或用地址作为Map的Key查找, 请使用IP而不是Host, 否则配置域名会有问题
  *
  * @return ip
  */
 public String getIp() {
   if (ip == null) {
     ip = NetUtils.getIpByHost(host);
   }
   return ip;
 }