本文整理了Java中com.netflix.spectator.api.Measurement.<init>()
方法的一些代码示例,展示了Measurement.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Measurement.<init>()
方法的具体详情如下:
包路径:com.netflix.spectator.api.Measurement
类名称:Measurement
方法名:<init>
[英]Create a new instance.
[中]创建一个新实例。
代码示例来源:origin: Netflix/servo
private void addMeasurements(Monitor<?> m, List<Measurement> measurements) {
// Skip any that will report directly
if (!(m instanceof SpectatorMonitor)) {
if (m instanceof CompositeMonitor<?>) {
CompositeMonitor<?> cm = (CompositeMonitor<?>) m;
for (Monitor<?> v : cm.getMonitors()) {
addMeasurements(v, measurements);
}
} else if (!isCounter(m.getConfig())) {
try {
Object obj = m.getValue();
if (obj instanceof Number) {
double value = ((Number) obj).doubleValue();
// timestamp will get ignored as the value will get forwarded to a gauge
Measurement v = new Measurement(createId(m.getConfig()), 0L, value);
measurements.add(v);
}
} catch (Throwable t) {
LOGGER.warn("Exception while querying user defined gauge ({}), "
+ "the value will be ignored. The owner of the user defined "
+ "function should fix it to not propagate an exception.", m.getConfig(), t);
}
}
}
}
代码示例来源:origin: apache/servicecomb-java-chassis
protected Measurement newMeasurement(Id id, long timestamp, Number n) {
return new Measurement(id, timestamp, n.doubleValue());
}
代码示例来源:origin: apache/servicecomb-java-chassis
private Measurement newMeasurement(Id id, long msNow, Number n) {
return new Measurement(id, msNow, n.doubleValue());
}
代码示例来源:origin: apache/servicecomb-java-chassis
public void calcMeasurements(List<Measurement> measurements, long msNow) {
netStats.forEach(netStat -> {
measurements.add(new Measurement(netStat.getId(), msNow, netStat.getRate()));
});
}
代码示例来源:origin: apache/servicecomb-java-chassis
public void calcMeasurements(List<Measurement> measurements, long msNow) {
update();
measurements.add(new Measurement(allCpuUsage.getId(), msNow, allCpuUsage.getUsage()));
measurements.add(new Measurement(processCpuUsage.getId(), msNow, processCpuUsage.getUsage()));
}
代码示例来源:origin: Netflix/spectator
@Override public Iterable<Measurement> measure() {
final long now = clock.wallTime();
final List<Measurement> ms = new ArrayList<>(2);
ms.add(new Measurement(id.withTag(Statistic.count), now, count.get()));
ms.add(new Measurement(id.withTag(Statistic.totalAmount), now, totalAmount.get()));
return ms;
}
代码示例来源:origin: Netflix/spectator
@Override public Iterable<Measurement> measure() {
final long now = clock.wallTime();
final List<Measurement> ms = new ArrayList<>(2);
ms.add(new Measurement(id.withTag(Statistic.count), now, count.get()));
ms.add(new Measurement(id.withTag(Statistic.totalTime), now, totalTime.get()));
return ms;
}
代码示例来源:origin: Netflix/spectator
@Override public Iterable<Measurement> measure() {
final double delta = value.getAndSet(0.0);
if (delta > 0.0) {
final Measurement m = new Measurement(stat, clock.wallTime(), delta);
return Collections.singletonList(m);
} else {
return Collections.emptyList();
}
}
}
代码示例来源:origin: Netflix/spectator
private Measurement newMeasurement(Id mid, StepValue v, double f) {
// poll needs to be called before accessing the timestamp to ensure
// the counters have been rotated if there was no activity in the
// current interval.
double rate = v.pollAsRate() * f;
long timestamp = v.timestamp();
return new Measurement(mid, timestamp, rate);
}
代码示例来源:origin: Netflix/spectator
private Measurement newMeasurement(Id mid, LongToDoubleFunction getAndSet) {
double delta = getAndSet.applyAsDouble(0);
long timestamp = clock.wallTime();
return new Measurement(mid, timestamp, delta);
}
}
代码示例来源:origin: Netflix/spectator
@Override public Iterable<Measurement> measure() {
long now = clock.wallTime();
double v = impl.getValue(0).doubleValue();
return Collections.singleton(new Measurement(id(), now, v));
}
代码示例来源:origin: Netflix/spectator
private Measurement newMaxMeasurement(Id mid, StepLong v) {
// poll needs to be called before accessing the timestamp to ensure
// the counters have been rotated if there was no activity in the
// current interval.
double maxValue = v.poll() / 1e9;
long timestamp = v.timestamp();
return new Measurement(mid, timestamp, maxValue);
}
代码示例来源:origin: Netflix/spectator
@Override public Iterable<Measurement> measure() {
final long now = clock.wallTime();
final Snapshot snapshot = impl.getSnapshot();
return Collections.singleton(new Measurement(id, now, snapshot.getMean()));
}
代码示例来源:origin: Netflix/spectator
private List<TagsValuePair> data(String name, double... vs) {
List<Measurement> ms = new ArrayList<>();
for (int i = 0; i < vs.length; ++i) {
String pos = String.format("%03d", i);
String value = String.format("%f", vs[i]);
ms.add(new Measurement(registry.createId(name, "i", pos, "v", value), 0L, vs[i]));
}
return ms.stream().map(this::newTagsValuePair).collect(Collectors.toList());
}
代码示例来源:origin: Netflix/spectator
/** Helper for converting Micrometer measurements to Spectator measurements. */
Iterable<Measurement> convert(Iterable<io.micrometer.core.instrument.Measurement> ms) {
long now = Clock.SYSTEM.wallTime();
List<Measurement> measurements = new ArrayList<>();
for (io.micrometer.core.instrument.Measurement m : ms) {
Id measurementId = id.withTag("statistic", m.getStatistic().getTagValueRepresentation());
measurements.add(new Measurement(measurementId, now, m.getValue()));
}
return measurements;
}
}
代码示例来源:origin: Netflix/spectator
private List<TagsValuePair> data(String name, double... vs) {
List<Measurement> ms = new ArrayList<>();
for (int i = 0; i < vs.length; ++i) {
String pos = String.format("%03d", i);
String value = String.format("%f", vs[i]);
ms.add(new Measurement(registry.createId(name, "i", pos, "v", value), 0L, vs[i]));
}
return ms.stream().map(this::newTagsValuePair).collect(Collectors.toList());
}
代码示例来源:origin: Netflix/spectator
@Test
public void encode() throws Exception {
Id id = registry.createId("foo", "bar", "baz");
Measurement m = new Measurement(id, 42L, 3.0);
String json = mapper.writeValueAsString(m);
String tags = "{\"name\":\"foo\",\"bar\":\"baz\",\"atlas.dstype\":\"gauge\"}";
String expected = "{\"tags\":" + tags + ",\"timestamp\":42,\"value\":3.0}";
Assertions.assertEquals(expected, json);
}
代码示例来源:origin: Netflix/spectator
@Test
public void userTagName() throws Exception {
Id id = registry.createId("foo", "name", "bar");
Measurement m = new Measurement(id, 42L, 3.0);
String json = mapper.writeValueAsString(m);
String tags = "{\"name\":\"foo\",\"atlas.dstype\":\"gauge\"}";
String expected = "{\"tags\":" + tags + ",\"timestamp\":42,\"value\":3.0}";
Assertions.assertEquals(expected, json);
}
代码示例来源:origin: Netflix/spectator
@Test
public void valueCharsetOverrides() throws Exception {
Id id = registry.createId("foo", "bar", "abc^~def", "cluster", "abc^~def");
Measurement m = new Measurement(id, 42L, 3.0);
String json = mapper.writeValueAsString(m);
String tags = "{\"name\":\"foo\",\"bar\":\"abc__def\",\"cluster\":\"abc^~def\",\"atlas.dstype\":\"gauge\"}";
String expected = "{\"tags\":" + tags + ",\"timestamp\":42,\"value\":3.0}";
Assertions.assertEquals(expected, json);
}
代码示例来源:origin: Netflix/spectator
@Test
public void testToString() {
Id id = new DefaultId("foo");
Measurement m = new Measurement(id, 42L, 42.0);
Assertions.assertEquals(m.toString(), "Measurement(foo,42,42.0)");
}
}
内容来源于网络,如有侵权,请联系作者删除!