Beispiel #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) {

    }
  }
Beispiel #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) {

    }
  }
Beispiel #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) {

    }
  }