示例#1
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);
        }
      }
    }
  }
示例#2
0
  public void walkTree(MBeanServerConnection connection, Server server) throws Exception {

    // key here is null, null returns everything!
    Set<ObjectName> mbeans = connection.queryNames(null, null);

    Map<String, String> output = newHashMap();

    for (ObjectName name : mbeans) {
      MBeanInfo info = connection.getMBeanInfo(name);
      MBeanAttributeInfo[] attrs = info.getAttributes();

      Query.Builder queryBuilder = Query.builder().setObj(name.getCanonicalName());
      ResultCapture resultCapture = new ResultCapture();
      queryBuilder.addOutputWriter(resultCapture);

      for (MBeanAttributeInfo attrInfo : attrs) {
        queryBuilder.addAttr(attrInfo.getName());
      }

      Query query = queryBuilder.build();

      try {
        Iterable<Result> results = server.execute(query);
        query.runOutputWritersForQuery(server, results);
      } catch (AttributeNotFoundException anfe) {
        log.error("Error", anfe);
      }

      for (Result result : resultCapture.results) {
        output.put(result.getTypeName(), query.getAttr().toString());
      }
    }

    for (Entry<String, String> entry : output.entrySet()) {
      log.debug(entry.getKey());
      log.debug(entry.getValue());
      log.debug("-----------------------------------------");
    }
  }