Package org.apache.hadoop.metrics2

Examples of org.apache.hadoop.metrics2.MetricsTag


      .add("test.sink.ganglia.tagsForPrefix.none", "");
    GangliaSink30 sink = new GangliaSink30();
    sink.init(cb.subset("test.sink.ganglia"));

    List<MetricsTag> tags = new ArrayList<MetricsTag>();
    tags.add(new MetricsTag(MsInfo.Context, "all"));
    tags.add(new MetricsTag(MsInfo.NumActiveSources, "foo"));
    tags.add(new MetricsTag(MsInfo.NumActiveSinks, "bar"));
    tags.add(new MetricsTag(MsInfo.NumAllSinks, "haa"));
    tags.add(new MetricsTag(MsInfo.Hostname, "host"));
    Set<AbstractMetric> metrics = new HashSet<AbstractMetric>();
    MetricsRecord record = new MetricsRecordImpl(MsInfo.Context, (long) 1, tags, metrics);

    StringBuilder sb = new StringBuilder();
    sink.appendPrefix(record, sb);
    assertEquals(".NumActiveSources=foo.NumActiveSinks=bar.NumAllSinks=haa", sb.toString());

    tags.set(0, new MetricsTag(MsInfo.Context, "some"));
    sb = new StringBuilder();
    sink.appendPrefix(record, sb);
    assertEquals(".NumActiveSources=foo.NumActiveSinks=bar", sb.toString());

    tags.set(0, new MetricsTag(MsInfo.Context, "none"));
    sb = new StringBuilder();
    sink.appendPrefix(record, sb);
    assertEquals("", sb.toString());

    tags.set(0, new MetricsTag(MsInfo.Context, "nada"));
    sb = new StringBuilder();
    sink.appendPrefix(record, sb);
    assertEquals("", sb.toString());
  }
View Full Code Here


    when(mr.metrics()).thenReturn(metrics);
    return mr;
  }

  private MetricsTag makeTag(String name, String value) {
    return new MetricsTag(info(name, ""), value);
  }
View Full Code Here

    MetricsInfo info = info("m", "m desc");
    assertSame("same info", info, info("m", "m desc"));
  }

  @Test public void testTag() {
    MetricsTag tag = tag("t", "t desc", "t value");
    assertSame("same tag", tag, tag("t", "t desc", "t value"));
  }
View Full Code Here

    }
    assertNotSame("i1 is gone", i1,  info("m1", "m desc"));
  }

  @Test public void testTagOverflow() {
    MetricsTag t0 = tag("t0", "t desc", "t value");
    for (int i = 0; i < MAX_TAG_NAMES + 1; ++i) {
      tag("t"+ i, "t desc", "t value");
      if (i < MAX_TAG_NAMES) {
        assertSame("t0 still there", t0, tag("t0", "t desc", "t value"));
      }
    }
    assertNotSame("t0 is gone", t0, tag("t0", "t desc", "t value"));

    MetricsTag t1 = tag("t1", "t desc", "t value");
    for (int i = 0; i < MAX_TAG_VALUES; ++i) {
      tag("t1", "t desc", "t value"+ i);
      if (i < MAX_TAG_VALUES -1) {
        assertSame("t1 is still there", t1, tag("t1", "t desc", "t value"));
      }
View Full Code Here

    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);
View Full Code Here

   * @param value of the tag
   * @param override existing tag if true
   * @return the registry (for keep adding tags etc.)
   */
  public DynamicMetricsRegistry tag(MetricsInfo info, String value, boolean override) {
    MetricsTag tag = Interns.tag(info, value);

    if (!override) {
      MetricsTag existing = tagsMap.putIfAbsent(info.name(), tag);
      if (existing != null) {
        throw new MetricsException("Tag "+ info.name() +" already exists!");
      }
      return this;
    }
View Full Code Here

   * @param value of the tag
   * @param override existing tag if true
   * @return the registry (for keep adding tags etc.)
   */
  public DynamicMetricsRegistry tag(MetricsInfo info, String value, boolean override) {
    MetricsTag tag = Interns.tag(info, value);

    if (!override) {
      MetricsTag existing = tagsMap.putIfAbsent(info.name(), tag);
      if (existing != null) {
        throw new MetricsException("Tag "+ info.name() +" already exists!");
      }
      return this;
    }
View Full Code Here

   * @param override  existing tag if true
   * @return  the registry (for keep adding tags)
   */
  public DynamicMetricsRegistry tag(String name, String description, String value,
                             boolean override) {
    MetricsTag tag = new MetricsTag(name, description, value);

    if (!override) {
      MetricsTag existing = tagsMap.putIfAbsent(name, tag);
      if (existing != null) {
        throw new MetricsException("Tag "+ name +" already exists!");
      }
      return this;
    }
View Full Code Here

  static void checkMetricsRecords(List<MetricsRecord> recs, String expected) {
    LOG.debug(recs);
    MetricsRecord r = recs.get(0);
    assertEquals("name", expected, r.name());
    assertEquals("tags", new MetricsTag[] {
      new MetricsTag("context", "Metrics context", "test"),
      new MetricsTag("hostName", "Local hostname", hostname)}, r.tags());
    assertEquals("metrics", new Metric[] {
      new MetricCounterLong("c1", "c1 desc", 1),
      new MetricGaugeLong("g1", "g1 desc", 2),
      new MetricCounterLong("s1_num_ops", "Number of ops for s1 desc", 1),
      new MetricGaugeDouble("s1_avg_time", "Average time for s1 desc", 0)},
View Full Code Here

   * @return  the registry (for keep adding tags)
   */
  public MetricsRegistry tag(String name, String description, String value,
                             boolean override) {
    if (!override) checkTagName(name);
    tagsMap.put(name, new MetricsTag(name, description, value));
    return this;
  }
View Full Code Here

TOP

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

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.