@Override public String get(Result result) { return result.getTypeName(); } };
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(); } }
private static void addTypeName(Query query, Result result, List<String> typeNames, StringBuilder sb) { String typeName = StringUtils.cleanupStr(query.makeTypeNameValueString(typeNames, result.getTypeName()), query.isAllowDottedKeys()); if (typeName != null && typeName.length() > 0) { sb.append(typeName); sb.append("."); } }
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(); } }
/** * Add the tag(s) for typeNames. * * @param result - the result of the JMX query. * @param resultString - current form of the metric string. * @return String - the updated metric string with the necessary tag(s) added. */ protected void addTypeNamesTags(StringBuilder resultString, Result result) { if (mergeTypeNamesTags) { // Produce a single tag with all the TypeName keys concatenated and all the values joined with '_'. String typeNameValues = TypeNameValuesStringBuilder.getDefaultBuilder().build(typeNames, result.getTypeName()); addTag(resultString, StringUtils.join(typeNames, ""), typeNameValues); } else { Map<String, String> typeNameMap = TypeNameValue.extractMap(result.getTypeName()); for (String oneTypeName : typeNames) { String value = typeNameMap.get(oneTypeName); if (value == null) value = ""; addTag(resultString, oneTypeName, value); } } }
private void doGenerate(List<Result> results) throws Exception { if (isDebugEnabled() && generate) { StringBuilder sb = new StringBuilder("\n"); List<String> keys = new ArrayList<>(); for (Result res : results) { if (isNumeric(res.getValue())) { String key = getDataSourceName(getConcatedTypeNameValues(res.getTypeName()), res.getAttributeName(), res.getValuePath()); if (keys.contains(key)) { throw new Exception("Duplicate datasource name found: '" + key + "'. Please try to add more typeName keys to the writer to make the name more unique. " + res.toString()); } keys.add(key); sb.append("<datasource><!-- ").append(res.getTypeName()).append(":") .append(res.getAttributeName()).append(":").append(res.getValuePath()) .append(" --><name>").append(key) .append("</name><type>GAUGE</type><heartbeat>400</heartbeat><min>U</min><max>U</max></datasource>\n"); } } log.debug(sb.toString()); } }
@Override public void internalWrite(Server server, Query query, ImmutableList<Result> results) throws Exception { RrdDef def = getDatabaseTemplateSpec(); List<String> dsNames = getDsNames(def.getDsDefs()); Map<String, String> dataMap = new TreeMap<>(); // go over all the results and look for datasource names that map to // keys from the result values for (Result res : results) { log.debug(res.toString()); String key = getDataSourceName(getConcatedTypeNameValues(res.getTypeName()), res.getAttributeName(), res.getValuePath()); if (isNumeric(res.getValue())) { log.debug("Generated DataSource name:value: {} : {}", key, res.getValue()); if (dsNames.contains(key)) { dataMap.put(key, res.getValue().toString()); } } } doGenerate(results); if (!dataMap.keySet().isEmpty() && !dataMap.values().isEmpty()) { rrdToolUpdate(StringUtils.join(dataMap.keySet(), ':'), StringUtils.join(dataMap.values(), ':')); } else { log.error("Nothing was logged for query: " + query); } }
TypeNameValuesStringBuilder.getDefaultBuilder().build(typeNames, metric.getTypeName())); if (typeName != null && typeName.length() > 0) { nameBuilder.append(".");
output.put(result.getTypeName(), query.getAttr().toString());
@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); } } }
@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); } }
@Override public String get(Result result) { return result.getTypeName(); } };
private static void addTypeName(Query query, Result result, List<String> typeNames, StringBuilder sb) { String typeName = StringUtils.cleanupStr(query.makeTypeNameValueString(typeNames, result.getTypeName()), query.isAllowDottedKeys()); if (typeName != null && typeName.length() > 0) { sb.append(typeName); sb.append("."); } }
/** * Add the tag(s) for typeNames. * * @param result - the result of the JMX query. * @param resultString - current form of the metric string. * @return String - the updated metric string with the necessary tag(s) added. */ protected void addTypeNamesTags(StringBuilder resultString, Result result) { if (mergeTypeNamesTags) { // Produce a single tag with all the TypeName keys concatenated and all the values joined with '_'. String typeNameValues = TypeNameValuesStringBuilder.getDefaultBuilder().build(typeNames, result.getTypeName()); addTag(resultString, StringUtils.join(typeNames, ""), typeNameValues); } else { Map<String, String> typeNameMap = TypeNameValue.extractMap(result.getTypeName()); for (String oneTypeName : typeNames) { String value = typeNameMap.get(oneTypeName); if (value == null) value = ""; addTag(resultString, oneTypeName, value); } } }
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 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); } } }
String typeName = cleanupStr(getConcatedTypeNameValues(query, typeNames, result.getTypeName())); if (typeName != null) { sb.append(typeName);
@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); } }