Java Code Examples for org.apache.hadoop.metrics2.MetricsTag#value()

The following examples show how to use org.apache.hadoop.metrics2.MetricsTag#value() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HadoopTimelineMetricsSink.java    From ambari-metrics with Apache License 2.0 6 votes vote down vote up
@InterfaceAudience.Private
public void appendPrefix(MetricsRecord record, StringBuilder sb) {
  String contextName = record.context();
  Collection<MetricsTag> tags = record.tags();
  if (useTagsMap.containsKey(contextName)) {
    Set<String> useTags = useTagsMap.get(contextName);
    for (MetricsTag t : tags) {
      if (useTags == null || useTags.contains(t.name())) {

        // the context is always skipped here because it is always added

        // the hostname is always skipped to avoid case-mismatches
        // from different DNSes.

        if (t.info() != MsInfo.Context && t.info() != MsInfo.Hostname && t.value() != null) {
          sb.append('.').append(t.name()).append('=').append(t.value());
        }
      }
    }
  }
}
 
Example 2
Source File: GangliaSink30.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@InterfaceAudience.Private
public void appendPrefix(MetricsRecord record, StringBuilder sb) {
  String contextName = record.context();
  Collection<MetricsTag> tags = record.tags();
  if (useTagsMap.containsKey(contextName)) {
    Set<String> useTags = useTagsMap.get(contextName);
    for (MetricsTag t : tags) {
      if (useTags == null || useTags.contains(t.name())) {

        // the context is always skipped here because it is always added
        
        // the hostname is always skipped to avoid case-mismatches 
        // from different DNSes.

        if (t.info() != MsInfo.Context && t.info() != MsInfo.Hostname && t.value() != null) {
          sb.append('.').append(t.name()).append('=').append(t.value());
        }
      }
    }
  }          
}
 
Example 3
Source File: GangliaSink30.java    From big-c with Apache License 2.0 6 votes vote down vote up
@InterfaceAudience.Private
public void appendPrefix(MetricsRecord record, StringBuilder sb) {
  String contextName = record.context();
  Collection<MetricsTag> tags = record.tags();
  if (useTagsMap.containsKey(contextName)) {
    Set<String> useTags = useTagsMap.get(contextName);
    for (MetricsTag t : tags) {
      if (useTags == null || useTags.contains(t.name())) {

        // the context is always skipped here because it is always added
        
        // the hostname is always skipped to avoid case-mismatches 
        // from different DNSes.

        if (t.info() != MsInfo.Context && t.info() != MsInfo.Hostname && t.value() != null) {
          sb.append('.').append(t.name()).append('=').append(t.value());
        }
      }
    }
  }          
}
 
Example 4
Source File: MetricsRecordImpl.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override public String context() {
  // usually the first tag
  for (MetricsTag t : tags) {
    if (t.info() == MsInfo.Context) {
      return t.value();
    }
  }
  return DEFAULT_CONTEXT;
}
 
Example 5
Source File: MetricsRecordImpl.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override public String context() {
  // usually the first tag
  for (MetricsTag t : tags) {
    if (t.info() == MsInfo.Context) {
      return t.value();
    }
  }
  return DEFAULT_CONTEXT;
}
 
Example 6
Source File: PhoenixMetricsSink.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private void addDynamicEntry(List<String> keys, List<Object> values,
        List<String> variableValues, String family, MetricsTag tag,
        MetricInfo metric, int count) {
    // <family><.dynColumn><count> <VARCHAR>
    keys.add(getDynamicColumnName(family, metric.columnName, count) + " VARCHAR");

    // build the annotation value
    String val = tag.description() + " - " + tag.value();
    values.add(VARIABLE_VALUE);
    variableValues.add(val);
}
 
Example 7
Source File: TestBalancerStatusTagInJMXMetrics.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the balancer status tag from the Metrics registry
 */
public String getStatus() throws Exception {
  MetricsSource source =
      DefaultMetricsSystem.instance().getSource(MetricsBalancerSource.METRICS_JMX_CONTEXT);
  if (source instanceof MetricsBalancerSourceImpl) {
    MetricsTag status = ((MetricsBalancerSourceImpl) source).getMetricsRegistry()
        .getTag(MetricsBalancerSource.BALANCER_STATUS);
    return status.value();
  } else {
    LOG.warn("Balancer JMX Metrics not registered");
    throw new Exception("MetricsBalancer JMX Context not found");
  }
}
 
Example 8
Source File: PhoenixMetricsSink.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private void addDynamicEntry(List<String> keys, List<Object> values,
        List<String> variableValues, String family, MetricsTag tag,
        MetricInfo metric, int count) {
    // <family><.dynColumn><count> <VARCHAR>
    keys.add(getDynamicColumnName(family, metric.columnName, count) + " VARCHAR");

    // build the annotation value
    String val = tag.description() + " - " + tag.value();
    values.add(VARIABLE_VALUE);
    variableValues.add(val);
}
 
Example 9
Source File: GraphiteSink.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Override
public void putMetrics(MetricsRecord record) {
    StringBuilder lines = new StringBuilder();
    StringBuilder metricsPathPrefix = new StringBuilder();

    // Configure the hierarchical place to display the graph.
    metricsPathPrefix.append(metricsPrefix).append(".")
            .append(record.context()).append(".").append(record.name());

    for (MetricsTag tag : record.tags()) {
        if (tag.value() != null) {
            metricsPathPrefix.append(".");
            metricsPathPrefix.append(tag.name());
            metricsPathPrefix.append("=");
            metricsPathPrefix.append(tag.value());
        }
    }

    // The record timestamp is in milliseconds while Graphite expects an epoc time in seconds.
    long timestamp = record.timestamp() / 1000L;

    // Collect datapoints.
    for (AbstractMetric metric : record.metrics()) {
        lines.append(
                metricsPathPrefix.toString() + "."
                        + metric.name().replace(' ', '.')).append(" ")
                .append(metric.value()).append(" ").append(timestamp)
                .append("\n");
    }

    try {
      graphite.write(lines.toString());
    } catch (Exception e) {
      LOG.warn("Error sending metrics to Graphite", e);
      try {
        graphite.close();
      } catch (Exception e1) {
        throw new MetricsException("Error closing connection to Graphite", e1);
      }
    }
}
 
Example 10
Source File: GraphiteSink.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Override
public void putMetrics(MetricsRecord record) {
    StringBuilder lines = new StringBuilder();
    StringBuilder metricsPathPrefix = new StringBuilder();

    // Configure the hierarchical place to display the graph.
    metricsPathPrefix.append(metricsPrefix).append(".")
            .append(record.context()).append(".").append(record.name());

    for (MetricsTag tag : record.tags()) {
        if (tag.value() != null) {
            metricsPathPrefix.append(".");
            metricsPathPrefix.append(tag.name());
            metricsPathPrefix.append("=");
            metricsPathPrefix.append(tag.value());
        }
    }

    // The record timestamp is in milliseconds while Graphite expects an epoc time in seconds.
    long timestamp = record.timestamp() / 1000L;

    // Collect datapoints.
    for (AbstractMetric metric : record.metrics()) {
        lines.append(
                metricsPathPrefix.toString() + "."
                        + metric.name().replace(' ', '.')).append(" ")
                .append(metric.value()).append(" ").append(timestamp)
                .append("\n");
    }

    try {
      graphite.write(lines.toString());
    } catch (Exception e) {
      LOG.warn("Error sending metrics to Graphite", e);
      try {
        graphite.close();
      } catch (Exception e1) {
        throw new MetricsException("Error closing connection to Graphite", e1);
      }
    }
}