本文整理汇总了Java中org.apache.hadoop.metrics2.AbstractMetric类的典型用法代码示例。如果您正苦于以下问题:Java AbstractMetric类的具体用法?Java AbstractMetric怎么用?Java AbstractMetric使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AbstractMetric类属于org.apache.hadoop.metrics2包,在下文中一共展示了AbstractMetric类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: putMetrics
import org.apache.hadoop.metrics2.AbstractMetric; //导入依赖的package包/类
@Override
public void putMetrics(MetricsRecord record) {
writer.print(record.timestamp());
writer.print(" ");
writer.print(record.context());
writer.print(".");
writer.print(record.name());
String separator = ": ";
for (MetricsTag tag : record.tags()) {
writer.print(separator);
separator = ", ";
writer.print(tag.name());
writer.print("=");
writer.print(tag.value());
}
for (AbstractMetric metric : record.metrics()) {
writer.print(separator);
separator = ", ";
writer.print(metric.name());
writer.print("=");
writer.print(metric.value());
}
writer.println();
}
示例2: update
import org.apache.hadoop.metrics2.AbstractMetric; //导入依赖的package包/类
/**
* Update the cache and return the current cached record
* @param mr the update record
* @param includingTags cache tag values (for later lookup by name) if true
* @return the updated cache record
*/
public Record update(MetricsRecord mr, boolean includingTags) {
String name = mr.name();
RecordCache recordCache = map.get(name);
if (recordCache == null) {
recordCache = new RecordCache();
map.put(name, recordCache);
}
Collection<MetricsTag> tags = mr.tags();
Record record = recordCache.get(tags);
if (record == null) {
record = new Record();
recordCache.put(tags, record);
}
for (AbstractMetric m : mr.metrics()) {
record.metrics.put(m.name(), m);
}
if (includingTags) {
// mostly for some sinks that include tags as part of a dense schema
for (MetricsTag t : mr.tags()) {
record.tags.put(t.name(), t.value());
}
}
return record;
}
示例3: get
import org.apache.hadoop.metrics2.AbstractMetric; //导入依赖的package包/类
MBeanInfo get() {
curRecNo = 0;
for (MetricsRecordImpl rec : recs) {
for (MetricsTag t : rec.tags()) {
attrs.add(newAttrInfo("tag."+ t.name(), t.description(),
"java.lang.String"));
}
for (AbstractMetric m : rec.metrics()) {
m.visit(this);
}
++curRecNo;
}
MetricsSystemImpl.LOG.debug(attrs);
MBeanAttributeInfo[] attrsArray = new MBeanAttributeInfo[attrs.size()];
return new MBeanInfo(name, description, attrs.toArray(attrsArray),
null, null, null); // no ops/ctors/notifications
}
示例4: updateAttrCache
import org.apache.hadoop.metrics2.AbstractMetric; //导入依赖的package包/类
private int updateAttrCache() {
LOG.debug("Updating attr cache...");
int recNo = 0;
int numMetrics = 0;
for (MetricsRecordImpl record : lastRecs) {
for (MetricsTag t : record.tags()) {
setAttrCacheTag(t, recNo);
++numMetrics;
}
for (AbstractMetric m : record.metrics()) {
setAttrCacheMetric(m, recNo);
++numMetrics;
}
++recNo;
}
LOG.debug("Done. # tags & metrics="+ numMetrics);
return numMetrics;
}
示例5: metrics
import org.apache.hadoop.metrics2.AbstractMetric; //导入依赖的package包/类
@Override public Iterable<AbstractMetric> metrics() {
return new Iterable<AbstractMetric>() {
final Iterator<AbstractMetric> it = delegate.metrics().iterator();
@Override public Iterator<AbstractMetric> iterator() {
return new AbstractIterator<AbstractMetric>() {
@Override public AbstractMetric computeNext() {
while (it.hasNext()) {
AbstractMetric next = it.next();
if (filter.accepts(next.name())) {
return next;
}
}
return endOfData();
}
};
}
};
}
示例6: putMetrics
import org.apache.hadoop.metrics2.AbstractMetric; //导入依赖的package包/类
@Override
public void putMetrics(MetricsRecord record) {
final String prefix = "threadSourceRec";
if (record.name().startsWith(prefix)) {
final int recordNumber = Integer.parseInt(
record.name().substring(prefix.length()));
ArrayList<String> names = new ArrayList<String>();
for (AbstractMetric m : record.metrics()) {
if (m.name().equalsIgnoreCase("g1")) {
collected[recordNumber].set(m.value().longValue());
return;
}
names.add(m.name());
}
}
}
示例7: getLatestMetricValue
import org.apache.hadoop.metrics2.AbstractMetric; //导入依赖的package包/类
public Number getLatestMetricValue(String metricName, Number defaultValue)
throws IndexOutOfBoundsException{
boolean found = false;
Number ret = null;
for (MetricsRecord currentRecord : allMetrics) {
// First check if this record is coming for my file system.
if (wasGeneratedByMe(currentRecord)) {
for (AbstractMetric currentMetric : currentRecord.metrics()) {
if (currentMetric.name().equalsIgnoreCase(metricName)) {
found = true;
ret = currentMetric.value();
break;
}
}
}
}
if (!found) {
if (defaultValue != null) {
return defaultValue;
}
throw new IndexOutOfBoundsException(metricName);
}
return ret;
}
示例8: putMetrics
import org.apache.hadoop.metrics2.AbstractMetric; //导入依赖的package包/类
/**
* add a metrics record in the sink
*
* @param record the record to add
*/
@Override
public void putMetrics(MetricsRecord record) {
// let us do this only once, otherwise
// our count could go out of sync.
if (count == 0) {
for (AbstractMetric m : record.metrics()) {
if (nameMap.contains(m.name())) {
count++;
}
}
for (MetricsTag t : record.tags()) {
if (nameMap.contains(t.name())) {
count++;
}
}
}
}
示例9: testCloseAndWrite
import org.apache.hadoop.metrics2.AbstractMetric; //导入依赖的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);
}