本文整理匯總了Java中com.codahale.metrics.Gauge類的典型用法代碼示例。如果您正苦於以下問題:Java Gauge類的具體用法?Java Gauge怎麽用?Java Gauge使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Gauge類屬於com.codahale.metrics包,在下文中一共展示了Gauge類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: start
import com.codahale.metrics.Gauge; //導入依賴的package包/類
public void start() throws Exception {
client.start();
leaderSelector = new LeaderSelector(client, SnowflakeConfig.getLeaderPath(), this);
leaderSelector.autoRequeue();
LOGGER.info("start SnowflakeServer... ip: {}", getHostname());
leaderSelector.start();
while (!hasLeader()) {
Thread.sleep(1000);
}
initWorkerId();
ReporterHolder.metrics.register(MetricRegistry.name("SnowflakeServer", "workerId"), new Gauge<Integer>() {
@Override
public Integer getValue() {
return workerId;
}
});
}
示例2: ZKInt32IdGenerator
import com.codahale.metrics.Gauge; //導入依賴的package包/類
public ZKInt32IdGenerator(CuratorFramework client, String lockPath, String sequencePath, String name, long start, int rangeCount) {
Preconditions.checkNotNull(client);
Preconditions.checkNotNull(lockPath);
Preconditions.checkNotNull(sequencePath);
Preconditions.checkNotNull(name);
this.client = client;
client.start();
RangeStore rangeStore = new ZkRangeStore(name, client, lockPath, sequencePath, 1, TimeUnit.SECONDS, start, rangeCount);
try {
start = rangeStore.getNextRange();
} catch (InterruptedException e) {
throw new IllegalStateException("ZKInt32IdGenerator 初始值獲取失敗!!!");
}
rangeSequence = new RangeSequence(1, start, rangeCount, rangeStore);
rangeSequence.start();
ReporterHolder.metrics.register("ZKInt32.seq." + name + ".currId", (Gauge<Long>) () -> rangeSequence.get());
timer = ReporterHolder.metrics.timer(name("ZKInt32.seq." + name, "generateId"));
}
示例3: initialize
import com.codahale.metrics.Gauge; //導入依賴的package包/類
@PostConstruct
public void initialize() {
for (Metric<?> metric : systemPublicMetrics.metrics()) {
Gauge<Long> metricGauge = () -> metric.getValue().longValue();
String name = metric.getName();
if (!name.contains(".")) {
name += ".total";
}
registry.register(name, metricGauge);
}
final MackerelSender sender = new MackerelSender(serviceName, apiKey);
final MackerelReporter reporter = MackerelReporter
.forRegistry(registry)
.build(sender);
reporter.start(1, TimeUnit.MINUTES);
}
示例4: shouldCollectNotOnOrAfterValueFromAssertion
import com.codahale.metrics.Gauge; //導入依賴的package包/類
@Test
public void shouldCollectNotOnOrAfterValueFromAssertion() {
DateTimeFreezer.freezeTime();
MetricRegistry metricRegistry = new MetricRegistry();
IdpAssertionMetricsCollector idpAssertionMetricsCollector = new IdpAssertionMetricsCollector(metricRegistry);
DateTime notOnOrAfter = DateTime.now().plusMinutes(15);
Assertion anAssertion = anAssertion()
.withIssuer(anIssuer().withIssuerId("testIdP").build())
.withSubject(aSubject().withSubjectConfirmation(aSubjectConfirmation()
.withSubjectConfirmationData(aSubjectConfirmationData()
.withNotOnOrAfter(notOnOrAfter)
.build())
.build())
.build())
.buildUnencrypted();
idpAssertionMetricsCollector.update(anAssertion);
Gauge actual = metricRegistry.getGauges().get("notOnOrAfter.testIdP");
assertThat(actual.getValue()).isEqualTo(15L);
}
示例5: report
import com.codahale.metrics.Gauge; //導入依賴的package包/類
@Override
public void report(final SortedMap<String, Gauge> gauges,
final SortedMap<String, Counter> counters,
final SortedMap<String, Histogram> histograms,
final SortedMap<String, Meter> meters,
final SortedMap<String, Timer> timers) {
final long timestamp = clock.instant().toEpochMilli();
final ImmutableList<InfluxDbMeasurement> influxDbMeasurements = ImmutableList.<InfluxDbMeasurement>builder()
.addAll(transformer.fromGauges(gauges, timestamp))
.addAll(transformer.fromCounters(counters, timestamp))
.addAll(transformer.fromHistograms(histograms, timestamp))
.addAll(transformer.fromMeters(meters, timestamp))
.addAll(transformer.fromTimers(timers, timestamp))
.build();
sender.send(influxDbMeasurements);
}
示例6: testFromGauges_Ungrouped
import com.codahale.metrics.Gauge; //導入依賴的package包/類
@Test
public void testFromGauges_Ungrouped() {
final DropwizardMeasurementParser parser = mock(DropwizardMeasurementParser.class);
final DropwizardTransformer transformer = transformerWithParser(parser, false);
final Map<String, Gauge> gauges = ImmutableMap.of(
"some.stuff.queued", () -> 12,
"some.stuff.processed", () -> 15
);
when(parser.parse("some.stuff.queued")).thenReturn(
DropwizardMeasurement.create("some.stuff.queued", MEASUREMENT_TAGS, Optional.empty())
);
when(parser.parse("some.stuff.processed")).thenReturn(
DropwizardMeasurement.create("some.stuff.processed", MEASUREMENT_TAGS, Optional.empty())
);
final List<InfluxDbMeasurement> expected = ImmutableList.of(
InfluxDbMeasurement.create("some.stuff.queued", ALL_TAGS, ImmutableMap.of("value", "12i"), 90210L),
InfluxDbMeasurement.create("some.stuff.processed", ALL_TAGS, ImmutableMap.of("value", "15i"), 90210L)
);
final List<InfluxDbMeasurement> measurements = transformer.fromGauges(gauges, 90210L);
assertEquals("should not group gauge measurements", expected, measurements);
}
示例7: testFromGauges_Grouped
import com.codahale.metrics.Gauge; //導入依賴的package包/類
@Test
public void testFromGauges_Grouped() {
final DropwizardMeasurementParser parser = mock(DropwizardMeasurementParser.class);
final DropwizardTransformer transformer = transformerWithParser(parser, true);
final Map<String, Gauge> gauges = ImmutableMap.of(
"some.stuff.queued", () -> 12,
"some.stuff.processed", () -> 15
);
when(parser.parse("some.stuff")).thenReturn(
DropwizardMeasurement.create("some.stuff", MEASUREMENT_TAGS, Optional.empty())
);
final List<InfluxDbMeasurement> expected = ImmutableList.of(
InfluxDbMeasurement.create("some.stuff", ALL_TAGS, ImmutableMap.of("queued", "12i", "processed", "15i"), 90210L)
);
final List<InfluxDbMeasurement> measurements = transformer.fromGauges(gauges, 90210L);
assertEquals("should group gauges by tags and prefix", expected, measurements);
}
示例8: testGroupValues_Inline
import com.codahale.metrics.Gauge; //導入依賴的package包/類
@Test
public void testGroupValues_Inline() {
final DropwizardMeasurementParser parser = mock(DropwizardMeasurementParser.class);
final DropwizardTransformer transformer = transformerWithParser(parser, true);
final Map<String, Gauge> gauges = ImmutableMap.of(
"Measurement queued", () -> 12,
"Measurement processed", () -> 15
);
when(parser.parse("Measurement queued")).thenReturn(
DropwizardMeasurement.create("Measurement", MEASUREMENT_TAGS, Optional.of("queued"))
);
when(parser.parse("Measurement processed")).thenReturn(
DropwizardMeasurement.create("Measurement", MEASUREMENT_TAGS, Optional.of("processed"))
);
final Map<GroupKey, Map<String, Object>> expected = ImmutableMap.of(
GroupKey.create("Measurement", MEASUREMENT_TAGS), ImmutableMap.of("queued", 12, "processed", 15)
);
final Map<GroupKey, Map<String, Object>> groups = transformer.groupValues(gauges, "unused_default_key", Gauge::getValue);
assertEquals("should group values with inlined keys", expected, groups);
}
示例9: testGroupValues_CountingGauges
import com.codahale.metrics.Gauge; //導入依賴的package包/類
@Test
public void testGroupValues_CountingGauges() {
final DropwizardMeasurementParser parser = mock(DropwizardMeasurementParser.class);
final DropwizardTransformer transformer = transformerWithParser(parser, true);
final Map<String, Gauge> gauges = ImmutableMap.of(
"some.stuff.queued.count", () -> 12,
"some.stuff.processed.count", () -> 15
);
when(parser.parse("some.stuff")).thenReturn(
DropwizardMeasurement.create("some.stuff", MEASUREMENT_TAGS, Optional.empty())
);
final Map<GroupKey, Map<String, Object>> expected = ImmutableMap.of(
GroupKey.create("some.stuff", MEASUREMENT_TAGS), ImmutableMap.of("queued.count", 12, "processed.count", 15)
);
final Map<GroupKey, Map<String, Object>> groups = transformer.groupValues(gauges, "unused_default_key", Gauge::getValue);
assertEquals("should ignore .count postfix when parsing groups", expected, groups);
}
示例10: testGroupValues_NoDotIndex
import com.codahale.metrics.Gauge; //導入依賴的package包/類
@Test
public void testGroupValues_NoDotIndex() {
final DropwizardMeasurementParser parser = mock(DropwizardMeasurementParser.class);
final DropwizardTransformer transformer = transformerWithParser(parser, true);
final Map<String, Gauge> gauges = ImmutableMap.of(
"some_stuff_queued", () -> 12,
"some_stuff_processed", () -> 15
);
when(parser.parse("some_stuff_queued")).thenReturn(
DropwizardMeasurement.create("some.stuff.queued", MEASUREMENT_TAGS, Optional.empty())
);
when(parser.parse("some_stuff_processed")).thenReturn(
DropwizardMeasurement.create("some.stuff.processed", MEASUREMENT_TAGS, Optional.empty())
);
final Map<GroupKey, Map<String, Object>> expected = ImmutableMap.of(
GroupKey.create("some.stuff.queued", MEASUREMENT_TAGS), ImmutableMap.of("default_key", 12),
GroupKey.create("some.stuff.processed", MEASUREMENT_TAGS), ImmutableMap.of("default_key", 15)
);
final Map<GroupKey, Map<String, Object>> groups = transformer.groupValues(gauges, "default_key", Gauge::getValue);
assertEquals("should use fully parsed key and default value", expected, groups);
}
示例11: testGroupValues_WithDotIndex
import com.codahale.metrics.Gauge; //導入依賴的package包/類
@Test
public void testGroupValues_WithDotIndex() {
final DropwizardMeasurementParser parser = mock(DropwizardMeasurementParser.class);
final DropwizardTransformer transformer = transformerWithParser(parser, true);
final Map<String, Gauge> gauges = ImmutableMap.of(
"some.stuff.queued", () -> 12,
"some.stuff.processed", () -> 15
);
when(parser.parse("some.stuff")).thenReturn(
DropwizardMeasurement.create("some.stuff", MEASUREMENT_TAGS, Optional.empty())
);
final Map<GroupKey, Map<String, Object>> expected = ImmutableMap.of(
GroupKey.create("some.stuff", MEASUREMENT_TAGS), ImmutableMap.of("queued", 12, "processed", 15)
);
final Map<GroupKey, Map<String, Object>> groups = transformer.groupValues(gauges, "unused_default_key", Gauge::getValue);
assertEquals("should group values by field postfix", expected, groups);
}
示例12: start
import com.codahale.metrics.Gauge; //導入依賴的package包/類
public void start(final DrillbitEndpoint endpoint, final Controller controller,
final DataConnectionCreator data, final ClusterCoordinator coord, final PStoreProvider provider) {
dContext = new DrillbitContext(endpoint, bContext, coord, controller, data, workBus, provider, executor);
statusThread.start();
// TODO remove try block once metrics moved from singleton, For now catch to avoid unit test failures
try {
dContext.getMetrics().register(
MetricRegistry.name("drill.exec.work.running_fragments." + dContext.getEndpoint().getUserPort()),
new Gauge<Integer>() {
@Override
public Integer getValue() {
return runningFragments.size();
}
});
} catch (final IllegalArgumentException e) {
logger.warn("Exception while registering metrics", e);
}
}
示例13: registerContainerAppNumMetrics
import com.codahale.metrics.Gauge; //導入依賴的package包/類
private void registerContainerAppNumMetrics() {
metrics.register("variable.running.application",
new Gauge<Integer>() {
@Override
public Integer getValue() {
if (scheduler == null || scheduler.getRootQueueMetrics() == null) {
return 0;
} else {
return scheduler.getRootQueueMetrics().getAppsRunning();
}
}
}
);
metrics.register("variable.running.container",
new Gauge<Integer>() {
@Override
public Integer getValue() {
if(scheduler == null || scheduler.getRootQueueMetrics() == null) {
return 0;
} else {
return scheduler.getRootQueueMetrics().getAllocatedContainers();
}
}
}
);
}
示例14: trackQueue
import com.codahale.metrics.Gauge; //導入依賴的package包/類
@Override
public void trackQueue(String queueName) {
trackedQueues.add(queueName);
FifoScheduler fifo = (FifoScheduler) scheduler;
// for FifoScheduler, only DEFAULT_QUEUE
// here the three parameters doesn't affect results
final QueueInfo queue = fifo.getQueueInfo(queueName, false, false);
// track currentCapacity, maximumCapacity (always 1.0f)
metrics.register("variable.queue." + queueName + ".currentcapacity",
new Gauge<Float>() {
@Override
public Float getValue() {
return queue.getCurrentCapacity();
}
}
);
metrics.register("variable.queue." + queueName + ".",
new Gauge<Float>() {
@Override
public Float getValue() {
return queue.getCurrentCapacity();
}
}
);
}
示例15: writeGauge
import com.codahale.metrics.Gauge; //導入依賴的package包/類
public void writeGauge(String name, Gauge<?> gauge) throws IOException {
final String sanitizedName = sanitizeMetricName(name);
writer.writeHelp(sanitizedName, getHelpMessage(name, gauge));
writer.writeType(sanitizedName, MetricType.GAUGE);
Object obj = gauge.getValue();
double value;
if (obj instanceof Number) {
value = ((Number) obj).doubleValue();
} else if (obj instanceof Boolean) {
value = ((Boolean) obj) ? 1 : 0;
} else {
LOG.warn("Invalid type for Gauge {}: {}", name, obj.getClass().getName());
return;
}
writer.writeSample(sanitizedName, emptyMap(), value);
}