當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。