本文整理汇总了Java中org.apache.hadoop.metrics2.sink.StatsDSink.StatsD类的典型用法代码示例。如果您正苦于以下问题:Java StatsD类的具体用法?Java StatsD怎么用?Java StatsD使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StatsD类属于org.apache.hadoop.metrics2.sink.StatsDSink包,在下文中一共展示了StatsD类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPutMetrics
import org.apache.hadoop.metrics2.sink.StatsDSink.StatsD; //导入依赖的package包/类
@Test(timeout=3000)
public void testPutMetrics() throws IOException, InterruptedException {
final StatsDSink sink = new StatsDSink();
List<MetricsTag> tags = new ArrayList<MetricsTag>();
tags.add(new MetricsTag(MsInfo.Hostname, "host"));
tags.add(new MetricsTag(MsInfo.Context, "jvm"));
tags.add(new MetricsTag(MsInfo.ProcessName, "process"));
Set<AbstractMetric> metrics = new HashSet<AbstractMetric>();
metrics.add(makeMetric("foo1", 1.25, MetricType.COUNTER));
metrics.add(makeMetric("foo2", 2.25, MetricType.GAUGE));
final MetricsRecord record =
new MetricsRecordImpl(MsInfo.Context, (long) 10000, tags, metrics);
try (DatagramSocket sock = new DatagramSocket()) {
sock.setReceiveBufferSize(8192);
final StatsDSink.StatsD mockStatsD =
new StatsD(sock.getLocalAddress().getHostName(),
sock.getLocalPort());
Whitebox.setInternalState(sink, "statsd", mockStatsD);
final DatagramPacket p = new DatagramPacket(new byte[8192], 8192);
sink.putMetrics(record);
sock.receive(p);
String result =new String(p.getData(), 0, p.getLength(),
Charset.forName("UTF-8"));
assertTrue(
"Received data did not match data sent",
result.equals("host.process.jvm.Context.foo1:1.25|c") ||
result.equals("host.process.jvm.Context.foo2:2.25|g"));
} finally {
sink.close();
}
}
示例2: testPutMetrics2
import org.apache.hadoop.metrics2.sink.StatsDSink.StatsD; //导入依赖的package包/类
@Test(timeout=3000)
public void testPutMetrics2() throws IOException {
StatsDSink sink = new StatsDSink();
List<MetricsTag> tags = new ArrayList<MetricsTag>();
tags.add(new MetricsTag(MsInfo.Hostname, null));
tags.add(new MetricsTag(MsInfo.Context, "jvm"));
tags.add(new MetricsTag(MsInfo.ProcessName, "process"));
Set<AbstractMetric> metrics = new HashSet<AbstractMetric>();
metrics.add(makeMetric("foo1", 1, MetricType.COUNTER));
metrics.add(makeMetric("foo2", 2, MetricType.GAUGE));
MetricsRecord record =
new MetricsRecordImpl(MsInfo.Context, (long) 10000, tags, metrics);
try (DatagramSocket sock = new DatagramSocket()) {
sock.setReceiveBufferSize(8192);
final StatsDSink.StatsD mockStatsD =
new StatsD(sock.getLocalAddress().getHostName(),
sock.getLocalPort());
Whitebox.setInternalState(sink, "statsd", mockStatsD);
final DatagramPacket p = new DatagramPacket(new byte[8192], 8192);
sink.putMetrics(record);
sock.receive(p);
String result =
new String(p.getData(), 0, p.getLength(), Charset.forName("UTF-8"));
assertTrue("Received data did not match data sent",
result.equals("process.jvm.Context.foo1:1|c") ||
result.equals("process.jvm.Context.foo2:2|g"));
} finally {
sink.close();
}
}