本文整理了Java中com.netflix.spectator.api.Utils
类的一些代码示例,展示了Utils
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils
类的具体详情如下:
包路径:com.netflix.spectator.api.Utils
类名称:Utils
[英]Helper functions for working with a sequence of measurements.
[中]用于处理测量序列的辅助函数。
代码示例来源:origin: apache/servicecomb-java-chassis
protected void readMeasurement(String name, Setter setter) {
MeasurementNode node = tree.findChild(name);
if (node == null) {
return;
}
for (Measurement measurement : node.getMeasurements()) {
String threadPoolName = Utils.getTagValue(measurement.id(), ThreadPoolMonitor.ID_TAG_NAME);
if (threadPoolName == null) {
continue;
}
ThreadPoolPublishModel model = threadPools.computeIfAbsent(threadPoolName, tpn -> {
return new ThreadPoolPublishModel();
});
setter.set(model, measurement);
}
}
}
代码示例来源:origin: Netflix/spectator
/**
* Returns the first measurement with a given tag value.
*
* @param ms
* A set of measurements.
* @param k
* Key to search for.
* @param v
* Value that should be associated with k on the ids.
* @return
* Measurement or null if no matches are found.
*/
public static Measurement first(final Iterable<Measurement> ms, final String k, final String v) {
return first(ms, value -> v.equals(getTagValue(value.id(), k)));
}
代码示例来源:origin: Netflix/spectator
/** Return the number of inflight requests associated with the given id. */
AtomicInteger inflightRequests(Id id) {
return Utils.computeIfAbsent(inflightRequests, id, i -> new AtomicInteger());
}
代码示例来源:origin: Netflix/spectator
/**
* Returns a new iterable restricted to measurements that match the predicate.
*
* @param ms
* A set of measurements.
* @param k
* Key to search for.
* @param v
* Value that should be associated with k on the ids.
* @return
* Measurements matching the predicate.
*/
public static Iterable<Measurement> filter(
final Iterable<Measurement> ms, final String k, final String v) {
return filter(ms, value -> v.equals(getTagValue(value.id(), k)));
}
代码示例来源:origin: com.netflix.spectator/spectator-api
/**
* Create a new instance.
*
* @param registry
* Registry to use.
* @param id
* Identifier for the metric being registered.
* @return
* Counter instance.
*/
public static IntervalCounter get(Registry registry, Id id) {
ConcurrentMap<Id, Object> state = registry.state();
Object c = Utils.computeIfAbsent(state, id, i -> new IntervalCounter(registry, i));
if (!(c instanceof IntervalCounter)) {
Utils.propagateTypeError(registry, id, IntervalCounter.class, c.getClass());
c = new IntervalCounter(new NoopRegistry(), id);
}
return (IntervalCounter) c;
}
代码示例来源:origin: Netflix/spectator
/**
* Returns the first measurement with a given tag value.
*
* @param ms
* A set of measurements.
* @param t
* The key and value to search for.
* @return
* Measurement or null if no matches are found.
*/
public static Measurement first(Iterable<Measurement> ms, Tag t) {
return first(ms, t.key(), t.value());
}
代码示例来源:origin: Netflix/spectator
/** Return a method supplying a value for a gauge. */
static Method getGaugeMethod(Registry registry, Id id, Object obj, String method) {
try {
final Method m = Utils.getMethod(obj.getClass(), method);
try {
// Make sure we can cast the response to a Number
final Number n = (Number) m.invoke(obj);
REGISTRY_LOGGER.debug(
"registering gauge {}, using method [{}], with initial value {}", id, m, n);
return m;
} catch (Exception e) {
final String msg = "exception thrown invoking method [" + m
+ "], skipping registration of gauge " + id;
registry.propagate(msg, e);
}
} catch (NoSuchMethodException e) {
final String mname = obj.getClass().getName() + "." + method;
final String msg = "invalid method [" + mname + "], skipping registration of gauge " + id;
registry.propagate(msg, e);
}
return null;
}
代码示例来源:origin: Netflix/spectator
@Test
public void filterPredicateEmpty() {
List<Measurement> ms = newList(10);
List<Measurement> out = Utils.toList(Utils.filter(ms, v -> false));
Assertions.assertEquals(0, out.size());
}
}
代码示例来源:origin: com.netflix.spectator/spectator-api
/**
* Returns the first measurement that matches the predicate.
*
* @param ms
* A set of measurements.
* @param p
* Predicate to use for selecting values.
* @return
* Measurement or null if no matches are found.
*/
public static Measurement first(Iterable<Measurement> ms, Predicate<Measurement> p) {
Iterator<Measurement> it = filter(ms, p).iterator();
return it.hasNext() ? it.next() : null;
}
代码示例来源:origin: Netflix/spectator
/** Create a new instance. */
public MetricsRegistry(Clock clock, com.codahale.metrics.MetricRegistry impl) {
this(clock, impl, id -> {
Id normalized = Utils.normalize(id);
StringBuilder buf = new StringBuilder();
buf.append(normalized.name());
for (Tag t : normalized.tags()) {
buf.append('.').append(t.key()).append('-').append(t.value());
}
return buf.toString();
});
}
代码示例来源:origin: com.netflix.spectator/spectator-api
/**
* Returns a new iterable restricted to measurements that match the predicate.
*
* @param ms
* A set of measurements.
* @param k
* Key to search for.
* @param v
* Value that should be associated with k on the ids.
* @return
* Measurements matching the predicate.
*/
public static Iterable<Measurement> filter(
final Iterable<Measurement> ms, final String k, final String v) {
return filter(ms, value -> v.equals(getTagValue(value.id(), k)));
}
代码示例来源:origin: Netflix/spectator
/**
* Create a new instance.
*
* @param registry
* Registry to use.
* @param id
* Identifier for the metric being registered.
* @return
* Counter instance.
*/
public static IntervalCounter get(Registry registry, Id id) {
ConcurrentMap<Id, Object> state = registry.state();
Object c = Utils.computeIfAbsent(state, id, i -> new IntervalCounter(registry, i));
if (!(c instanceof IntervalCounter)) {
Utils.propagateTypeError(registry, id, IntervalCounter.class, c.getClass());
c = new IntervalCounter(new NoopRegistry(), id);
}
return (IntervalCounter) c;
}
代码示例来源:origin: com.netflix.spectator/spectator-api
/**
* Returns the first measurement with a given tag value.
*
* @param ms
* A set of measurements.
* @param t
* The key and value to search for.
* @return
* Measurement or null if no matches are found.
*/
public static Measurement first(Iterable<Measurement> ms, Tag t) {
return first(ms, t.key(), t.value());
}
代码示例来源:origin: com.netflix.spectator/spectator-api
/** Return a method supplying a value for a gauge. */
static Method getGaugeMethod(Registry registry, Id id, Object obj, String method) {
try {
final Method m = Utils.getMethod(obj.getClass(), method);
try {
// Make sure we can cast the response to a Number
final Number n = (Number) m.invoke(obj);
REGISTRY_LOGGER.debug(
"registering gauge {}, using method [{}], with initial value {}", id, m, n);
return m;
} catch (Exception e) {
final String msg = "exception thrown invoking method [" + m
+ "], skipping registration of gauge " + id;
registry.propagate(msg, e);
}
} catch (NoSuchMethodException e) {
final String mname = obj.getClass().getName() + "." + method;
final String msg = "invalid method [" + mname + "], skipping registration of gauge " + id;
registry.propagate(msg, e);
}
return null;
}
代码示例来源:origin: Netflix/spectator
@Test
public void filterTag() {
List<Measurement> ms = newList(10);
Tag t = new BasicTag("i", "7");
List<Measurement> out = Utils.toList(Utils.filter(ms, t));
Assertions.assertEquals(1, out.size());
Assertions.assertEquals(out.get(0).id().tags(), ArrayTagSet.create(t));
}
代码示例来源:origin: Netflix/spectator
/**
* Returns the first measurement that matches the predicate.
*
* @param ms
* A set of measurements.
* @param p
* Predicate to use for selecting values.
* @return
* Measurement or null if no matches are found.
*/
public static Measurement first(Iterable<Measurement> ms, Predicate<Measurement> p) {
Iterator<Measurement> it = filter(ms, p).iterator();
return it.hasNext() ? it.next() : null;
}
代码示例来源:origin: com.netflix.spectator/spectator-reg-metrics3
/** Create a new instance. */
public MetricsRegistry(Clock clock, com.codahale.metrics.MetricRegistry impl) {
this(clock, impl, id -> {
Id normalized = Utils.normalize(id);
StringBuilder buf = new StringBuilder();
buf.append(normalized.name());
for (Tag t : normalized.tags()) {
buf.append('.').append(t.key()).append('-').append(t.value());
}
return buf.toString();
});
}
代码示例来源:origin: Netflix/spectator
private static boolean isPercentile(Id id) {
final String stat = Utils.getTagValue(id, "statistic");
return "percentile".equals(stat);
}
代码示例来源:origin: com.netflix.spectator/spectator-api
/**
* Returns the first measurement with a given tag value.
*
* @param ms
* A set of measurements.
* @param k
* Key to search for.
* @param v
* Value that should be associated with k on the ids.
* @return
* Measurement or null if no matches are found.
*/
public static Measurement first(final Iterable<Measurement> ms, final String k, final String v) {
return first(ms, value -> v.equals(getTagValue(value.id(), k)));
}
代码示例来源:origin: Netflix/spectator
/**
* Provided for backwards compatibility to support the {@link Registry#register(Meter)}
* method. Use the builder created with {@link #using(Registry)} instead.
*
* @deprecated This method only exists to allow for backwards compatibility and should
* be considered an internal detail. Scheduled to be removed in 2.0.
*/
@Deprecated
public static void monitorMeter(Registry registry, Meter meter) {
ConcurrentMap<Id, Object> state = registry.state();
Object c = Utils.computeIfAbsent(state, meter.id(), MeterState::new);
if (!(c instanceof MeterState)) {
Utils.propagateTypeError(registry, meter.id(), MeterState.class, c.getClass());
} else {
MeterState t = (MeterState) c;
t.add(meter);
long delay = registry.config().gaugePollingFrequency().toMillis();
t.schedule(registry, null, delay);
}
}
内容来源于网络,如有侵权,请联系作者删除!