Пример #1
0
  private void processExceptionRule() {
    List<ThresholdRule> rules = m_manager.getAllExceptionRules();
    Transaction t = Cat.newTransaction("Alarm", "ProcessExceptionRule");

    for (ThresholdRule rule : rules) {
      try {
        String connectUrl = rule.getConnectUrl();
        ThresholdDataEntity entity = m_connector.fetchAlarmData(connectUrl);

        if (entity != null) {
          entity.setDomain(rule.getDomain());
          Cat.getProducer().logEvent("AlarmUrl", connectUrl, Event.SUCCESS, entity.toString());

          ExceptionDataEvent event = new ExceptionDataEvent(entity);

          m_dispatcher.dispatch(event);
        }
      } catch (Exception e) {
        t.setStatus(e);
        Cat.logError(e);
      }
    }
    t.setStatus(Transaction.SUCCESS);
    t.complete();
  }
Пример #2
0
  @Test
  public void sendSqlTransaction() throws Exception {
    for (int k = 0; k < 5; k++) {
      for (int i = 0; i < 100; i++) {
        Transaction t = Cat.getProducer().newTransaction("SQL", "User.select" + i % 10);
        Cat.getProducer().newEvent("SQL.Method", "Select").setStatus(Message.SUCCESS);
        Cat.getProducer()
            .newEvent("SQL.Database", "jdbc:mysql://192.168.7.43:3306/database" + k)
            .setStatus(Message.SUCCESS);
        t.addData("select * from hostinfo");
        t.setStatus(Message.SUCCESS);
        t.complete();

        Transaction t2 = Cat.getProducer().newTransaction("SQL", "User.insert" + i % 10);
        Cat.getProducer().newEvent("SQL.Method", "Update").setStatus(Message.SUCCESS);
        Cat.getProducer()
            .newEvent("SQL.Database", "jdbc:mysql://192.168.7.43:3306/database" + k)
            .setStatus(Message.SUCCESS);
        t2.addData("update * from hostinfo");
        t2.complete();

        Transaction t3 = Cat.getProducer().newTransaction("SQL", "User.delete" + i % 10);
        Cat.getProducer().newEvent("SQL.Method", "Delete").setStatus(Message.SUCCESS);
        Cat.getProducer()
            .newEvent("SQL.Database", "jdbc:mysql://192.168.7.43:3306/database" + k)
            .setStatus(Message.SUCCESS);
        t3.addData("delete * from hostinfo");
        t3.setStatus(Message.SUCCESS);
        t3.complete();
      }
    }
    Thread.sleep(1000);
  }
Пример #3
0
    @Override
    public void run() {
      boolean active = true;

      while (active) {
        Date date = TimeUtil.getCurrentDay();
        long time = date.getTime();

        if (time > m_end) {
          Transaction t = Cat.newTransaction("ReportReload", "Week");
          try {
            reload();
            t.setStatus(Transaction.SUCCESS);
          } catch (Exception e) {
            Cat.logError(e);
            t.setStatus(e);
          } finally {
            t.complete();
          }
        }
        try {
          Thread.sleep(60 * 60 * 1000);
        } catch (InterruptedException e) {
          active = false;
        }
      }
    }
Пример #4
0
  @Test
  public void sendDependencyTransaction() throws Exception {
    int size = 10;
    for (int i = 0; i < size; i++) {
      Transaction t = Cat.getProducer().newTransaction("SQL", "User.select" + i % 10);
      Cat.getProducer().newEvent("SQL.Method", "Select").setStatus(Message.SUCCESS);
      Cat.getProducer()
          .newEvent("SQL.Database", "jdbc:mysql://192.168.7.43:3306/database" + i % 4)
          .setStatus(Message.SUCCESS);
      t.addData("select * from hostinfo");
      t.setStatus(Message.SUCCESS);
      t.complete();
    }

    for (int i = 0; i < size; i++) {
      Transaction t = Cat.getProducer().newTransaction("PigeonCall", "Method3");
      Cat.getProducer().newEvent("PigeonCall.server", "192.168.64.11:2280");
      t.addData("key and value");

      Thread.sleep(1);
      t.complete();
    }

    for (int i = 0; i < size; i++) {
      Transaction t = Cat.getProducer().newTransaction("PigeonService", "Method6");
      Cat.getProducer().newEvent("PigeonService.client", "192.168.7.77");
      t.addData("key and value");

      Thread.sleep(51);
      t.complete();
    }
  }
Пример #5
0
    @Override
    public void run() {
      Transaction t = Cat.newTransaction("TaggedThread", m_tag);

      try {
        TimeUnit.MILLISECONDS.sleep(m_timeout);

        t.setStatus(Message.SUCCESS);
        Cat.getManager().bind(m_tag, "Child Tagged Thread");
      } catch (Exception e) {
        Cat.logError(e);
        t.setStatus(e);
      } finally {
        t.complete();
      }
    }
Пример #6
0
  @Override
  public void run() {
    boolean active = true;
    try {
      Thread.sleep(5000);
    } catch (InterruptedException e) {
      active = false;
    }
    while (active) {
      Transaction t = Cat.newTransaction("AlertDatabase", TimeHelper.getMinuteStr());
      long current = System.currentTimeMillis();

      try {
        Map<String, ProductLine> productLines =
            m_productLineConfigManager.getCompany().getProductLines();

        for (ProductLine productLine : productLines.values()) {
          try {
            if (productLine.isDatabaseMonitorDashboard()) {
              processProductLine(productLine);
            }
          } catch (Exception e) {
            Cat.logError(e);
          }
        }

        t.setStatus(Transaction.SUCCESS);
      } catch (Exception e) {
        t.setStatus(e);
      } finally {
        m_currentReports.clear();
        m_lastReports.clear();
        t.complete();
      }
      long duration = System.currentTimeMillis() - current;

      try {
        if (duration < DURATION) {
          Thread.sleep(DURATION - duration);
        }
      } catch (InterruptedException e) {
        active = false;
      }
    }
  }
Пример #7
0
  @Test
  public void sendSendSqlErrorMessage() throws Exception {
    for (int i = 0; i < 100; i++) {
      Transaction t = Cat.getProducer().newTransaction("SQL", "Test");

      t.addData("key and value");
      t.setStatus(new NullPointerException());
      t.complete();
    }
    Thread.sleep(1000);
  }
Пример #8
0
  @Test
  public void sendException() throws Exception {
    for (int i = 0; i < 10; i++) {
      Transaction t = Cat.newTransaction("Midas", "XXName");
      try {
        t.setStatus("Fail");

        DefaultMessageTree tree = (DefaultMessageTree) Cat.getManager().getThreadLocalMessageTree();

        tree.setDomain("rs-mapi-web");
      } catch (Exception e) {
        t.setStatus(Transaction.SUCCESS);
        Cat.logError(e);
        throw e;
      } finally {
        t.complete();
      }
    }
    Thread.sleep(10000);
  }
Пример #9
0
  @Override
  public void run() {
    boolean active = true;
    try {
      Thread.sleep(5000);
    } catch (InterruptedException e) {
      active = false;
    }
    while (active) {
      Transaction t = Cat.newTransaction("AlertApp", TimeHelper.getMinuteStr());
      long current = System.currentTimeMillis();

      try {
        MonitorRules monitorRules = m_appRuleConfigManager.getMonitorRules();
        Map<String, Rule> rules = monitorRules.getRules();

        for (Entry<String, Rule> entry : rules.entrySet()) {
          try {
            processRule(entry.getValue());
          } catch (Exception e) {
            Cat.logError(e);
          }
        }
        t.setStatus(Transaction.SUCCESS);
      } catch (Exception e) {
        t.setStatus(e);
        Cat.logError(e);
      } finally {
        t.complete();
      }
      long duration = System.currentTimeMillis() - current;

      try {
        if (duration < DURATION) {
          Thread.sleep(DURATION - duration);
        }
      } catch (InterruptedException e) {
        active = false;
      }
    }
  }
Пример #10
0
  @Test
  public void sendTraceInfo() throws Exception {

    for (int i = 0; i < 10; i++) {
      Transaction t = Cat.newTransaction("Trace", "Test" + i);
      try {
        Cat.logTrace("Trace", "Info");
        Cat.logTrace("Trace", "Dubug", Trace.SUCCESS, "sss");
        Trace trace = Cat.newTrace("Trace", "Error");

        trace.setStatus(Trace.SUCCESS);
        trace.addData("errorTrace");
        t.setStatus("Fail");
      } catch (Exception e) {
        t.setStatus(Transaction.SUCCESS);
        Cat.logError(e);
        throw e;
      } finally {
        t.complete();
      }
    }
    Thread.sleep(10000);
  }
Пример #11
0
  @Test
  public void testTaggedTransaction() throws Exception {
    Transaction t = Cat.newTransaction("TaggedRoot", "Root");
    Cat.newTaggedTransaction("TaggedChild", "Child1", "Tag1");
    Cat.newTaggedTransaction("TaggedChild", "Child2", "Tag2");

    Threads.forGroup().start(new TaggedThread(500, "Tag1"));
    Threads.forGroup().start(new TaggedThread(100, "Tag2"));

    TimeUnit.MILLISECONDS.sleep(200);

    t.setStatus(Message.SUCCESS);
    t.complete();
  }
Пример #12
0
  @Test
  public void testForkedTransaction() throws Exception {
    Transaction t = Cat.newTransaction("ForkedRoot", "Root");
    ForkedTransaction t1 = Cat.newForkedTransaction("ForkedChild", "Child1");
    ForkedTransaction t2 = Cat.newForkedTransaction("ForkedChild", "Child2");

    Threads.forGroup().start(new TimedThread(t1, 500)); // will run away
    Threads.forGroup().start(new TimedThread(t2, 100)); // will be back in time

    TimeUnit.MILLISECONDS.sleep(200);

    t.setStatus(Message.SUCCESS);
    t.complete();
  }
Пример #13
0
  @Test
  public void sendMaxMessage() throws Exception {
    long time = System.currentTimeMillis();
    int i = 10;

    while (i > 0) {
      i++;
      Transaction total = Cat.newTransaction("Cat", "Test");
      Transaction t = Cat.getProducer().newTransaction("Cache.kvdb", "Method" + i % 10);
      t.setStatus(Message.SUCCESS);
      Cat.getProducer().newEvent("Cache.kvdb", "Method" + i % 10 + ":missed");
      t.addData("key and value");

      Transaction t2 = Cat.getProducer().newTransaction("Cache.web", "Method" + i % 10);
      Cat.getProducer().newEvent("Cache.web", "Method" + i % 10 + ":missed");
      t2.addData("key and value");
      t2.setStatus(Message.SUCCESS);
      t2.complete();

      Transaction t3 = Cat.getProducer().newTransaction("Cache.memcached", "Method" + i % 10);
      t3.addData("key and value");
      t3.setStatus(Message.SUCCESS);
      t3.complete();

      Transaction t4 = Cat.getProducer().newTransaction("Cache.memcached", "Method" + i % 10);
      t4.addData("key and value");
      t4.setStatus(Message.SUCCESS);
      t4.complete();

      Transaction t5 = Cat.getProducer().newTransaction("Cache.memcached", "Method" + i % 10);
      t5.addData("key and value");
      t5.setStatus(Message.SUCCESS);
      t5.complete();

      Transaction t6 = Cat.getProducer().newTransaction("Cache.memcached", "Method" + i % 10);
      t6.addData("key and value");
      t6.setStatus(Message.SUCCESS);
      t6.complete();

      Transaction t7 = Cat.getProducer().newTransaction("Cache.memcached", "Method" + i % 10);
      t7.addData("key and value");
      t7.setStatus(Message.SUCCESS);
      t7.complete();

      Transaction t8 = Cat.getProducer().newTransaction("Cache.memcached", "Method" + i % 10);
      t8.addData("key and value");
      t8.setStatus(Message.SUCCESS);
      t8.complete();

      Transaction t9 = Cat.getProducer().newTransaction("Cache.memcached", "Method" + i % 10);
      t9.addData("key and value");
      t9.setStatus(Message.SUCCESS);
      t9.complete();
      t.complete();

      total.setStatus(Transaction.SUCCESS);
      t.complete();

      if (i % 10000 == 0) {
        long duration = System.currentTimeMillis() - time;
        System.out.println(
            "[" + duration + "ms]" + "[total]" + i + "[每秒" + i / duration * 1000 + "]");
      }
    }
    Thread.sleep(10 * 1000);
  }
Пример #14
0
  /**
   * 保存swallowMessage到数据库
   *
   * @throws ServerDaoException
   */
  @Override
  public Packet sendMessage(Packet pkt) throws ServerDaoException {
    if (pkt == null) {
      throw new IllegalArgumentException("Argument of remote service could not be null.");
    }
    Packet pktRet = null;
    SwallowMessage swallowMessage;
    String topicName;
    String sha1;
    switch (pkt.getPacketType()) {
      case PRODUCER_GREET:
        LOGGER.info(
            "[Got Greet][From="
                + ((PktProducerGreet) pkt).getProducerIP()
                + "][Version="
                + ((PktProducerGreet) pkt).getProducerVersion()
                + "]");
        // 返回ProducerServer地址
        pktRet = new PktSwallowPACK(producerServerIP);
        break;
      case OBJECT_MSG:
        topicName = ((PktMessage) pkt).getDestination().getName();

        // 验证topicName是否在白名单里
        boolean isValid = topicWhiteList.isValid(topicName);
        if (!isValid) {
          throw new IllegalArgumentException(
              "Invalid topic("
                  + topicName
                  + "), because it's not in whitelist, please contact swallow group for support.");
        }

        swallowMessage = ((PktMessage) pkt).getContent();
        sha1 = SHAUtil.generateSHA(swallowMessage.getContent());
        pktRet = new PktSwallowPACK(sha1);
        // 设置swallowMessage的sha-1
        swallowMessage.setSha1(sha1);

        String parentDomain;
        try {
          parentDomain = MessageId.parse(((PktMessage) pkt).getCatEventID()).getDomain();
        } catch (Exception e) {
          parentDomain = "UnknownDomain";
        }
        //            MessageTree tree = Cat.getManager().getThreadLocalMessageTree();
        //            tree.setMessageId(((PktMessage)pkt).getCatEventID());

        Transaction producerServerTransaction =
            Cat.getProducer()
                .newTransaction(
                    "In:" + topicName, parentDomain + ":" + swallowMessage.getSourceIp());
        // 将swallowMessage保存到mongodb
        try {
          messageDAO.saveMessage(topicName, swallowMessage);
          producerServerTransaction.addData("sha1", swallowMessage.getSha1());
          producerServerTransaction.setStatus(Message.SUCCESS);
        } catch (Exception e) {
          producerServerTransaction.addData(swallowMessage.toKeyValuePairs());
          producerServerTransaction.setStatus(e);
          Cat.getProducer().logError(e);
          LOGGER.error("[Save message to DB failed.]", e);
          throw new ServerDaoException(e);
        } finally {
          producerServerTransaction.complete();
        }
        break;
      default:
        LOGGER.warn("[Received unrecognized packet.]" + pkt);
        break;
    }
    return pktRet;
  }
Пример #15
0
    @Override
    protected void doActivity(AgentContext ctx) throws Exception {
      int retriedCount = ctx.getRetriedCount();

      if (retriedCount >= MAX_RETRY_COUNT) {
        moveTo(ctx, FAILED);
      } else {

        long retryInterval = ctx.getConfigManager().getDeployRetryInterval();

        ctx.setRetriedCount(retriedCount + 1);

        Thread.sleep(retryInterval); // sleep a while before retry

        Transaction t =
            Cat.newTransaction(
                "phoenix-agent:" + ctx.getDomain(),
                ctx.getHost() + ":" + ctx.getWarType() + ":" + ctx.getVersion());

        String host = ctx.getHost();
        int id = ctx.getDeployId();
        String domain = ctx.getDomain();
        String version = ctx.getVersion();
        String type = ctx.getWarType();
        boolean skipTest = ctx.isSkipTest();
        String url = ctx.getConfigManager().getDeployUrl(type, host, id, domain, version, skipTest);
        String json = null;

        ctx.print(
            "[WARN] Retry to deploy phoenix kernel(%s) to host(%s) for deploy(%s) of domain(%s)  ... ",
            version, host, id, domain);

        boolean shouldRetry = false;

        try {
          json = ctx.openUrl(url);
          t.setStatus(Message.SUCCESS);
        } catch (Exception e) {
          ctx.println(e.toString());

          t.setStatus(e);
          Cat.logError(e);

          shouldRetry = true;
          return;
        } finally {
          t.complete();

          if (shouldRetry) {
            moveTo(ctx, UNREACHABLE);
          }
        }

        Response response = DefaultJsonParser.parse(json);

        if ("ok".equals(response.getStatus())) {
          ctx.println("ACCEPTED");

          moveTo(ctx, SUBMITTED);
        } else {
          ctx.print(response.getStatus()).println();
          ctx.println(response.getMessage());

          moveTo(ctx, FAILED);
        }
      }
    }
Пример #16
0
    @Override
    protected void doActivity(AgentContext ctx) throws Exception {
      Transaction t =
          Cat.newTransaction(
              "phoenix-agent:" + ctx.getDomain(),
              ctx.getHost() + ":" + ctx.getWarType() + ":" + ctx.getVersion());

      int id = ctx.getDeployId();
      String domain = ctx.getDomain();
      String version = ctx.getVersion();
      String host = ctx.getHost();
      String type = ctx.getWarType();
      boolean skipTest = ctx.isSkipTest();
      String url = ctx.getConfigManager().getDeployUrl(type, host, id, domain, version, skipTest);
      String json = null;

      ctx.println(String.format("[INFO] Deploy URL: %s", url));
      ctx.print(
          "[INFO] Deploying phoenix kernel(%s) to host(%s) for deploy(%s) of domain(%s)  ... ",
          version, host, id, domain);

      boolean shouldRetry = false;

      try {
        json = ctx.openUrl(url);
        t.setStatus(Message.SUCCESS);
      } catch (Exception e) {
        t.setStatus(e);
        Cat.logError(e);

        ctx.println(e.toString());
        shouldRetry = true;
        return;
      } finally {
        t.complete();

        if (shouldRetry) {
          moveTo(ctx, UNREACHABLE);
        }
      }

      Response response;

      try {
        response = DefaultJsonParser.parse(json);
      } catch (Exception e) {
        ctx.println("Invalid JSON result:\r\n%s", json);
        return;
      }

      if ("ok".equals(response.getStatus())) {
        ctx.println("ACCEPTED");

        moveTo(ctx, SUBMITTED);
      } else {
        ctx.print(response.getStatus()).println();
        ctx.println(response.getMessage());

        moveTo(ctx, FAILED);
      }
    }