本文整理汇总了Java中com.yammer.metrics.core.Counter.inc方法的典型用法代码示例。如果您正苦于以下问题:Java Counter.inc方法的具体用法?Java Counter.inc怎么用?Java Counter.inc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.yammer.metrics.core.Counter
的用法示例。
在下文中一共展示了Counter.inc方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFetchCounter
import com.yammer.metrics.core.Counter; //导入方法依赖的package包/类
@Test
public void testFetchCounter() throws Exception {
final MetricName name = new MetricName("gr", "t1", "n1");
Counter counter = metricsRegistry.newCounter(name);
final MuninDataSourceFactory dataSourceFactory = new MuninDataSourceFactory();
Map<String, MuninGraph> graphs = new HashMap<String, MuninGraph>() {{
put("foo", new MuninGraph("foo", "gr", "t", asList(
dataSourceFactory.forMetric(name, null, null, new MuninDataSourceConfig()))));
}};
MetricsCommandProcessor sut = new MetricsCommandProcessor(metricsRegistry, new StaticMuninGraphProvider(graphs), hostname);
counter.inc();
counter.inc();
assertEquals(asList(
"n1__count.value 2",
"."
)
, sut.processCommand("fetch", asList("foo")));
}
示例2: testTopicReporter
import com.yammer.metrics.core.Counter; //导入方法依赖的package包/类
@Test
public void testTopicReporter() {
MetricsRegistry registry = new MetricsRegistry();
Counter counter = registry.newCounter(KafkaReporterTest.class, "test-counter");
counter.inc();
Properties producerProps = new Properties();
producerProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaConnect);
producerProps.put("schema.registry.url", schemaRegistry);
KafkaReporter reporter = new KafkaReporter(registry, producerProps, topic);
reporter.start(1, TimeUnit.SECONDS);
Properties props = new Properties();
props.put("zookeeper.connect", zkConnect);
props.put("group.id", UUID.randomUUID().toString());
props.put("auto.offset.reset", "smallest");
props.put("zookeeper.session.timeout.ms", "30000");
props.put("consumer.timeout.ms", "30000");
props.put("schema.registry.url", schemaRegistry);
ConsumerConnector consumer = Consumer.createJavaConsumerConnector(new ConsumerConfig(props));
KafkaStream<String, Object> messageStream = consumer.createMessageStreamsByFilter(new Whitelist(topic),
1,
new StringDecoder(null),
new KafkaAvroDecoder(new VerifiableProperties(props))).get(0);
GenericRecord message = (GenericRecord) messageStream.iterator().next().message();
assertNotNull(message);
reporter.shutdown();
}
示例3: inc
import com.yammer.metrics.core.Counter; //导入方法依赖的package包/类
public void inc(final long value, final Object param) {
Counter counter = counters.get(param);
if (counter == null) {
final MetricName name = paramMetricName.name(param);
counter = registry.newCounter(name);
final Counter existingCounter = counters.putIfAbsent(param, counter);
if (existingCounter != null) {
counter = existingCounter;
}
}
counter.inc(value);
}
示例4: sendWritableRequest
import com.yammer.metrics.core.Counter; //导入方法依赖的package包/类
@Override
public void sendWritableRequest(Integer destTaskId,
WritableRequest request) {
Counter counter = superstepRequestCounters.get(request.getType());
if (counter != null) {
counter.inc();
}
nettyClient.sendWritableRequest(destTaskId, request);
}
示例5: nonZeroCounterNotFilteredOut
import com.yammer.metrics.core.Counter; //导入方法依赖的package包/类
@Test
public void nonZeroCounterNotFilteredOut() throws Exception {
final Counter counter = Metrics.newCounter(this.getClass(), "counter1");
counter.inc();
assertThat(filter.matches(METRIC_NAME, counter), is(true));
}
示例6: main
import com.yammer.metrics.core.Counter; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
System.out.println("Running example...");
Properties prop = new Properties();
prop.load(new FileInputStream("auth.properties"));
final String auth_token = prop.getProperty("auth");
final String hostUrlStr = prop.getProperty("host");
final URL hostUrl = new URL(hostUrlStr);
System.out.println("Auth=" + auth_token + " .. host=" + hostUrl);
SignalFxReceiverEndpoint endpoint = new SignalFxEndpoint(hostUrl.getProtocol(),
hostUrl.getHost(), hostUrl.getPort());
MetricsRegistry metricsRegistry = new MetricsRegistry();
SignalFxReporter reporter = new SignalFxReporter.Builder(metricsRegistry,
new StaticAuthToken(auth_token),
hostUrlStr).setEndpoint(endpoint)
.setOnSendErrorHandlerCollection(
Collections.<OnSendErrorHandler>singleton(new OnSendErrorHandler() {
public void handleError(MetricError error) {
System.out.println("" + error.getMessage());
}
}))
.setDetailsToAdd(ImmutableSet.of(SignalFxReporter.MetricDetails.COUNT,
SignalFxReporter.MetricDetails.MIN,
SignalFxReporter.MetricDetails.MAX))
.build();
final MetricMetadata metricMetadata = reporter.getMetricMetadata();
Counter counter = getCounter(metricsRegistry, metricMetadata);
Metric cumulativeCounter = getCumulativeCounter(metricsRegistry, metricMetadata);
Gauge gauge1 = getGauge(metricsRegistry, metricMetadata);
Timer timer = getTimer(metricsRegistry, metricMetadata);
// main body generating data and sending it in a loop
while (true) {
final TimerContext context = timer.time();
try {
System.out.println("Sending data...");
Thread.sleep(500);
counter.inc();
} finally {
context.stop();
}
reporter.report(); // Report all metrics
}
}