本文整理汇总了Java中com.timgroup.statsd.StatsDClient.count方法的典型用法代码示例。如果您正苦于以下问题:Java StatsDClient.count方法的具体用法?Java StatsDClient.count怎么用?Java StatsDClient.count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.timgroup.statsd.StatsDClient
的用法示例。
在下文中一共展示了StatsDClient.count方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateImpl
import com.timgroup.statsd.StatsDClient; //导入方法依赖的package包/类
@Override
public void updateImpl(List<Metric> metrics) {
// The statsd client doesn't do any checks on the underlying socket's state
// and the socket connects only once, so we cannot trust the socket to stay
// open over a period of time. If this is changed/fixed we could reuse the
// client but until then it cannot be safely reused.
StatsDClient statsd = createClient();
LOGGER.debug("sending data");
try {
for (Metric metric : metrics) {
String aspect = namingConvention.getName(metric);
if (metric.getConfig().getTags().getTag(DataSourceType.COUNTER.getValue()) != null) {
statsd.count(aspect, metric.getNumberValue().longValue());
} else if (metric.hasNumberValue()) {
statsd.gauge(aspect, metric.getNumberValue().longValue());
} else {
statsd.set(aspect, metric.getValue().toString());
}
statsd.time(aspect, metric.getTimestamp() / 1000);
}
} finally {
statsd.stop();
}
}
示例2: process
import com.timgroup.statsd.StatsDClient; //导入方法依赖的package包/类
public void process(Exchange exchange) throws Exception {
StatsDComponent statsDComponent = (StatsDComponent) endpoint.getComponent();
StatsDClient statsDClient = statsDComponent.getStatsDClient();
if (statsDClient != null) {
// whipped up for a while
if (StatsDOperation.COUNTER.equals(endpoint.getOperation())) {
statsDClient.count(endpoint.getAspect(), endpoint.getValue());
} else if (StatsDOperation.VALUE.equals(endpoint.getOperation())) {
statsDClient.gauge(endpoint.getAspect(), endpoint.getValue());
} else {
statsDClient.time(endpoint.getAspect(), endpoint.getValue());
}
} else {
// do nothing. add logger
System.out.printf("operation = %s, aspect = %s, value = %s",
endpoint.getOperation().getName(), endpoint.getAspect(), endpoint.getValue());
}
}
示例3: test
import com.timgroup.statsd.StatsDClient; //导入方法依赖的package包/类
@Test
public void test() {
final StatsdSource statsdSource = new StatsdSource.Builder()
.setActorSystem(_actorSystem)
.setActorName("StatsdSourceTest.testActor")
.setName("StatsdSourceTest.test")
.setPort(1234)
.build();
final Observer observer = Mockito.mock(Observer.class);
statsdSource.attach(observer);
// CHECKSTYLE.OFF: AnonInnerLength - This is the Akka test pattern
new TestKit(_actorSystem) {{
// Deploy the statsd source actor
final ActorRef statsdSourceActor = _actorSystem.actorOf(StatsdSource.Actor.props(statsdSource));
// Wait for it to be ready
boolean isReady = false;
while (!isReady) {
statsdSourceActor.tell("IsReady", getRef());
isReady = expectMsgClass(Duration.create(10, TimeUnit.SECONDS), Boolean.class);
}
// Send metrics using statsd over udp
final StatsDClient statsdClient = new NonBlockingStatsDClient("StatsdSourceTest.test", "localhost", 1234);
statsdClient.count("counter1", 3);
statsdClient.stop();
// Captor observation of the resulting records
Mockito.verify(observer, Mockito.timeout(1000)).notify(
Mockito.same(statsdSource),
_recordCaptor.capture());
// Verify the captured records
assertRecordEquality(
new DefaultRecord.Builder()
.setTime(DateTime.now())
.setId(UUID.randomUUID().toString())
.setMetrics(ImmutableMap.of(
"StatsdSourceTest.test.counter1",
new DefaultMetric.Builder()
.setType(MetricType.COUNTER)
.setValues(ImmutableList.of(
new Quantity.Builder()
.setValue(3d)
.build()))
.build()))
.build(),
_recordCaptor.getValue());
}};
// CHECKSTYLE.ON: AnonInnerLength
}