@Override public String get(Result result) { return result.getClassName(); } };
public static String getKeyString2(Query query, Result result, Entry<String, Object> values, List<String> typeNames, String rootPrefix) { String keyStr = null; if (values.getKey().startsWith(result.getAttributeName())) { keyStr = values.getKey(); } else { keyStr = result.getAttributeName() + "." + values.getKey(); } StringBuilder sb = new StringBuilder(); // Allow people to use something other than the classname as the output. if (result.getClassNameAlias() != null) { sb.append(result.getClassNameAlias()); } else { sb.append(cleanupStr(result.getClassName())); } sb.append("."); String typeName = cleanupStr(getConcatedTypeNameValues(query, typeNames, result.getTypeName())); if (typeName != null) { sb.append(typeName); sb.append("."); } sb.append(cleanupStr(keyStr)); return sb.toString(); }
@Override public String formatName(Result result) { StringBuilder formatted = new StringBuilder(); String attName = result.getAttributeName(); String className = result.getKeyAlias(); if (className == null) className = result.getClassName(); formatted.append(className); formatted.append(delimiter); formatted.append(attName); return formatted.toString(); } }
sb.append(result.getClassNameAlias()); } else { sb.append(cleanupStr(result.getClassName()));
nameBuilder.append(metric.getClassName());
quote(result.getAttributeName(), writer); writer.append(", \"class\" : "); quote(result.getClassName(), writer); writer.append(", \"alias\" : "); quote(result.getClassNameAlias(), writer);
@Override protected void internalWrite(Server server, Query query, ImmutableList<Result> results) throws Exception { for (Result result : results) { log.debug("Query result: [{}]", result); if (isNumeric(result.getValue())) { Map<String, Object> map = new HashMap<>(); 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("valuePath", Joiner.on('/').join(result.getValuePath())); map.put("keyAlias", result.getKeyAlias()); map.put("value", Double.parseDouble(result.getValue().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 [{}]", result.getValue(), result); } } }
/** * Adds a key to the StringBuilder * * It uses in order of preference: * * 1. resultAlias if that was specified as part of the query * 2. The domain portion of the ObjectName in the query if useObjDomainAsKey is set to true * 3. else, the Class Name of the MBean. I.e. ClassName will be used by default if the * user doesn't specify anything special * @param query * @param result * @param sb */ private static void addMBeanIdentifier(Query query, Result result, StringBuilder sb) { if (result.getKeyAlias() != null) { sb.append(result.getKeyAlias()); } else if (query.isUseObjDomainAsKey()) { sb.append(StringUtils.cleanupStr(result.getObjDomain(), query.isAllowDottedKeys())); } else { sb.append(StringUtils.cleanupStr(result.getClassName())); } }
@Nullable @Override public Result apply(@Nullable Result input) { if (input == null) { return null; } return new Result( input.getEpoch(), input.getAttributeName(), input.getClassName(), input.getObjDomain(), input.getKeyAlias(), input.getTypeName(), input.getValuePath(), valueTransformer.apply(input.getValue()) ); }
/** * Populate the context with values from the result. * * @param context - the expression context used when evaluating JEXL expressions. * @param result - the result of a JMX query. */ protected void populateContext(JexlContext context, Result result) { context.set(VAR_CLASSNAME, result.getClassName()); context.set(VAR_ATTRIBUTE_NAME, result.getAttributeName()); context.set(VAR_CLASSNAME_ALIAS, result.getKeyAlias()); Map<String, String> typeNameMap = TypeNameValue.extractMap(result.getTypeName()); context.set(VAR_TYPENAME, typeNameMap); String effectiveClassname = result.getKeyAlias(); if (effectiveClassname == null) { effectiveClassname = result.getClassName(); } context.set(VAR_EFFECTIVE_CLASSNAME, effectiveClassname); context.set(VAR_RESULT, result); } }
private KResult(Server server, Result result) { alias = server.getAlias(); pid = server.getPid(); host = server.getHost(); port = server.getPort(); source = server.getSource(); attributeName = result.getAttributeName(); className = result.getClassName(); objDomain = result.getObjDomain(); typeName = result.getTypeName(); typeNameMap = result.getTypeNameMap(); epoch = result.getEpoch(); keyAlias = result.getKeyAlias(); this.valuePath = result.getValuePath(); this.value = result.getValue(); } }
@Override public String get(Result result) { return result.getClassName(); } };
@Override public String formatName(Result result) { StringBuilder formatted = new StringBuilder(); String attName = result.getAttributeName(); String className = result.getKeyAlias(); if (className == null) className = result.getClassName(); formatted.append(className); formatted.append(delimiter); formatted.append(attName); return formatted.toString(); } }
nameBuilder.append(metric.getClassName());
@Override protected void internalWrite(Server server, Query query, ImmutableList<Result> results) throws Exception { for (Result result : results) { log.debug("Query result: [{}]", result); if (isNumeric(result.getValue())) { Map<String, Object> map = new HashMap<>(); 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("valuePath", Joiner.on('/').join(result.getValuePath())); map.put("keyAlias", result.getKeyAlias()); map.put("value", Double.parseDouble(result.getValue().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 [{}]", result.getValue(), result); } } }
/** * Adds a key to the StringBuilder * * It uses in order of preference: * * 1. resultAlias if that was specified as part of the query * 2. The domain portion of the ObjectName in the query if useObjDomainAsKey is set to true * 3. else, the Class Name of the MBean. I.e. ClassName will be used by default if the * user doesn't specify anything special * @param query * @param result * @param sb */ private static void addMBeanIdentifier(Query query, Result result, StringBuilder sb) { if (result.getKeyAlias() != null) { sb.append(result.getKeyAlias()); } else if (query.isUseObjDomainAsKey()) { sb.append(StringUtils.cleanupStr(result.getObjDomain(), query.isAllowDottedKeys())); } else { sb.append(StringUtils.cleanupStr(result.getClassName())); } }
@Nullable @Override public Result apply(@Nullable Result input) { if (input == null) { return null; } return new Result( input.getEpoch(), input.getAttributeName(), input.getClassName(), input.getObjDomain(), input.getKeyAlias(), input.getTypeName(), input.getValuePath(), valueTransformer.apply(input.getValue()) ); }
/** * Populate the context with values from the result. * * @param context - the expression context used when evaluating JEXL expressions. * @param result - the result of a JMX query. */ protected void populateContext(JexlContext context, Result result) { context.set(VAR_CLASSNAME, result.getClassName()); context.set(VAR_ATTRIBUTE_NAME, result.getAttributeName()); context.set(VAR_CLASSNAME_ALIAS, result.getKeyAlias()); Map<String, String> typeNameMap = TypeNameValue.extractMap(result.getTypeName()); context.set(VAR_TYPENAME, typeNameMap); String effectiveClassname = result.getKeyAlias(); if (effectiveClassname == null) { effectiveClassname = result.getClassName(); } context.set(VAR_EFFECTIVE_CLASSNAME, effectiveClassname); context.set(VAR_RESULT, result); } }
private KResult(Server server, Result result) { alias = server.getAlias(); pid = server.getPid(); host = server.getHost(); port = server.getPort(); source = server.getSource(); attributeName = result.getAttributeName(); className = result.getClassName(); objDomain = result.getObjDomain(); typeName = result.getTypeName(); typeNameMap = result.getTypeNameMap(); epoch = result.getEpoch(); keyAlias = result.getKeyAlias(); this.valuePath = result.getValuePath(); this.value = result.getValue(); } }