Package org.apache.hadoop.metrics2

Examples of org.apache.hadoop.metrics2.MetricsFilter


      writer = filename == null
          ? new PrintWriter(System.out)
          : new PrintWriter(new FileWriter(new File(filename), true));
    }
    catch (Exception e) {
      throw new MetricsException("Error creating "+ filename, e);
    }
  }
View Full Code Here


        try {
            // Open an connection to Graphite server.
            socket = new Socket(serverHost, serverPort);
            writer = new OutputStreamWriter(socket.getOutputStream());
        } catch (Exception e) {
            throw new MetricsException("Error creating connection, "
                    + serverHost + ":" + serverPort, e);
        }
    }
View Full Code Here

        try {
            if(writer != null){
              writer.write(lines.toString());
            } else {
              throw new MetricsException("Writer in GraphiteSink is null!");
            }
        } catch (Exception e) {
            throw new MetricsException("Error sending metrics", e);
        }
    }
View Full Code Here

    @Override
    public void flush() {
        try {
            writer.flush();
        } catch (Exception e) {
            throw new MetricsException("Error flushing metrics", e);
        }
    }
View Full Code Here

      try {
        IOUtils.closeStream(writer);
        writer = null;
        LOG.info("writer in GraphiteSink is closed!");
      } catch (Throwable e){
        throw new MetricsException("Error closing writer", e);
      } finally {
        if (socket != null && !socket.isClosed()) {
          socket.close();
          socket = null;
          LOG.info("socket in GraphiteSink is closed!");
View Full Code Here

  MetricsFilter getFilter(String prefix) {
    // don't create filter instances without out options
    MetricsConfig conf = subset(prefix);
    if (conf.isEmpty()) return null;
    MetricsFilter filter = getPlugin(prefix);
    if (filter != null) return filter;
    // glob filter is assumed if pattern is specified but class is not.
    filter = new GlobFilter();
    filter.init(conf);
    return filter;
  }
View Full Code Here

    shouldAcceptImpl(false, conf, tags, expectedAcceptedSpec);
  }
 
  private static void shouldAcceptImpl(final boolean expectAcceptList, 
      SubsetConfiguration conf, List<MetricsTag> tags, boolean[] expectedAcceptedSpec) {
    final MetricsFilter globFilter = newGlobFilter(conf);
    final MetricsFilter regexFilter = newRegexFilter(conf);
   
    // Test acceptance of the tag list: 
    assertEquals("accepts "+ tags, expectAcceptList, globFilter.accepts(tags));
    assertEquals("accepts "+ tags, expectAcceptList, regexFilter.accepts(tags));
   
    // Test results on each of the individual tags:
    int acceptedCount = 0;
    for (int i=0; i<tags.size(); i++) {
      MetricsTag tag = tags.get(i);
      boolean actGlob = globFilter.accepts(tag);
      boolean actRegex = regexFilter.accepts(tag);
      assertEquals("accepts "+tag, expectedAcceptedSpec[i], actGlob);
      // Both the filters should give the same result:
      assertEquals(actGlob, actRegex);
      if (actGlob) {
        acceptedCount++;
View Full Code Here

  MetricsFilter getFilter(String prefix) {
    // don't create filter instances without out options
    MetricsConfig conf = subset(prefix);
    if (conf.isEmpty()) return null;
    MetricsFilter filter = getPlugin(prefix);
    if (filter != null) return filter;
    // glob filter is assumed if pattern is specified but class is not.
    filter = new GlobFilter();
    filter.init(conf);
    return filter;
  }
View Full Code Here

  @Override public synchronized <T>
  T register(String name, String desc, T source) {
    MetricsSourceBuilder sb = MetricsAnnotations.newSourceBuilder(source);
    final MetricsSource s = sb.build();
    MetricsInfo si = sb.info();
    String name2 = name == null ? si.name() : name;
    final String finalDesc = desc == null ? si.description() : desc;
    final String finalName = // be friendly to non-metrics tests
        DefaultMetricsSystem.sourceName(name2, !monitoring);
    allSources.put(finalName, s);
    LOG.debug(finalName +", "+ finalDesc);
    if (monitoring) {
View Full Code Here

    ms.shutdown();
  }

  private void checkMetricsRecords(List<MetricsRecord> recs) {
    LOG.debug(recs);
    MetricsRecord r = recs.get(0);
    assertEquals("name", "s1rec", r.name());
    assertEquals("tags", new MetricsTag[] {
      tag(MsInfo.Context, "test"),
      tag(MsInfo.Hostname, hostname)}, r.tags());
    assertEquals("metrics", MetricsLists.builder("")
      .addCounter(info("C1", "C1 desc"), 1L)
      .addGauge(info("G1", "G1 desc"), 2L)
      .addCounter(info("S1NumOps", "Number of ops for s1"), 1L)
      .addGauge(info("S1AvgTime", "Average time for s1"), 0.0)
      .metrics(), r.metrics());

    r = recs.get(1);
    assertTrue("NumActiveSinks should be 3", Iterables.contains(r.metrics(),
               new MetricGaugeInt(MsInfo.NumActiveSinks, 3)));
  }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.metrics2.MetricsFilter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.