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


Java GraphiteSink.putMetrics方法代码示例

本文整理汇总了Java中org.apache.hadoop.metrics2.sink.GraphiteSink.putMetrics方法的典型用法代码示例。如果您正苦于以下问题:Java GraphiteSink.putMetrics方法的具体用法?Java GraphiteSink.putMetrics怎么用?Java GraphiteSink.putMetrics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.hadoop.metrics2.sink.GraphiteSink的用法示例。


在下文中一共展示了GraphiteSink.putMetrics方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testCloseAndWrite

import org.apache.hadoop.metrics2.sink.GraphiteSink; //导入方法依赖的package包/类
@Test(expected=MetricsException.class)
public void testCloseAndWrite() throws IOException {
  GraphiteSink sink = new GraphiteSink();
  List<MetricsTag> tags = new ArrayList<MetricsTag>();
  tags.add(new MetricsTag(MsInfo.Context, "all"));
  tags.add(new MetricsTag(MsInfo.Hostname, "host"));
  Set<AbstractMetric> metrics = new HashSet<AbstractMetric>();
  metrics.add(makeMetric("foo1", 1.25));
  metrics.add(makeMetric("foo2", 2.25));
  MetricsRecord record = new MetricsRecordImpl(MsInfo.Context, (long) 10000, tags, metrics);

  OutputStreamWriter writer = mock(OutputStreamWriter.class);

  Whitebox.setInternalState(sink, "writer", writer);
  sink.close();
  sink.putMetrics(record);
}
 
开发者ID:Nextzero,项目名称:hadoop-2.6.0-cdh5.4.3,代码行数:18,代码来源:TestGraphiteMetrics.java

示例2: testPutMetrics

import org.apache.hadoop.metrics2.sink.GraphiteSink; //导入方法依赖的package包/类
@Test
public void testPutMetrics() {
    GraphiteSink sink = new GraphiteSink();
    List<MetricsTag> tags = new ArrayList<MetricsTag>();
    tags.add(new MetricsTag(MsInfo.Context, "all"));
    tags.add(new MetricsTag(MsInfo.Hostname, "host"));
    Set<AbstractMetric> metrics = new HashSet<AbstractMetric>();
    metrics.add(makeMetric("foo1", 1.25));
    metrics.add(makeMetric("foo2", 2.25));
    MetricsRecord record = new MetricsRecordImpl(MsInfo.Context, (long) 10000, tags, metrics);

    ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class);
    final GraphiteSink.Graphite mockGraphite = makeGraphite();
    Whitebox.setInternalState(sink, "graphite", mockGraphite);
    sink.putMetrics(record);

    try {
      verify(mockGraphite).write(argument.capture());
    } catch (IOException e) {
      e.printStackTrace();
    }

    String result = argument.getValue();

    assertEquals(true,
        result.equals("null.all.Context.Context=all.Hostname=host.foo1 1.25 10\n" +
        "null.all.Context.Context=all.Hostname=host.foo2 2.25 10\n") ||
        result.equals("null.all.Context.Context=all.Hostname=host.foo2 2.25 10\n" + 
        "null.all.Context.Context=all.Hostname=host.foo1 1.25 10\n"));
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:31,代码来源:TestGraphiteMetrics.java

示例3: testPutMetrics2

import org.apache.hadoop.metrics2.sink.GraphiteSink; //导入方法依赖的package包/类
@Test
public void testPutMetrics2() {
    GraphiteSink sink = new GraphiteSink();
    List<MetricsTag> tags = new ArrayList<MetricsTag>();
    tags.add(new MetricsTag(MsInfo.Context, "all"));
  tags.add(new MetricsTag(MsInfo.Hostname, null));
    Set<AbstractMetric> metrics = new HashSet<AbstractMetric>();
    metrics.add(makeMetric("foo1", 1));
    metrics.add(makeMetric("foo2", 2));
    MetricsRecord record = new MetricsRecordImpl(MsInfo.Context, (long) 10000, tags, metrics);


    ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class);
    final GraphiteSink.Graphite mockGraphite = makeGraphite();
    Whitebox.setInternalState(sink, "graphite", mockGraphite);
    sink.putMetrics(record);

    try {
        verify(mockGraphite).write(argument.capture());
    } catch (IOException e) {
        e.printStackTrace();
    }

    String result = argument.getValue();

    assertEquals(true,
        result.equals("null.all.Context.Context=all.foo1 1 10\n" + 
        "null.all.Context.Context=all.foo2 2 10\n") ||
        result.equals("null.all.Context.Context=all.foo2 2 10\n" + 
        "null.all.Context.Context=all.foo1 1 10\n"));
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:32,代码来源:TestGraphiteMetrics.java

示例4: testFailureAndPutMetrics

import org.apache.hadoop.metrics2.sink.GraphiteSink; //导入方法依赖的package包/类
@Test
public void testFailureAndPutMetrics() throws IOException {
  GraphiteSink sink = new GraphiteSink();
  List<MetricsTag> tags = new ArrayList<MetricsTag>();
  tags.add(new MetricsTag(MsInfo.Context, "all"));
  tags.add(new MetricsTag(MsInfo.Hostname, "host"));
  Set<AbstractMetric> metrics = new HashSet<AbstractMetric>();
  metrics.add(makeMetric("foo1", 1.25));
  metrics.add(makeMetric("foo2", 2.25));
  MetricsRecord record = new MetricsRecordImpl(MsInfo.Context, (long) 10000, tags, metrics);

  final GraphiteSink.Graphite mockGraphite = makeGraphite();
  Whitebox.setInternalState(sink, "graphite", mockGraphite);

  // throw exception when first try
  doThrow(new IOException("IO exception")).when(mockGraphite).write(anyString());

  sink.putMetrics(record);
  verify(mockGraphite).write(anyString());
  verify(mockGraphite).close();

  // reset mock and try again
  reset(mockGraphite);
  when(mockGraphite.isConnected()).thenReturn(false);

  ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class);
  sink.putMetrics(record);

  verify(mockGraphite).write(argument.capture());
  String result = argument.getValue();

  assertEquals(true,
      result.equals("null.all.Context.Context=all.Hostname=host.foo1 1.25 10\n" +
      "null.all.Context.Context=all.Hostname=host.foo2 2.25 10\n") ||
      result.equals("null.all.Context.Context=all.Hostname=host.foo2 2.25 10\n" +
      "null.all.Context.Context=all.Hostname=host.foo1 1.25 10\n"));
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:38,代码来源:TestGraphiteMetrics.java

示例5: testPutMetrics

import org.apache.hadoop.metrics2.sink.GraphiteSink; //导入方法依赖的package包/类
@Test
public void testPutMetrics() {
    GraphiteSink sink = new GraphiteSink();
    List<MetricsTag> tags = new ArrayList<MetricsTag>();
    tags.add(new MetricsTag(MsInfo.Context, "all"));
    tags.add(new MetricsTag(MsInfo.Hostname, "host"));
    Set<AbstractMetric> metrics = new HashSet<AbstractMetric>();
    metrics.add(makeMetric("foo1", 1.25));
    metrics.add(makeMetric("foo2", 2.25));
    MetricsRecord record = new MetricsRecordImpl(MsInfo.Context, (long) 10000, tags, metrics);

    OutputStreamWriter mockWriter = mock(OutputStreamWriter.class);
    ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class);
    Whitebox.setInternalState(sink, "writer", mockWriter);
    sink.putMetrics(record);

    try {
        verify(mockWriter).write(argument.capture());
    } catch (IOException e) {
        e.printStackTrace();
    }

    String result = argument.getValue().toString();

    assertEquals(true,
        result.equals("null.all.Context.Context=all.Hostname=host.foo1 1.25 10\n" +
        "null.all.Context.Context=all.Hostname=host.foo2 2.25 10\n") ||
        result.equals("null.all.Context.Context=all.Hostname=host.foo2 2.25 10\n" + 
        "null.all.Context.Context=all.Hostname=host.foo1 1.25 10\n"));
}
 
开发者ID:Nextzero,项目名称:hadoop-2.6.0-cdh5.4.3,代码行数:31,代码来源:TestGraphiteMetrics.java

示例6: testPutMetrics2

import org.apache.hadoop.metrics2.sink.GraphiteSink; //导入方法依赖的package包/类
@Test
public void testPutMetrics2() {
    GraphiteSink sink = new GraphiteSink();
    List<MetricsTag> tags = new ArrayList<MetricsTag>();
    tags.add(new MetricsTag(MsInfo.Context, "all"));
    tags.add(new MetricsTag(MsInfo.Hostname, null));
    Set<AbstractMetric> metrics = new HashSet<AbstractMetric>();
    metrics.add(makeMetric("foo1", 1));
    metrics.add(makeMetric("foo2", 2));
    MetricsRecord record = new MetricsRecordImpl(MsInfo.Context, (long) 10000, tags, metrics);

    OutputStreamWriter mockWriter = mock(OutputStreamWriter.class);
    ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class);
    Whitebox.setInternalState(sink, "writer", mockWriter);
    sink.putMetrics(record);

    try {
        verify(mockWriter).write(argument.capture());
    } catch (IOException e) {
        e.printStackTrace();
    }

    String result = argument.getValue().toString();

    assertEquals(true,
        result.equals("null.all.Context.Context=all.foo1 1 10\n" + 
        "null.all.Context.Context=all.foo2 2 10\n") ||
        result.equals("null.all.Context.Context=all.foo2 2 10\n" + 
        "null.all.Context.Context=all.foo1 1 10\n"));
}
 
开发者ID:Nextzero,项目名称:hadoop-2.6.0-cdh5.4.3,代码行数:31,代码来源:TestGraphiteMetrics.java

示例7: testPutMetrics3

import org.apache.hadoop.metrics2.sink.GraphiteSink; //导入方法依赖的package包/类
/**
 * Assert that timestamps are converted correctly, ticket HADOOP-11182
 */
@Test
public void testPutMetrics3() {

  // setup GraphiteSink
  GraphiteSink sink = new GraphiteSink();
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  Whitebox.setInternalState(sink, "writer", new OutputStreamWriter(out));

  // given two metrics records with timestamps 1000 milliseconds apart.
  List<MetricsTag> tags = Collections.emptyList();
  Set<AbstractMetric> metrics = new HashSet<AbstractMetric>();
  metrics.add(makeMetric("foo1", 1));
  MetricsRecord record1 = new MetricsRecordImpl(MsInfo.Context, 1000000000000L, tags, metrics);
  MetricsRecord record2 = new MetricsRecordImpl(MsInfo.Context, 1000000001000L, tags, metrics);

  sink.putMetrics(record1);
  sink.putMetrics(record2);

  sink.flush();
  try {
    sink.close();
  } catch(IOException e) {
    e.printStackTrace();
  }

  // then the timestamps in the graphite stream should differ by one second.
  String expectedOutput
    = "null.default.Context.foo1 1 1000000000\n"
    + "null.default.Context.foo1 1 1000000001\n";
  assertEquals(expectedOutput, out.toString());
}
 
开发者ID:Nextzero,项目名称:hadoop-2.6.0-cdh5.4.3,代码行数:35,代码来源:TestGraphiteMetrics.java


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