@Override protected void publish(Iterator<MetricValues> metrics) throws Exception { int size = topicPayloads.size(); while (metrics.hasNext()) { encoderOutputStream.reset(); MetricValues metricValues = metrics.next(); // Encode MetricValues into bytes recordWriter.encode(metricValues, encoder); TopicPayload topicPayload = topicPayloads.get(Math.abs(metricValues.getTags().hashCode() % size)); // Calculate the topic number with the hashcode of MetricValues' tags and store the encoded payload in the // corresponding list of the topic number topicPayload.addPayload(encoderOutputStream.toByteArray(), metricValues.getTags(), metricValues.getMetrics().size()); } publishMetric(topicPayloads.values()); }
@Override protected void publish(Iterator<MetricValues> metrics) throws Exception { int size = topicPayloads.size(); while (metrics.hasNext()) { encoderOutputStream.reset(); MetricValues metricValues = metrics.next(); // Encode MetricValues into bytes recordWriter.encode(metricValues, encoder); TopicPayload topicPayload = topicPayloads.get(Math.abs(metricValues.getTags().hashCode() % size)); // Calculate the topic number with the hashcode of MetricValues' tags and store the encoded payload in the // corresponding list of the topic number topicPayload.addPayload(encoderOutputStream.toByteArray(), metricValues.getTags(), metricValues.getMetrics().size()); } publishMetric(topicPayloads.values()); }
@Override public void add(Collection<? extends MetricValues> metricValues) { List<CubeFact> facts = Lists.newArrayListWithCapacity(metricValues.size()); for (MetricValues metricValue : metricValues) { String scope = metricValue.getTags().get(Constants.Metrics.Tag.SCOPE); List<Measurement> metrics = Lists.newArrayList(); // todo improve this logic? for (MetricValue metric : metricValue.getMetrics()) { String measureName = (scope == null ? "system." : scope + ".") + metric.getName(); MeasureType type = metric.getType() == MetricType.COUNTER ? MeasureType.COUNTER : MeasureType.GAUGE; metrics.add(new Measurement(measureName, type, metric.getValue())); } CubeFact fact = new CubeFact(metricValue.getTimestamp()) .addDimensionValues(metricValue.getTags()) .addMeasurements(metrics); facts.add(fact); } cube.get().add(facts); }
@Override public void add(Collection<? extends MetricValues> metricValues) { List<CubeFact> facts = Lists.newArrayListWithCapacity(metricValues.size()); for (MetricValues metricValue : metricValues) { String scope = metricValue.getTags().get(Constants.Metrics.Tag.SCOPE); List<Measurement> metrics = Lists.newArrayList(); // todo improve this logic? for (MetricValue metric : metricValue.getMetrics()) { String measureName = (scope == null ? "system." : scope + ".") + metric.getName(); MeasureType type = metric.getType() == MetricType.COUNTER ? MeasureType.COUNTER : MeasureType.GAUGE; metrics.add(new Measurement(measureName, type, metric.getValue())); } CubeFact fact = new CubeFact(metricValue.getTimestamp()) .addDimensionValues(metricValue.getTags()) .addMeasurements(metrics); facts.add(fact); } cube.get().add(facts); }