public static String getValuePathString(Result result) { return Joiner.on('.').join(result.getValuePath()); }
@Override public String serialize(Server server, Query query, Result result) throws IOException { log.debug("Query result: [{}]", result); Object value = result.getValue(); if (!isNumeric(value)) { log.warn("Unable to submit non-numeric value to Kafka: [{}] from result [{}]", value, result); return null; } return createJsonMessage(server, query, result, result.getValuePath(), value); }
public static String getValueKey(Result result) { if (result.getValuePath().isEmpty()) { return result.getAttributeName(); } return result.getAttributeName() + "." + getValuePathString(result); }
/** * Parse one of the results of a Query and return a list of strings containing metric details ready for sending to * OpenTSDB. * * @param result - one results from the Query. * @param server - Server object for importing hostname * @return List<String> - the list of strings containing metric details ready for sending to OpenTSDB. */ /* private List<String> formatResult(Result result) { return this.formatResult(result, null); } */ private List<String> formatResult(Result result, Server server) { List<String> resultStrings = new LinkedList<>(); if (result.getValuePath().isEmpty()) { processOneMetric(resultStrings, server, result, result.getValue(), null, null); } else { processOneMetric(resultStrings, server, result, result.getValue(), tagName, StringUtils.join(result.getValuePath(), '.')); } return resultStrings; }
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()); } }
if( !result.getValuePath().isEmpty() ){ tagList.add("resultKey="+ KeyUtils.getValuePathString(result));
@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); } }
@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); } } }
@Override public void internalWrite(Server server, Query query, ImmutableList<Result> results) throws Exception { RrdDb db = null; try { db = createOrOpenDatabase(); Sample sample = db.createSample(); List<String> dsNames = Arrays.asList(db.getDsNames()); // go over all the results and look for datasource names that map to // keys from the result values for (Result res : results) { String key = StringUtils.join(res.getValuePath(), '.'); if (dsNames.contains(key) && isNumeric(res.getValue())) { sample.setValue(key, Double.valueOf(res.getValue().toString())); } } sample.update(); } finally { if (db != null) { db.close(); } } }
private MetricDatum processResult(Result result) { // Sometimes the attribute name and the key of the value are the same MetricDatum metricDatum = new MetricDatum(); if (result.getValuePath().isEmpty()) { metricDatum.setMetricName(result.getAttributeName()); } else { metricDatum.setMetricName(result.getAttributeName() + "_" + KeyUtils.getValuePathString(result)); } metricDatum.setDimensions(dimensions); // Converts the Objects to Double-values for CloudWatch metricDatum.setValue(toDoubleConverter.apply(result.getValue())); metricDatum.setTimestamp(new Date()); return metricDatum; }
@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()) ); }
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(); } }
public static String getValuePathString(Result result) { return Joiner.on('.').join(result.getValuePath()); }
@Override public String serialize(Server server, Query query, Result result) throws IOException { log.debug("Query result: [{}]", result); Object value = result.getValue(); if (!isNumeric(value)) { log.warn("Unable to submit non-numeric value to Kafka: [{}] from result [{}]", value, result); return null; } return createJsonMessage(server, query, result, result.getValuePath(), value); }
public static String getValueKey(Result result) { if (result.getValuePath().isEmpty()) { return result.getAttributeName(); } return result.getAttributeName() + "." + getValuePathString(result); }
/** * Parse one of the results of a Query and return a list of strings containing metric details ready for sending to * OpenTSDB. * * @param result - one results from the Query. * @param server - Server object for importing hostname * @return List<String> - the list of strings containing metric details ready for sending to OpenTSDB. */ /* private List<String> formatResult(Result result) { return this.formatResult(result, null); } */ private List<String> formatResult(Result result, Server server) { List<String> resultStrings = new LinkedList<>(); if (result.getValuePath().isEmpty()) { processOneMetric(resultStrings, server, result, result.getValue(), null, null); } else { processOneMetric(resultStrings, server, result, result.getValue(), tagName, StringUtils.join(result.getValuePath(), '.')); } return resultStrings; }
@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()) ); }
private MetricDatum processResult(Result result) { // Sometimes the attribute name and the key of the value are the same MetricDatum metricDatum = new MetricDatum(); if (result.getValuePath().isEmpty()) { metricDatum.setMetricName(result.getAttributeName()); } else { metricDatum.setMetricName(result.getAttributeName() + "_" + KeyUtils.getValuePathString(result)); } metricDatum.setDimensions(dimensions); // Converts the Objects to Double-values for CloudWatch metricDatum.setValue(toDoubleConverter.apply(result.getValue())); metricDatum.setTimestamp(new Date()); return metricDatum; }
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(); } }