当前位置: 首页>>代码示例>>Java>>正文


Java StatsD类代码示例

本文整理汇总了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();
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:35,代码来源:TestStatsDMetrics.java

示例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();
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:33,代码来源:TestStatsDMetrics.java


注:本文中的org.apache.hadoop.metrics2.sink.StatsDSink.StatsD类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。