예제 #1
0
 private String createAlias(Server server) {
   String alias;
   if (server.getAlias() != null) {
     alias = server.getAlias();
   } else {
     alias = server.getHost() + "_" + server.getPort();
     alias = StringUtils.cleanupStr(alias);
   }
   return alias;
 }
예제 #2
0
  @Override
  protected void internalWrite(Server server, Query query, ImmutableList<Result> results)
      throws Exception {

    for (Result result : results) {
      log.debug("Query result: [{}]", result);
      Map<String, Object> resultValues = result.getValues();
      for (Entry<String, Object> values : resultValues.entrySet()) {
        Object value = values.getValue();
        if (isNumeric(value)) {

          Map<String, Object> map = new HashMap<String, Object>();
          map.put("serverAlias", server.getAlias());
          map.put("server", server.getHost());
          map.put("port", server.getPort());
          map.put("objDomain", result.getObjDomain());
          map.put("className", result.getClassName());
          map.put("typeName", result.getTypeName());
          map.put("attributeName", result.getAttributeName());
          map.put("key", values.getKey());
          map.put("keyAlias", result.getKeyAlias());
          map.put("value", Double.parseDouble(value.toString()));
          map.put("timestamp", result.getEpoch());

          log.debug(
              "Insert into Elastic: Index: [{}] Type: [{}] Map: [{}]",
              indexName,
              ELASTIC_TYPE_NAME,
              map);
          Index index = new Index.Builder(map).index(indexName).type(ELASTIC_TYPE_NAME).build();
          JestResult addToIndex = jestClient.execute(index);
          if (!addToIndex.isSucceeded()) {
            throw new ElasticWriterException(
                String.format(
                    "Unable to write entry to elastic: %s", addToIndex.getErrorMessage()));
          }
        } else {
          log.warn(
              "Unable to submit non-numeric value to Elastic: [{}] from result [{}]",
              value,
              result);
        }
      }
    }
  }
예제 #3
0
  public static void main(String[] args) throws Exception {
    Server server = Server.builder().setHost("w2").setPort("1105").build();

    JMXConnector conn = null;
    try {
      conn = server.getServerConnection();
      MBeanServerConnection mbeanServer = conn.getMBeanServerConnection();

      TreeWalker3 tw = new TreeWalker3();
      tw.walkTree(mbeanServer, server);
    } catch (IOException e) {
      log.error(
          "Problem processing queries for server: " + server.getHost() + ":" + server.getPort(), e);
    } finally {
      if (conn != null) {
        conn.close();
      }
    }
  }