hadoop中有自带的计数器,原理及定义,网上到处都是解释,这里不再班门弄斧。
介绍使用方法:
context有一个方法getCounter,参数类型为(Enum)枚举类型。
1、定义枚举
static enum AA{
A
}
如果有多种计数类型,可以继续定义。
2、在Mapper或reduce中写入:
context.getCounter(AA.A).increment(1);
3、在job执行完以后,
Counters counters = job.getCounters();
Counter counter = counters.findCounter(AA.A);
System.out.println(counter.getValue());
Counter也可用来统计指定字符串出现的次数等。