Java Code Examples for com.netflix.spectator.api.Measurement#value()
The following examples show how to use
com.netflix.spectator.api.Measurement#value() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PolledMeter.java From spectator with Apache License 2.0 | 6 votes |
private Iterable<Measurement> measure() { Map<Id, Measurement> measurements = new HashMap<>(); Iterator<Meter> iter = queue.iterator(); while (iter.hasNext()) { Meter meter = iter.next(); if (meter.hasExpired()) { iter.remove(); } else { for (Measurement m : meter.measure()) { Measurement prev = measurements.get(m.id()); if (prev == null) { measurements.put(m.id(), m); } else { double v = prev.value() + m.value(); measurements.put(prev.id(), new Measurement(prev.id(), prev.timestamp(), v)); } } } } if (queue.isEmpty()) { LOGGER.trace("meter [{}] has expired", id); } return measurements.values(); }
Example 2
Source File: SpectatorDistributionSummary.java From micrometer with Apache License 2.0 | 5 votes |
@Override public double max() { for (Measurement measurement : summary.measure()) { if (stream(measurement.id().tags().spliterator(), false) .anyMatch(tag -> tag.key().equals("statistic") && tag.value().equals(Statistic.max.toString()))) { return measurement.value(); } } return Double.NaN; }
Example 3
Source File: PrometheusPublisher.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
protected Sample convertMeasurementToSample(Measurement measurement) { String prometheusName = measurement.id().name().replace(".", "_"); List<String> labelNames = new ArrayList<>(); List<String> labelValues = new ArrayList<>(); labelNames.add("appId"); labelValues.add(RegistrationManager.INSTANCE.getAppId()); for (Tag tag : measurement.id().tags()) { labelNames.add(tag.key()); labelValues.add(tag.value()); } return new Sample(prometheusName, labelNames, labelValues, measurement.value()); }
Example 4
Source File: MeasurementNode.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
public double summary() { double result = 0; for (Measurement measurement : measurements) { result += measurement.value(); } return result; }
Example 5
Source File: TestMeasurementNode.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
@Test public void summary(@Mocked Measurement measurement) { new Expectations() { { measurement.value(); result = 10; } }; node.addMeasurement(measurement); node.addMeasurement(measurement); Assert.assertEquals(20, node.summary(), 0); }
Example 6
Source File: StackdriverWriter.java From kork with Apache License 2.0 | 5 votes |
/** * Convert a Spectator metric Meter into a Stackdriver TimeSeries entry. * * @param descriptorType The Stackdriver MetricDescriptorType name for the measurement. * @param measurement The Spectator Measurement to encode. * @return The Stackdriver TimeSeries equivalent for the measurement. */ public TimeSeries measurementToTimeSeries( String descriptorType, Registry registry, Meter meter, Measurement measurement) { Map<String, String> labels = cache.tagsToTimeSeriesLabels(descriptorType, measurement.id().tags()); long millis = measurement.timestamp(); double value = measurement.value(); TimeInterval timeInterval = new TimeInterval(); Date date = new Date(millis); timeInterval.setEndTime(rfc3339.format(date)); String descriptorKind = cache.descriptorTypeToKind(descriptorType, registry, meter); if (descriptorKind == "CUMULATIVE") { timeInterval.setStartTime(counterStartTimeRfc3339); } TypedValue typedValue = new TypedValue(); typedValue.setDoubleValue(value); Point point = new Point(); point.setValue(typedValue); point.setInterval(timeInterval); Metric metric = new Metric(); metric.setType(descriptorType); metric.setLabels(labels); TimeSeries ts = new TimeSeries(); ts.setResource(monitoredResource); ts.setMetric(metric); ts.setMetricKind(descriptorKind); ts.setValueType("DOUBLE"); ts.setPoints(Lists.<Point>newArrayList(point)); return ts; }
Example 7
Source File: DoubleDistributionSummaryTest.java From spectator with Apache License 2.0 | 5 votes |
@Test public void testMeasureZeroToOne() { double[] values = { 0.1, 0.2, 0.7, 0.8, 0.1, 0.4, 0.6, 0.9, 0.1, 1.0, 0.0, 0.5, 0.4 }; DoubleDistributionSummary s = newInstance(); for (double v : values) { s.record(v); } clock.setWallTime(65000L); double t = 0.0; double t2 = 0.0; double n = 0.0; double max = 0.0; for (Measurement m : s.measure()) { switch (get(m.id(), "statistic")) { case "count": n = m.value(); break; case "totalAmount": t = m.value(); break; case "totalOfSquares": t2 = m.value(); break; case "max": max = m.value(); break; default: Assertions.fail("unexpected id: " + m.id()); break; } } Assertions.assertEquals(1.0, max, 1e-12); Assertions.assertEquals(stddev(values), Math.sqrt((n * t2 - t * t) / (n * n)), 1e-12); }
Example 8
Source File: Rollups.java From spectator with Apache License 2.0 | 5 votes |
private static Aggregator newAggregator(Id id, Measurement m) { DoubleBinaryOperator af = MAX; String statistic = Utils.getTagValue(id, "statistic"); if (statistic != null && SUM_STATS.contains(statistic)) { af = SUM; } return new Aggregator(id, m.timestamp(), af, m.value()); }
Example 9
Source File: DataExprTest.java From spectator with Apache License 2.0 | 5 votes |
private TagsValuePair newTagsValuePair(Measurement m) { Map<String, String> tags = new HashMap<>(); for (Tag t : m.id().tags()) { tags.put(t.key(), t.value()); } tags.put("name", m.id().name()); return new TagsValuePair(tags, m.value()); }
Example 10
Source File: EvaluatorTest.java From spectator with Apache License 2.0 | 5 votes |
private TagsValuePair newTagsValuePair(Measurement m) { Map<String, String> tags = new HashMap<>(); for (Tag t : m.id().tags()) { tags.put(t.key(), t.value()); } tags.put("name", m.id().name()); return new TagsValuePair(tags, m.value()); }
Example 11
Source File: SpectatorReporterTest.java From spectator with Apache License 2.0 | 5 votes |
private long getValue(String name) { Meter meter = registry.get(registry.createId(name)); if (meter != null) { for (Measurement m : meter.measure()) { return (long) m.value(); } } return Long.MAX_VALUE; }
Example 12
Source File: DataPoint.java From spectator with Apache License 2.0 | 4 votes |
/** * Factory method to create a DataPoint from a Measurement. */ public static DataPoint make(Measurement m) { return new DataPoint(m.timestamp(), m.value()); }