本文整理匯總了Java中com.codahale.metrics.MetricSet類的典型用法代碼示例。如果您正苦於以下問題:Java MetricSet類的具體用法?Java MetricSet怎麽用?Java MetricSet使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MetricSet類屬於com.codahale.metrics包,在下文中一共展示了MetricSet類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: buildTimer
import com.codahale.metrics.MetricSet; //導入依賴的package包/類
public synchronized GoTimer buildTimer() {
String name = generateName("timing");
GoTimer timer = getExistingTimer(name);
if (timer == null) {
timer = new GoTimer(name);
Map<String, Metric> map = new HashMap<>(1);
map.put(name, timer);
MetricSet set = () -> map;
try {
registry.registerAll(set);
} catch (Exception ex) {
//I haven't figured out a good solution around this...
}
}
return timer;
}
示例2: register
import com.codahale.metrics.MetricSet; //導入依賴的package包/類
/**
* Given a {@link Metric}, registers it under the given name.
*
* @param name the name of the metric
* @param metric the metric
* @param <T> the type of the metric
* @return {@code metric}
* @throws IllegalArgumentException if the name is already registered
*/
@SuppressWarnings("unchecked")
public final <T extends Metric> T register(final String name, final T metric)
throws IllegalArgumentException {
if(metric instanceof MetricSet) {
registerAll(name, (MetricSet) metric);
} else {
final Metric existing = metrics.putIfAbsent(name, metric);
if(existing == null) {
onMetricAdded(name, metric);
} else {
throw new IllegalArgumentException("A metric named " + name + " already exists");
}
}
return metric;
}
示例3: registerMetricSetImpl
import com.codahale.metrics.MetricSet; //導入依賴的package包/類
private void registerMetricSetImpl(MetricSet metricSet, String namespace) {
for (Map.Entry<String, Metric> entry : metricSet.getMetrics().entrySet()) {
if (entry.getValue() == null) {
continue;
}
if (MetricSet.class.isInstance(entry.getValue())) {
MetricSet innerMetricSet = MetricSet.class.cast(entry.getValue());
if (namespace == null) {
registerMetricSet(innerMetricSet, entry.getKey());
} else {
registerMetricSetImpl(innerMetricSet, MetricNamingUtil.join(namespace, entry.getKey()));
}
} else {
String name = null;
if (namespace == null) {
name = entry.getKey();
} else {
name = MetricNamingUtil.join(namespace, entry.getKey());
}
name = addPostfixIfNeeded(name, getPostfixForMetric(entry.getValue()));
metricRegistry.register(name, entry.getValue());
}
}
}
示例4: removeMetricSetImpl
import com.codahale.metrics.MetricSet; //導入依賴的package包/類
private void removeMetricSetImpl(MetricSet metricSet, String namespace) {
for (Map.Entry<String, Metric> entry : metricSet.getMetrics().entrySet()) {
if (entry.getValue() == null) {
continue;
}
if (MetricSet.class.isInstance(entry.getValue())) {
MetricSet innerMetricSet = MetricSet.class.cast(entry.getValue());
if (namespace == null) {
removeMetricSet(innerMetricSet, entry.getKey());
} else {
removeMetricSetImpl(innerMetricSet, MetricNamingUtil.join(namespace, entry.getKey()));
}
} else {
String name = null;
if (namespace == null) {
name = entry.getKey();
} else {
name = MetricNamingUtil.join(namespace, entry.getKey());
}
name = addPostfixIfNeeded(name, getPostfixForMetric(entry.getValue()));
metricRegistry.remove(name);
}
}
}
示例5: getMetricSet
import com.codahale.metrics.MetricSet; //導入依賴的package包/類
/**
* {@inheritDoc}
*/
@NonNull
@Override
public MetricSet getMetricSet() {
Jenkins jenkins = Jenkins.getInstance();
if (jenkins == null) {
throw new AssertionError("Jenkins is missing");
}
HealthChecker c = jenkins.getExtensionList(PeriodicWork.class).get(HealthChecker.class);
if (c == null) {
throw new AssertionError("HealthChecker is missing");
}
return metrics(
metric(name("jenkins", "health-check", "duration"), c.getHealthCheckDuration()),
metric(name("jenkins", "health-check", "count"), c.getHealthCheckCount()),
metric(name("jenkins", "health-check", "score"), c.getHealthCheckScore()),
metric(name("jenkins", "health-check", "inverse-score"), new DerivativeGauge<Double, Double>(c.getHealthCheckScore()) {
@Override
protected Double transform(Double value) {
return value == null ? null : 1.0 - value;
}
})
);
}
示例6: getMetricSet
import com.codahale.metrics.MetricSet; //導入依賴的package包/類
/**
* {@inheritDoc}
*/
@NonNull
@Override
public MetricSet getMetricSet() {
if (set == null || nextRefresh < System.currentTimeMillis()) {
Map<String, Metric> metrics = new LinkedHashMap<String, Metric>();
metrics.put(name("jenkins", "versions", "core"), new VersionGauge(Jenkins.VERSION));
final Jenkins jenkins = Jenkins.getInstance();
if (jenkins != null) {
final PluginManager pluginManager = jenkins.getPluginManager();
for (PluginWrapper p : pluginManager.getPlugins()) {
if (p.isActive()) {
metrics.put(name("jenkins", "versions", "plugin", p.getShortName()),
new VersionGauge(p.getVersion()));
}
}
}
set = metrics(metrics); // idempotent
nextRefresh = System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(15);
}
return set;
}
示例7: convert
import com.codahale.metrics.MetricSet; //導入依賴的package包/類
public static Metric2Set convert(final MetricSet metricSet, final MetricNameConverter converter) {
return new Metric2Set() {
@Override
public Map<MetricName, Metric> getMetrics() {
final HashMap<MetricName, Metric> result = new HashMap<MetricName, Metric>();
for (Map.Entry<String, Metric> entry : metricSet.getMetrics().entrySet()) {
final MetricName convertedName;
try {
convertedName = converter.convert(entry.getKey());
result.put(convertedName, entry.getValue());
} catch (Exception e) {
e.printStackTrace();
logger.warn("Invalid name " + entry.getKey());
logger.debug(e.getMessage(), e);
}
}
return result;
}
};
}
示例8: register
import com.codahale.metrics.MetricSet; //導入依賴的package包/類
/**
* Given a {@link Metric}, registers it under the given name.
*
* @param name the name of the metric
* @param metric the metric
* @param <T> the type of the metric
* @return {@code metric}
* @throws IllegalArgumentException if the name is already registered
*/
@SuppressWarnings("unchecked")
public <T extends Metric> T register(MetricName name, T metric) throws IllegalArgumentException {
if (metric instanceof MetricSet) {
throw new IllegalArgumentException("This metrics registry is not compatible with MetricSets. Use a Metric2Set instead.");
} else {
final Metric existing = metrics.putIfAbsent(name, metric);
if (existing != null) {
throw new IllegalArgumentException("A metric named " + name + " already exists");
}
else {
// This is a new metric - we have to register the Metric with
// the legacy Dropwizard Metric registry as
// well to support existing reports and listeners
metricRegistry.register(name.toGraphiteName(), metric);
}
}
return metric;
}
示例9: configuration
import com.codahale.metrics.MetricSet; //導入依賴的package包/類
private void configuration(@Observes AfterDeploymentValidation adv, BeanManager manager) {
// Fire configuration event
manager.fireEvent(configuration);
configuration.unmodifiable();
// Produce and register custom metrics
MetricRegistry registry = getReference(manager, MetricRegistry.class);
MetricName name = getReference(manager, MetricName.class);
for (Map.Entry<Bean<?>, AnnotatedMember<?>> bean : metrics.entrySet()) {
// TODO: add MetricSet metrics into the metric registry
if (bean.getKey().getTypes().contains(MetricSet.class)
// skip non @Default beans
|| !bean.getKey().getQualifiers().contains(DEFAULT)
// skip producer methods with injection point
|| hasInjectionPoints(bean.getValue()))
continue;
registry.register(name.of(bean.getValue()), (Metric) getReference(manager, bean.getValue().getBaseType(), bean.getKey()));
}
// Let's clear the collected metric producers
metrics.clear();
}
示例10: registerAll
import com.codahale.metrics.MetricSet; //導入依賴的package包/類
private void registerAll(String prefix, MetricSet metricSet, MetricRegistry registry) {
for (Map.Entry<String, Metric> entry : metricSet.getMetrics().entrySet()) {
if (entry.getValue() instanceof MetricSet) {
registerAll(prefix + "." + entry.getKey(), (MetricSet) entry.getValue(), registry);
} else {
registry.register(prefix + "." + entry.getKey(), entry.getValue());
}
}
}
示例11: buildCounter
import com.codahale.metrics.MetricSet; //導入依賴的package包/類
public synchronized GoCounter buildCounter() {
String name = generateName("counter");
GoCounter counter = getExistingCounter(name);
if (counter == null) {
counter = new GoCounter(name);
Map<String, Metric> map = new HashMap<>();
map.put(name, counter);
MetricSet set = () -> map;
registry.registerAll(set);
}
return counter;
}
示例12: buildGauge
import com.codahale.metrics.MetricSet; //導入依賴的package包/類
public synchronized GoGauge buildGauge() {
String name = generateName("gauge");
GoGauge gauge = getExistingGauge(name);
if (gauge == null) {
gauge = new GoGauge(name);
Map<String, Metric> map = new HashMap<>();
map.put(name, gauge);
MetricSet set = () -> map;
registry.registerAll(set);
}
return gauge;
}
示例13: registerAll
import com.codahale.metrics.MetricSet; //導入依賴的package包/類
private static void registerAll(String prefix, MetricSet metricSet, MetricRegistry registry) {
for (Entry<String, Metric> entry : metricSet.getMetrics().entrySet()) {
if (entry.getValue() instanceof MetricSet) {
registerAll(prefix + "." + entry.getKey(), (MetricSet) entry.getValue(), registry);
} else {
registry.register(prefix + "." + entry.getKey(), entry.getValue());
}
}
}
示例14: scoped
import com.codahale.metrics.MetricSet; //導入依賴的package包/類
private static MetricSet scoped(final String name, final MetricSet metricSet) {
return new MetricSet() {
@Override
public Map<String, Metric> getMetrics() {
ImmutableMap.Builder<String, Metric> scopedMetrics = ImmutableMap.builder();
for(Map.Entry<String, Metric> entry: metricSet.getMetrics().entrySet()) {
scopedMetrics.put(MetricRegistry.name(name, entry.getKey()), entry.getValue());
}
return scopedMetrics.build();
}
};
}
示例15: init
import com.codahale.metrics.MetricSet; //導入依賴的package包/類
@PostConstruct
public void init() {
// ConsoleReporter consoleReporter = ConsoleReporter.forRegistry(metricRegistry)
// .convertRatesTo(TimeUnit.SECONDS)
// .convertDurationsTo(TimeUnit.MILLISECONDS)
// .build();
//
// consoleReporter.start(10, TimeUnit.SECONDS);
// Graphite graphite = new Graphite(new InetSocketAddress("192.168.99.100", 2003));
// GraphiteReporter graphiteReporter = GraphiteReporter.forRegistry(metricRegistry)
// .prefixedWith("com.packt.microservices.geolocation")
// .convertRatesTo(TimeUnit.SECONDS)
// .convertDurationsTo(TimeUnit.MILLISECONDS)
// .filter(MetricFilter.ALL)
// .build(graphite);
// graphiteReporter.start(60, TimeUnit.SECONDS);
geolocationWriteRequestCount = metricRegistry.counter("geolocationWriteRequestCount");
metricRegistry.register("geolocationLastWriteTime", new Gauge<Long>() {
@Override
public Long getValue() {
return geolocationLastWriteTime;
}
});
metricRegistry.registerAll(new MetricSet() {
@Override
public Map<String, Metric> getMetrics() {
Map<String, Metric> metrics = new HashMap<>();
metrics.put("geolocationMemoryUsage", new MemoryUsageGaugeSet());
metrics.put("geolocationClassLoading", new ClassLoadingGaugeSet());
metrics.put("geolocationGarbageCollector", new GarbageCollectorMetricSet());
return metrics;
}
});
}