Package org.apache.hadoop.metrics2

Examples of org.apache.hadoop.metrics2.MetricsTag


  @Test public void excludeOnlyShouldOnlyExcludeMatched() {
    SubsetConfiguration bl = new ConfigBuilder()
        .add("p.exclude", "foo")
        .add("p.exclude.tags", "foo:f").subset("p");
    shouldAccept(bl, "bar");
    shouldAccept(bl, Arrays.asList(new MetricsTag("bar", "", "")));
    shouldAccept(bl, mockMetricsRecord("bar", Arrays.asList(
      new MetricsTag("bar", "", ""))));
    shouldReject(bl, "foo");
    shouldReject(bl, Arrays.asList(new MetricsTag("bar", "", ""),
                                   new MetricsTag("foo", "", "f")));
    shouldReject(bl, mockMetricsRecord("foo", Arrays.asList(
      new MetricsTag("bar", "", ""))));
    shouldReject(bl, mockMetricsRecord("bar", Arrays.asList(
      new MetricsTag("bar", "", ""),
      new MetricsTag("foo", "", "f"))));
  }
View Full Code Here


        .add("p.include", "foo")
        .add("p.include.tags", "foo:f")
        .add("p.exclude", "bar")
        .add("p.exclude.tags", "bar:b").subset("p");
    shouldAccept(c, "foo");
    shouldAccept(c, Arrays.asList(new MetricsTag("foo", "", "f")));
    shouldAccept(c, mockMetricsRecord("foo", Arrays.asList(
      new MetricsTag("foo", "", "f"))));
    shouldReject(c, "bar");
    shouldReject(c, Arrays.asList(new MetricsTag("bar", "", "b")));
    shouldReject(c, mockMetricsRecord("bar", Arrays.asList(
      new MetricsTag("foo", "", "f"))));
    shouldReject(c, mockMetricsRecord("foo", Arrays.asList(
      new MetricsTag("bar", "", "b"))));
    shouldAccept(c, "foobar");
    shouldAccept(c, Arrays.asList(new MetricsTag("foobar", "", "")));
    shouldAccept(c, mockMetricsRecord("foobar", Arrays.asList(
      new MetricsTag("foobar", "", ""))));
  }
View Full Code Here

        .add("p.include", "foo")
        .add("p.include.tags", "foo:f")
        .add("p.exclude", "foo")
        .add("p.exclude.tags", "foo:f").subset("p");
    shouldAccept(c, "foo");
    shouldAccept(c, Arrays.asList(new MetricsTag("foo", "", "f")));
    shouldAccept(c, mockMetricsRecord("foo", Arrays.asList(
      new MetricsTag("foo", "", "f"))));
  }
View Full Code Here

    configureSources();
    configureSystem();
  }

  private synchronized void configureSystem() {
    injectedTags.add(new MetricsTag("hostName", "Local hostname",
                                    getHostname()));
  }
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

   * @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

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

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

    builder.addCounter(Interns.info(PARENT.traceName, EMPTY_STRING), span.getParentId());
    builder.addCounter(Interns.info(START.traceName, EMPTY_STRING), span.getStartTimeMillis());
    builder.addCounter(Interns.info(END.traceName, EMPTY_STRING), span.getStopTimeMillis());
    // add the tags to the span. They were written in order received so we mark them as such
    for (TimelineAnnotation ta : span.getTimelineAnnotations()) {
      builder.add(new MetricsTag(Interns.info(TAG.traceName, Long.toString(ta.getTime())), ta
          .getMessage()));
    }

    // add the annotations. We assume they are serialized as strings and integers, but that can
    // change in the future
    Map<byte[], byte[]> annotations = span.getKVAnnotations();
    for (Entry<byte[], byte[]> annotation : annotations.entrySet()) {
      Pair<String, String> val =
          TracingCompat.readAnnotation(annotation.getKey(), annotation.getValue());
      builder.add(new MetricsTag(Interns.info(ANNOTATION.traceName, val.getFirst()), val
          .getSecond()));
    }

    // add the span to the list we care about
    synchronized (this) {
View Full Code Here

  public void getMetrics(MetricsCollector collector, boolean all) {
    // add a marker record so we know how many spans are used
    // this is also necessary to ensure that we register the metrics source as an MBean (avoiding a
    // runtime warning)
    MetricsRecordBuilder marker = collector.addRecord(TracingCompat.METRICS_MARKER_CONTEXT);
    marker.add(new MetricsTag(new MetricsInfoImpl("stat", "num spans"), Integer
        .toString(spans.size())));

    // actually convert the known spans into metric records as well
    synchronized (this) {
      for (Metric span : spans) {
View Full Code Here

        MetricInfo.END.traceName, ""), endTime);
    final List<AbstractMetric> metrics = Lists.newArrayList(span, parent, start, end);

    // create an annotation as well
    String annotation = "test annotation for a span";
    MetricsTag tag = new MetricsTag(
        new ExposedMetricsInfoImpl(MetricInfo.ANNOTATION.traceName, "0"), annotation);
    String hostnameValue = "host-name.value";
    MetricsTag hostname = new MetricsTag(new ExposedMetricsInfoImpl(MetricInfo.HOSTNAME.traceName,
        ""), hostnameValue);
    final List<MetricsTag> tags = Lists.newArrayList(hostname, tag);

    MetricsRecord record = new ExposedMetricsRecordImpl(info, System.currentTimeMillis(), tags,
        metrics);
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.