本文整理汇总了Java中com.yammer.metrics.core.Metric类的典型用法代码示例。如果您正苦于以下问题:Java Metric类的具体用法?Java Metric怎么用?Java Metric使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Metric类属于com.yammer.metrics.core包,在下文中一共展示了Metric类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import com.yammer.metrics.core.Metric; //导入依赖的package包/类
@Override
public void run() {
for (Map.Entry<String, SortedMap<MetricName, Metric>> entry : getMetricsRegistry().groupedMetrics(
MetricPredicate.ALL).entrySet()) {
try {
for (Map.Entry<MetricName, Metric> subEntry : entry.getValue().entrySet()) {
out.print(" " + subEntry.getKey().getName());
out.println(':');
subEntry.getValue().processWith(this, subEntry.getKey(), out);
}
} catch (Exception e) {
e.printStackTrace(out);
}
}
}
示例2: onMetricAdded
import com.yammer.metrics.core.Metric; //导入依赖的package包/类
/**
* New metric added to the Yammer Metrics registry.
*
* Note that Kafka uses the default registry, so there can be non-Kafka metrics there
* as well. This function ignores any metric whose group does not start with {@code 'kafka'}.
*
* @param metricName
* @param metric
*/
public void onMetricAdded(MetricName metricName, Metric metric) {
// The default registry can have non-Kafka metrics. Filter those out.
if (!metricName.getGroup().startsWith("kafka")) {
return;
}
MetricInfo mi = process(metric, metricName);
if (mi != null) {
synchronized (listeners) {
for (KafkaMetricsListener listener : listeners) {
listener.onKafkaMetricAdded(mi);
}
}
} else {
// metric not recognized
System.err.println("Unrecognized Kafka metric: " + metricName.toString()
+ "\n group: " + metricName.getGroup()
+ "\n type: " + metricName.getType()
+ "\n name: " + metricName.getName()
+ "\n scope: " + metricName.getScope()
);
}
}
示例3: getStats
import com.yammer.metrics.core.Metric; //导入依赖的package包/类
@ManagedAttribute
public Map<String, Object> getStats() {
Map<String, Object> stats = new HashMap<String, Object>();
MetricsRegistry registry = Metrics.defaultRegistry();
for (Entry<MetricName, Metric> e : registry.allMetrics().entrySet()) {
MetricName name = e.getKey();
Metric metric = e.getValue();
if (metric instanceof Meter) {
Meter m = (Meter) metric;
stats.put(name.toString(), new MeterPOJO(m));
} else if (metric instanceof Gauge) {
Gauge<?> g = (Gauge<?>) metric;
stats.put(name.toString(), g.value());
}
}
return stats;
}
示例4: matches
import com.yammer.metrics.core.Metric; //导入依赖的package包/类
@Override
public boolean matches(MetricName name, Metric metric) {
String metricName = sanitizeName(name);
boolean isVersionMetric = APPVERSION_PATTERN.matcher(metricName).matches();
if (isVersionMetric || cleanInvalidGauge(name, metric, metricName)) {
return false;
}
if (pattern != null) {
return !pattern.matcher(metricName).matches();
}
return true;
}
示例5: keepGaugesIfTheyThrowRuntimeExceptions
import com.yammer.metrics.core.Metric; //导入依赖的package包/类
@Test
public void keepGaugesIfTheyThrowRuntimeExceptions() throws Exception {
MetricPredicate predicate = new FilterMetricPredicate();
MetricName metricName = new MetricName("test", "test", "delete", "scope", "mBeanName");
Metric gauge = Metrics.newGauge(metricName, new Gauge<Long>() {
@Override
public Long value() {
throw new RuntimeException("catch me if you can");
}
});
assertTrue(predicate.matches(metricName, gauge));
assertTrue("The gauge should be there", Metrics.defaultRegistry().allMetrics().containsKey(metricName));
assertEquals(Metrics.defaultRegistry().allMetrics().get(metricName), gauge);
}
示例6: printRegularMetrics
import com.yammer.metrics.core.Metric; //导入依赖的package包/类
protected void printRegularMetrics(long epoch) {
for (Map.Entry<String, SortedMap<MetricName, Metric>> entry : getMetricsRegistry().groupedMetrics(predicate)
.entrySet()) {
for (Map.Entry<MetricName, Metric> subEntry : entry.getValue().entrySet()) {
final Metric metric = subEntry.getValue();
if (metric != null) {
try {
log.info("Trying to process " + entry.getKey());
metric.processWith(this, subEntry.getKey(), epoch);
} catch (Exception ignored) {
log.error("Error printing regular metrics:", ignored);
}
}
}
}
}
示例7: getProperty
import com.yammer.metrics.core.Metric; //导入依赖的package包/类
public static Property getProperty(final Property propertyOrNull, final Metric metric) {
if (propertyOrNull != null) {
return propertyOrNull;
} else {
// is null, find a default
if (metric instanceof Counter) {
return CounterProperty.COUNT;
} else if (metric instanceof Gauge) {
return GaugeProperty.VALUE_GAUGE;
} else if (metric instanceof Timer) {
return TimerProperty.MEDIAN;
} else if (metric instanceof Meter) {
return MeterProperty.FIVE_MINUTE_RATE;
} else if (metric instanceof Histogram) {
return HistogramProperty.MEDIAN;
} else {
throw new RuntimeException("Unexpected metric type: " + metric.getClass());
}
}
}
示例8: getNumber
import com.yammer.metrics.core.Metric; //导入依赖的package包/类
public Number getNumber(final Metric metric, final Snapshot none) {
if (metric instanceof Meter) {
Meter meter = (Meter) metric;
switch(this) {
case COUNT:
return meter.count();
case ONE_MINUTE_RATE:
return meter.oneMinuteRate();
case FIVE_MINUTE_RATE:
return meter.fiveMinuteRate();
case FIFTEEN_MINUTE_RATE:
return meter.fifteenMinuteRate();
case MEAN_RATE:
return meter.meanRate();
default:
throw new RuntimeException("Unexpected property");
}
} else {
throw new IllegalArgumentException("Invalid metric for property");
}
}
示例9: testGetMetricNames
import com.yammer.metrics.core.Metric; //导入依赖的package包/类
@Test
public void testGetMetricNames() throws Exception {
final MetricName name1 = mock(MetricName.class);
final MetricName name2 = mock(MetricName.class);
final MetricName name3 = mock(MetricName.class);
final MetricFilter filter = mock(MetricFilter.class);
when(filter.matches(name1)).thenReturn(true);
when(filter.matches(name2)).thenReturn(true);
when(filter.matches(name3)).thenReturn(false);
final MetricsRegistry registry = mock(MetricsRegistry.class);
final Map<MetricName, Metric> metrics = new HashMap<MetricName, Metric>();
metrics.put(name1, mock(Metric.class));
metrics.put(name2, mock(Metric.class));
metrics.put(name3, mock(Metric.class));
when(registry.allMetrics()).thenReturn(metrics);
final WildcardMuninDataSource dataSource = new WildcardMuninDataSource(
filter, null, null, mock(MuninDataSourceConfig.class));
assertListEqualsUnordered(Arrays.asList(name1, name2), dataSource.getMetricNames(registry));
}
示例10: getValueAndReset
import com.yammer.metrics.core.Metric; //导入依赖的package包/类
/**
* Returns a Map representing all the Yammer metrics managed by this facade metric.
*
* @return A Map which is in fact a snapshot of all the Yammer metrics managed by this facade metric.
*/
@Override
public Object getValueAndReset() {
final Map metricsValues = new HashMap();
for (final Map.Entry<MetricName, Metric> entry : metricsRegistry.allMetrics().entrySet()) {
try {
entry.getValue().processWith(METRIC_SERIALIZER, entry.getKey(), metricsValues);
} catch (final Exception e) {
// log?
}
}
return metricsValues;
}
示例11: processHistogram
import com.yammer.metrics.core.Metric; //导入依赖的package包/类
@Override
public void processHistogram(MetricName name, Histogram histogram,
ConcurrentMap<String, org.apache.blur.thrift.generated.Metric> context) throws Exception {
org.apache.blur.thrift.generated.Metric metric = getMetric(name, context);
metric.putToDoubleMap("min", histogram.min());
metric.putToDoubleMap("max", histogram.max());
metric.putToDoubleMap("mean", histogram.mean());
metric.putToDoubleMap("stdDev", histogram.stdDev());
Snapshot snapshot = histogram.getSnapshot();
metric.putToDoubleMap("median", snapshot.getMedian());
metric.putToDoubleMap("75%", snapshot.get75thPercentile());
metric.putToDoubleMap("95%", snapshot.get95thPercentile());
metric.putToDoubleMap("98%", snapshot.get98thPercentile());
metric.putToDoubleMap("99%", snapshot.get99thPercentile());
metric.putToDoubleMap("99.9%", snapshot.get999thPercentile());
}
示例12: processTimer
import com.yammer.metrics.core.Metric; //导入依赖的package包/类
@Override
public void processTimer(MetricName name, Timer timer,
ConcurrentMap<String, org.apache.blur.thrift.generated.Metric> context) throws Exception {
org.apache.blur.thrift.generated.Metric metric = getMetric(name, context);
addMeter(metric, timer, context);
metric.putToStrMap("unit", timer.durationUnit().toString());
metric.putToDoubleMap("min", timer.min());
metric.putToDoubleMap("max", timer.max());
metric.putToDoubleMap("mean", timer.mean());
metric.putToDoubleMap("stdDev", timer.stdDev());
Snapshot snapshot = timer.getSnapshot();
metric.putToDoubleMap("median", snapshot.getMedian());
metric.putToDoubleMap("75%", snapshot.get75thPercentile());
metric.putToDoubleMap("95%", snapshot.get95thPercentile());
metric.putToDoubleMap("98%", snapshot.get98thPercentile());
metric.putToDoubleMap("99%", snapshot.get99thPercentile());
metric.putToDoubleMap("99.9%", snapshot.get999thPercentile());
}
示例13: getCumulativeCounter
import com.yammer.metrics.core.Metric; //导入依赖的package包/类
private static Metric getCumulativeCounter(MetricsRegistry metricsRegistry,
MetricMetadata metricMetadata) {
MetricName counterCallbackName = new MetricName(YammerExample.class, "yammer.test.cumulativeCounter");
Metric cumulativeCounter = SfUtil.cumulativeCounter(
metricsRegistry,
counterCallbackName,
metricMetadata,
new Gauge<Long>() {
private long i = 0;
@Override
public Long value() {
return i++;
}
});
metricMetadata.forMetric(cumulativeCounter)
.withSourceName(SIGNAL_FX)
.withDimension(LIBRARY_VERSION, YAMMER);
return cumulativeCounter;
}
示例14: getMetrics
import com.yammer.metrics.core.Metric; //导入依赖的package包/类
/**
* get Metrics by class and predicate
*
* @param klass
* @param filter
* @return
*/
@SuppressWarnings("unchecked")
private <T extends Metric> SortedMap<MetricName, T> getMetrics(Class<T> klass, MetricPredicate filter) {
Map<MetricName, Metric> allMetrics = registry.allMetrics();
final TreeMap<MetricName, T> timers = new TreeMap<MetricName, T>();
for (Map.Entry<MetricName, Metric> entry : allMetrics.entrySet()) {
if (klass.isInstance(entry.getValue()) && filter.matches(entry.getKey(),
entry.getValue())) {
timers.put(entry.getKey(), (T) entry.getValue());
}
}
return Collections.unmodifiableSortedMap(timers);
}
示例15: processAll
import com.yammer.metrics.core.Metric; //导入依赖的package包/类
/**
* @param metrics The metrics you want to process
* @return A string of table rows.
*/
public String processAll(Map<MetricName, Metric> metrics) {
StringBuilder sb = new StringBuilder();
for (Entry<MetricName, Metric> metric : metrics.entrySet()) {
if (metric.getValue() instanceof Metered) {
if (metric.getValue() instanceof Timer) {
processTimer(metric.getKey(), (Timer) metric.getValue(), sb);
} else {
processMeter(metric.getKey(), (Metered) metric.getValue(), sb);
}
} else if (metric.getValue() instanceof Counter) {
processCounter(metric.getKey(), (Counter) metric.getValue(), sb);
} else if (metric.getValue() instanceof Histogram) {
processHistogram(metric.getKey(), (Histogram) metric.getValue(), sb);
} else if (metric.getValue() instanceof Gauge) {
processGauge(metric.getKey(), (Gauge<?>) metric.getValue(), sb);
} else {
throw new IllegalStateException("Unknown metric " + metric);
}
}
return sb.toString();
}