本文整理了Java中com.yammer.metrics.Metrics.newGauge()
方法的一些代码示例,展示了Metrics.newGauge()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Metrics.newGauge()
方法的具体详情如下:
包路径:com.yammer.metrics.Metrics
类名称:Metrics
方法名:newGauge
[英]Given a new com.yammer.metrics.core.Gauge, registers it under the given metric name.
[中]给一个新的com。亚默。韵律学。果心仪表,在给定的度量名称下注册。
代码示例来源:origin: apache/incubator-pinot
/**
*
* Return an existing gauge if
* (a) A gauge already exist with the same metric name.
* Otherwise, creates a new meter and registers
*
* @param registry MetricsRegistry
* @param name metric name
* @param gauge Underlying gauge to be tracked
* @return gauge
*/
public static <T> Gauge<T> newGauge(MetricsRegistry registry, MetricName name, Gauge<T> gauge) {
if (registry != null) {
return registry.newGauge(name, gauge);
} else {
return Metrics.newGauge(name, gauge);
}
}
代码示例来源:origin: lealone/Lealone
activeTasks = Metrics.newGauge(factory.createMetricName("ActiveTasks"), new Gauge<Integer>() {
public Integer value() {
return executor.getActiveCount();
pendingTasks = Metrics.newGauge(factory.createMetricName("PendingTasks"), new Gauge<Long>() {
public Long value() {
return executor.getPendingTasks();
totalBlocked = Metrics.newGauge(factory.createMetricName("TotalBlockedTasks"), new Gauge<Integer>() {
public Integer value() {
return executor.getTotalBlockedTasks();
currentBlocked = Metrics.newGauge(factory.createMetricName("CurrentlyBlockedTasks"), new Gauge<Long>() {
public Long value() {
return (long) executor.getCurrentlyBlockedTasks();
completedTasks = Metrics.newGauge(factory.createMetricName("CompletedTasks"), new Gauge<Long>() {
public Long value() {
return executor.getCompletedTasks();
代码示例来源:origin: lealone/Lealone
/**
* Create metrics for given ThreadPoolExecutor.
*
* @param executor Thread pool
* @param path Type of thread pool
* @param poolName Name of thread pool to identify metrics
*/
public ThreadPoolMetrics(final ThreadPoolExecutor executor, String path, String poolName) {
this.factory = new ThreadPoolMetricNameFactory("ThreadPools", path, poolName);
activeTasks = Metrics.newGauge(factory.createMetricName("ActiveTasks"), new Gauge<Integer>() {
public Integer value() {
return executor.getActiveCount();
}
});
totalBlocked = Metrics.newCounter(factory.createMetricName("TotalBlockedTasks"));
currentBlocked = Metrics.newCounter(factory.createMetricName("CurrentlyBlockedTasks"));
completedTasks = Metrics.newGauge(factory.createMetricName("CompletedTasks"), new Gauge<Long>() {
public Long value() {
return executor.getCompletedTaskCount();
}
});
pendingTasks = Metrics.newGauge(factory.createMetricName("PendingTasks"), new Gauge<Long>() {
public Long value() {
return executor.getTaskCount() - executor.getCompletedTaskCount();
}
});
}
代码示例来源:origin: addthis/hydra
private static <T> void makeGauge(String name, Supplier<T> value) {
Gauge<T> gauge = new Gauge<T>() {
@Override public T value() {
return value.get();
}
};
Metrics.newGauge(SpawnBalancer.class, name, gauge);
}
代码示例来源:origin: wavefrontHQ/java
public void reportGauge(Number number, MetricName metricName) {
Metrics.newGauge(metricName,
new Gauge<Double>() {
@Override
public Double value() {
return number.doubleValue();
}
}
);
}
}
代码示例来源:origin: com.wavefront/proxy
public void reportGauge(Number number, MetricName metricName) {
Metrics.newGauge(metricName,
new Gauge<Double>() {
@Override
public Double value() {
return number.doubleValue();
}
}
);
}
}
代码示例来源:origin: com.yammer.dropwizard/dropwizard-db
private void setupGauges(final GenericObjectPool pool, String scope) {
Metrics.newGauge(ManagedPooledDataSource.class, "numActive", scope, new Gauge<Integer>() {
@Override
public Integer value() {
return pool.getNumActive();
}
});
Metrics.newGauge(ManagedPooledDataSource.class, "numIdle", scope, new Gauge<Integer>() {
@Override
public Integer value() {
return pool.getNumIdle();
}
});
}
}
代码示例来源:origin: addthis/hydra
public JobOnFinishStateHandlerImpl(Spawn spawn) {
this.spawn = spawn;
backgroundTaskQueue = new LinkedBlockingQueue<>(backgroundQueueSize);
backgroundService = new ThreadPoolExecutor(
backgroundThreads, backgroundThreads, 0L, TimeUnit.MILLISECONDS, backgroundTaskQueue,
new ThreadFactoryBuilder().setDaemon(true).build());
emailLastFired = new AtomicLong();
backgroundQueueGauge = Metrics.newGauge(
Spawn.class, "backgroundExecutorQueue", new Gauge<Integer>() {
@Override public Integer value() {
return backgroundTaskQueue.size();
}
});
}
代码示例来源:origin: addthis/hydra
public AutobalanceTask(SpawnBalancer spawnBalancer) {
this.spawnBalancer = spawnBalancer;
this.minutesSinceLastBalanceGauge = new MinuteSinceLastBalanceGauge();
Metrics.newGauge(AutobalanceTask.class, "minutesSinceLastBalance", minutesSinceLastBalanceGauge);
}
代码示例来源:origin: addthis/hydra
public static <T> SettableGauge<T> newSettableGauge(Class<?> klass, String name, T initial_value) {
SettableGauge<T> gauge = new SettableGauge(initial_value);
Metrics.newGauge(klass, name, gauge);
return gauge;
}
}
代码示例来源:origin: com.wavefront/proxy
public AbstractAgent(boolean localAgent, boolean pushAgent) {
this.pushAgent = pushAgent;
this.localAgent = localAgent;
this.hostname = getLocalHostName();
Metrics.newGauge(ExpectedAgentMetric.BUFFER_BYTES_LEFT.metricName,
new Gauge<Long>() {
@Override
public Long value() {
return bufferSpaceLeft.get();
}
}
);
}
代码示例来源:origin: com.wavefront/java-lib
public static void set(long serverTime) {
localTime = System.currentTimeMillis();
Clock.serverTime = serverTime;
clockDrift = serverTime - localTime;
if (clockDriftGauge == null) {
// doesn't have to be synchronized, ok to initialize clockDriftGauge more than once
clockDriftGauge = Metrics.newGauge(new MetricName("clock", "", "drift"), new Gauge<Long>() {
@Override
public Long value() {
return clockDrift == null ? null : (long)Math.floor(clockDrift / 1000 + 0.5d);
}
});
}
}
代码示例来源:origin: wavefrontHQ/java
public AbstractAgent(boolean localAgent, boolean pushAgent) {
this.pushAgent = pushAgent;
this.localAgent = localAgent;
this.hostname = getLocalHostName();
Metrics.newGauge(ExpectedAgentMetric.BUFFER_BYTES_LEFT.metricName,
new Gauge<Long>() {
@Override
public Long value() {
return bufferSpaceLeft.get();
}
}
);
}
代码示例来源:origin: wavefrontHQ/java
public static void set(long serverTime) {
localTime = System.currentTimeMillis();
Clock.serverTime = serverTime;
clockDrift = serverTime - localTime;
if (clockDriftGauge == null) {
// doesn't have to be synchronized, ok to initialize clockDriftGauge more than once
clockDriftGauge = Metrics.newGauge(new MetricName("clock", "", "drift"), new Gauge<Long>() {
@Override
public Long value() {
return clockDrift == null ? null : (long)Math.floor(clockDrift / 1000 + 0.5d);
}
});
}
}
代码示例来源:origin: com.facebook.presto.cassandra/cassandra-server
public void addCounter(String name, final Callable<Integer> provider)
{
Metrics.newGauge(factory.createMetricName(name), new Gauge<Integer>()
{
public Integer value()
{
try
{
return provider.call();
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
});
}
}
代码示例来源:origin: com.facebook.presto.cassandra/cassandra-server
/**
* Create a gauge that will be part of a merged version of all column families. The global gauge
* is defined as the globalGauge parameter
*/
protected <G,T> Gauge<T> createColumnFamilyGauge(String name, Gauge<T> gauge, Gauge<G> globalGauge)
{
Gauge<T> cfGauge = Metrics.newGauge(factory.createMetricName(name), gauge);
if (register(name, cfGauge))
{
Metrics.newGauge(globalNameFactory.createMetricName(name), globalGauge);
}
return cfGauge;
}
代码示例来源:origin: com.facebook.presto.cassandra/cassandra-server
/**
* Creates a gauge that will sum the current value of a metric for all column families in this keyspace
* @param name
* @param MetricValue
* @return Gauge>Long> that computes sum of MetricValue.getValue()
*/
private <T extends Number> Gauge<Long> createKeyspaceGauge(String name, final MetricValue extractor)
{
allMetrics.add(name);
return Metrics.newGauge(factory.createMetricName(name), new Gauge<Long>()
{
public Long value()
{
long sum = 0;
for (ColumnFamilyStore cf : keyspace.getColumnFamilyStores())
{
sum += extractor.getValue(cf.metric);
}
return sum;
}
});
}
代码示例来源:origin: com.wavefront/proxy
public CachingGraphiteHostAnnotator(@Nullable final List<String> customSourceTags, boolean disableRdnsLookup) {
this.disableRdnsLookup = disableRdnsLookup;
this.sourceTags = Lists.newArrayListWithExpectedSize(customSourceTags == null ? 4 : customSourceTags.size() + 4);
this.sourceTags.add("source=");
this.sourceTags.add("source\"=");
this.sourceTags.add("host=");
this.sourceTags.add("host\"=");
if (customSourceTags != null) {
this.sourceTags.addAll(customSourceTags.stream().map(customTag -> customTag + "=").collect(Collectors.toList()));
}
this.rdnsCache = disableRdnsLookup ? null : Caffeine.newBuilder()
.maximumSize(5000)
.refreshAfterWrite(5, TimeUnit.MINUTES)
.build(InetAddress::getHostName);
Metrics.newGauge(ExpectedAgentMetric.RDNS_CACHE_SIZE.metricName, new Gauge<Long>() {
@Override
public Long value() {
return disableRdnsLookup ? 0 : rdnsCache.estimatedSize();
}
});
}
代码示例来源:origin: com.wavefront/proxy
ReportingObjectQueueWrapper(ObjectQueue<T> backingQueue, String title) {
this.addCounter = Metrics.newCounter(new MetricName("tape." + title, "", "add"));
this.removeCounter = Metrics.newCounter(new MetricName("tape." + title, "", "remove"));
this.peekCounter = Metrics.newCounter(new MetricName("tape." + title, "", "peek"));
Metrics.newGauge(new MetricName("tape." + title, "", "size"),
new Gauge<Integer>() {
@Override
public Integer value() {
return backingQueue.size();
}
});
this.backingQueue = backingQueue;
}
代码示例来源:origin: wavefrontHQ/java
ReportingObjectQueueWrapper(ObjectQueue<T> backingQueue, String title) {
this.addCounter = Metrics.newCounter(new MetricName("tape." + title, "", "add"));
this.removeCounter = Metrics.newCounter(new MetricName("tape." + title, "", "remove"));
this.peekCounter = Metrics.newCounter(new MetricName("tape." + title, "", "peek"));
Metrics.newGauge(new MetricName("tape." + title, "", "size"),
new Gauge<Integer>() {
@Override
public Integer value() {
return backingQueue.size();
}
});
this.backingQueue = backingQueue;
}
内容来源于网络,如有侵权,请联系作者删除!