本文整理汇总了Java中com.yammer.metrics.core.Counter类的典型用法代码示例。如果您正苦于以下问题:Java Counter类的具体用法?Java Counter怎么用?Java Counter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Counter类属于com.yammer.metrics.core包,在下文中一共展示了Counter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getProperty
import com.yammer.metrics.core.Counter; //导入依赖的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());
}
}
}
示例2: 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")));
}
示例3: createNewMetricsGroup
import com.yammer.metrics.core.Counter; //导入依赖的package包/类
protected MetricsGroup createNewMetricsGroup(String scope) {
MetricName readRandomAccessName = new MetricName(ORG_APACHE_BLUR, HDFS, "Read Random Latency in \u00B5s", scope);
MetricName readStreamAccessName = new MetricName(ORG_APACHE_BLUR, HDFS, "Read Stream Latency in \u00B5s", scope);
MetricName writeAcccessName = new MetricName(ORG_APACHE_BLUR, HDFS, "Write Latency in \u00B5s", scope);
MetricName readRandomThroughputName = new MetricName(ORG_APACHE_BLUR, HDFS, "Read Random Throughput", scope);
MetricName readStreamThroughputName = new MetricName(ORG_APACHE_BLUR, HDFS, "Read Stream Throughput", scope);
MetricName readSeekName = new MetricName(ORG_APACHE_BLUR, HDFS, "Read Stream Seeks", scope);
MetricName writeThroughputName = new MetricName(ORG_APACHE_BLUR, HDFS, "Write Throughput", scope);
MetricName totalHdfsBlocks = new MetricName(ORG_APACHE_BLUR, HDFS, "Hdfs Blocks Total", scope);
MetricName localHdfsBlocks = new MetricName(ORG_APACHE_BLUR, HDFS, "Hdfs Blocks Local", scope);
Histogram readRandomAccess = Metrics.newHistogram(readRandomAccessName);
Histogram readStreamAccess = Metrics.newHistogram(readStreamAccessName);
Histogram writeAccess = Metrics.newHistogram(writeAcccessName);
Meter readRandomThroughput = Metrics.newMeter(readRandomThroughputName, "Read Random Bytes", TimeUnit.SECONDS);
Meter readStreamThroughput = Metrics.newMeter(readStreamThroughputName, "Read Stream Bytes", TimeUnit.SECONDS);
Meter readStreamSeek = Metrics.newMeter(readSeekName, "Read Stream Seeks", TimeUnit.SECONDS);
Meter writeThroughput = Metrics.newMeter(writeThroughputName, "Write Bytes", TimeUnit.SECONDS);
Counter totalHdfsBlock = Metrics.newCounter(totalHdfsBlocks);
Counter localHdfsBlock = Metrics.newCounter(localHdfsBlocks);
return new MetricsGroup(readRandomAccess, readStreamAccess, writeAccess, readRandomThroughput,
readStreamThroughput, readStreamSeek, writeThroughput, totalHdfsBlock, localHdfsBlock);
}
示例4: processAll
import com.yammer.metrics.core.Counter; //导入依赖的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();
}
示例5: copyIndexingMetricsToCounters
import com.yammer.metrics.core.Counter; //导入依赖的package包/类
private void copyIndexingMetricsToCounters(Context context) {
final String COUNTER_GROUP = "HBase Indexer Metrics";
SortedMap<String, SortedMap<MetricName, Metric>> groupedMetrics = Metrics.defaultRegistry().groupedMetrics(
new IndexerMetricsUtil.IndexerMetricPredicate());
for (Entry<String, SortedMap<MetricName, Metric>> metricsGroupEntry : groupedMetrics.entrySet()) {
SortedMap<MetricName, Metric> metricsGroupMap = metricsGroupEntry.getValue();
for (Entry<MetricName, Metric> metricEntry : metricsGroupMap.entrySet()) {
MetricName metricName = metricEntry.getKey();
Metric metric = metricEntry.getValue();
String counterName = metricName.getType() + ": " + metricName.getName();
if (metric instanceof Counter) {
Counter counter = (Counter) metric;
context.getCounter(COUNTER_GROUP, counterName).increment(counter.count());
} else if (metric instanceof Meter) {
Meter meter = (Meter) metric;
context.getCounter(COUNTER_GROUP, counterName).increment(meter.count());
} else if (metric instanceof Timer) {
Timer timer = (Timer) metric;
context.getCounter(COUNTER_GROUP, counterName).increment((long) timer.sum());
}
}
}
}
示例6: processCounter
import com.yammer.metrics.core.Counter; //导入依赖的package包/类
public void processCounter(MetricName name, Counter counter, PrintStream stream) {
GraphData<Counter> graphData = GraphData.counterGraphData(name, maxItems);
graphData.addItem(counter);
stream.append(TABLE_BEGIN);
header(name.getName(), stream);
stream.printf("<tr><td>value</td><td>%d</td></tr>", counter.count());
stream.append(TABLE_END);
stream.append("<div class=\"span8 chart\"");
stream.printf(" id=\"chart-%s\"", name.hashCode());
stream.append(" style=\"height:420px;width:620px;\"");
stream.printf(" data=\"%s\"", graphData.data());
stream.append(" name=\"count\" labels=\"['count']\"");
stream.append("></div>");
}
示例7: refresh
import com.yammer.metrics.core.Counter; //导入依赖的package包/类
/**
* Update counter from underlying counters.
*/
public void refresh() {
long count = 0;
for (Metric m : _counters) {
if (m instanceof Counter) {
count += ((Counter) m).count();
} else if (m instanceof AggregatedCounter) {
count += ((AggregatedCounter) m).count();
}
}
_count = count;
}
示例8: 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();
}
示例9: counter
import com.yammer.metrics.core.Counter; //导入依赖的package包/类
@Test
public final void counter() throws Exception {
final long count = new Random().nextInt(Integer.MAX_VALUE);
addMetricAndRunReporter(
new Callable<Counter>() {
@Override
public Counter call() throws Exception {
return createCounter(count);
}
});
verifyCounter(count);
}
示例10: createCounter
import com.yammer.metrics.core.Counter; //导入依赖的package包/类
static Counter createCounter(long count) throws Exception {
final Counter mock = mock(Counter.class);
when(mock.count()).thenReturn(count);
return configureMatcher(mock, doAnswer(new MetricsProcessorAction() {
@Override
void delegateToProcessor(MetricProcessor<Object> processor, MetricName name, Object context) throws Exception {
processor.processCounter(name, mock, context);
}
}));
}
示例11: getNumber
import com.yammer.metrics.core.Counter; //导入依赖的package包/类
public Number getNumber(final Metric metric, final Snapshot none) {
if (metric instanceof Counter) {
Counter counter = (Counter) metric;
return counter.count();
} else {
throw new IllegalArgumentException("Invalid metric for property");
}
}
示例12: 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);
}
示例13: MetricsGroup
import com.yammer.metrics.core.Counter; //导入依赖的package包/类
MetricsGroup(Histogram readRandomAccess, Histogram readStreamAccess, Histogram writeAccess,
Meter readRandomThroughput, Meter readStreamThroughput, Meter readStreamSeek, Meter writeThroughput,
Counter totalHdfsBlock, Counter localHdfsBlock) {
this.readRandomAccess = readRandomAccess;
this.readStreamAccess = readStreamAccess;
this.writeAccess = writeAccess;
this.readRandomThroughput = readRandomThroughput;
this.readStreamThroughput = readStreamThroughput;
this.writeThroughput = writeThroughput;
this.readStreamSeek = readStreamSeek;
this.totalHdfsBlock = totalHdfsBlock;
this.localHdfsBlock = localHdfsBlock;
}
示例14: processCounter
import com.yammer.metrics.core.Counter; //导入依赖的package包/类
@Override
public void processCounter(MetricName name, Counter counter, Context context) throws Exception {
MetricInfo info = context.getMetricInfo(name);
long time = context.getTime();
info.addNumber("timestamp", time);
info.addNumber("value", counter.count());
}
示例15: getCounter
import com.yammer.metrics.core.Counter; //导入依赖的package包/类
private static Counter getCounter(MetricsRegistry metricsRegistry,
MetricMetadata metricMetadata) {
Counter counter = metricsRegistry.newCounter(YammerExample.class, "yammer.test.counter");
metricMetadata.forMetric(counter)
.withSourceName("signalFx")
.withDimension(LIBRARY_VERSION, YAMMER);
return counter;
}