function (){ measurement = new Measurement({ map : map, defaultAreaUnit : Units.SQUARE_KILOMETERS, defaultLengthUnit : Units.KILOMETERS }, dom.byId('measurementDiv')); measurement.startup(); }
public void add(List<Fact> facts) { // Simply collecting all rows/cols/values that need to be put to the underlying table. NavigableMap<byte[], NavigableMap<byte[], byte[]>> gaugesTable = Maps.newTreeMap(Bytes.BYTES_COMPARATOR); NavigableMap<byte[], NavigableMap<byte[], byte[]>> incrementsTable = Maps.newTreeMap(Bytes.BYTES_COMPARATOR); for (Fact fact : facts) { for (Measurement measurement : fact.getMeasurements()) { byte[] rowKey = codec.createRowKey(fact.getDimensionValues(), measurement.getName(), fact.getTimestamp()); byte[] column = codec.createColumn(fact.getTimestamp()); if (MeasureType.COUNTER == measurement.getType()) { inc(incrementsTable, rowKey, column, measurement.getValue()); } else { set(gaugesTable, rowKey, column, Bytes.toBytes(measurement.getValue())); } } } NavigableMap<byte[], NavigableMap<byte[], Long>> convertedIncrementsTable = Maps.transformValues(incrementsTable, TRANSFORM_MAP_BYTE_ARRAY_TO_LONG); NavigableMap<byte[], NavigableMap<byte[], Long>> convertedGaugesTable = Maps.transformValues(gaugesTable, TRANSFORM_MAP_BYTE_ARRAY_TO_LONG); // todo: replace with single call, to be able to optimize rpcs in underlying table timeSeriesTable.put(convertedGaugesTable); timeSeriesTable.increment(convertedIncrementsTable); if (metrics != null) { metrics.increment(putCountMetric, convertedGaugesTable.size()); metrics.increment(incrementCountMetric, convertedIncrementsTable.size()); } }
for (Fact fact : facts) { for (Measurement measurement : fact.getMeasurements()) { byte[] rowKey = codec.createRowKey(fact.getDimensionValues(), measurement.getName(), fact.getTimestamp()); byte[] column = codec.createColumn(fact.getTimestamp()); if (MeasureType.COUNTER == measurement.getType()) { if (factCounterCache != null) { FactCacheKey cacheKey = new FactCacheKey(fact.getDimensionValues(), measurement.getName()); Long existingTs = factCounterCache.getIfPresent(cacheKey); inc(incrementsTable, rowKey, column, measurement.getValue()); inc(incGaugeTable, rowKey, column, measurement.getValue()); inc(incrementsTable, rowKey, column, measurement.getValue()); .put(column, measurement.getValue());
/** * Adds a {@link Measurement} to this {@link CubeFact}. * @param name name of the measurement to add * @param type type of the measurement to add * @param value value of the measurement to add * @return this {@link CubeFact} */ public CubeFact addMeasurement(String name, MeasureType type, long value) { measurements.add(new Measurement(name, type, value)); return this; }
@Nullable public Measurement getMeasurement(StructuredRecord record) { Long value = getValue(record); if (value == null) { return null; } return new Measurement(name, type, value); }
super.onAttach(activity); try { Measurement measurement = new Measurement(); measurement.s = "fragment"; onMeasurementSetListener = (OnMeasurementSetListener) activity;
private void writeInc(FactTable table, String metric, long ts, int value, String... dims) { table.add(ImmutableList.of(new Fact(ts, dimValues(dims), new Measurement(metric, MeasureType.COUNTER, value)))); }
@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); }
new Measurement("metric1", MeasureType.COUNTER, 1)))); new Measurement("metric1", MeasureType.COUNTER, 1)))); new Measurement("metric1", MeasureType.COUNTER, 1))));
new Measurement("metric" + k, MeasureType.COUNTER, k)))); for (int k = 1; k < 4; k++) { table.add(ImmutableList.of(new Fact(ts + resolution * i + i, dimensionValues, new Measurement("metric" + k, MeasureType.COUNTER, 2 * k)))); for (int i = 0; i < 7; i++) { for (int k = 1; k < 4; k++) { aggs.add(new Fact(ts + resolution, dimensionValues, new Measurement("metric" + k, MeasureType.COUNTER, 3 * k))); for (int k = 1; k < 4; k++) { aggs.add(new Fact(ts + resolution * i, dimensionValues, new Measurement("metric" + k, MeasureType.COUNTER, 4 * k))); new DimensionValue("dim2", "value5"), new DimensionValue("dim3", null)); table.add(ImmutableList.of(new Fact(ts, dimensionValues, new Measurement("metric", MeasureType.COUNTER, 10)))); table.add(ImmutableList.of(new Fact(ts, dimensionValues, new Measurement("metric", MeasureType.COUNTER, 10))));
List<Fact> metrics = new ArrayList<>(); for (int i = 0; i < 10; i++) { metrics.add(new Fact(timestampNow, dims, new Measurement("metric" + i, MeasureType.COUNTER, 1))); metrics.add(new Fact(timestampNow - 5, dims, new Measurement("metric" + i, MeasureType.COUNTER, 1))); metrics.add(new Fact(timestampNow + 5, dims, new Measurement("metric" + i, MeasureType.COUNTER, 1)));