@Override public void apply() { delegate.add(fact); } });
@Override public void apply() { delegate.add(facts); } });
/** * Adds facts to a {@link Cube} as defined by {@link Cube#add(java.util.Collection)}. */ @Path("add") @POST public void addFact(HttpServiceRequest request, HttpServiceResponder responder) { try { String body = Bytes.toString(request.getContent()); Collection<CubeFact> facts = GSON.fromJson(body, CUBE_FACT_COLLECTION); getCube().add(facts); responder.sendStatus(200); } catch (Throwable th) { LOG.error("Error while executing request", th); responder.sendError(500, th.getMessage()); } }
protected void writeInc(Cube cube, String mearsureName, long ts, long value, Map<String, String> dims) throws Exception { cube.add(getFact(mearsureName, ts, value, MeasureType.COUNTER, dims)); }
protected void writeGauge(Cube cube, String measureName, long ts, long value, String... dims) throws Exception { cube.add(getFact(measureName, ts, value, MeasureType.GAUGE, dims)); }
protected void writeInc(Cube cube, String measureName, long ts, long value, String... dims) throws Exception { cube.add(getFact(measureName, ts, value, MeasureType.COUNTER, dims)); }
@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); }
writeIncViaBatchWritable(cube, "metric1", 9, 1, null, null, null); cube.add(ImmutableList.of( getFact("metric1", 10, 2, MeasureType.COUNTER, "1", "1", "1", "1"), getFact("metric1", 11, 3, MeasureType.COUNTER, "1", "1", "1", null),