定义:
hadoop计数器:可以让开发人员以全局的视角来审查程序的运行情况以及各项指标,及时做出错误诊断并进行相应处理。
内置计数器(MapReduce相关、文件系统相关和作业调度相关)
例子:(内置计数器)
Counters: 19
File Output Format Counters
Bytes Written=19 <span style="white-space:pre"> </span>//reduce输出到hdfs的字节数
FileSystemCounters
FILE_BYTES_READ=481
HDFS_BYTES_READ=38
FILE_BYTES_WRITTEN=81316
HDFS_BYTES_WRITTEN=19
File Input Format Counters
Bytes Read=19 <span style="white-space:pre"> </span>//map从hdfs读取的字节数
Map-Reduce Framework
Map output materialized bytes=49
Map input records=2 //map读入的记录行数
Reduce shuffle bytes=0
Spilled Records=8
Map output bytes=35
Total committed heap usage (bytes)=266469376
SPLIT_RAW_BYTES=105
Combine input records=0
Reduce input records=4 //reduce从map端接收的记录行数
Reduce input groups=3 //reduce函数接收的key数量,即归并后的k2数量
Combine output records=0
Reduce output records=3 //reduce输出的记录行数
Map output records=4 //map输出的记录行数
例子:(自定义计数器)
<span style="white-space:pre"> </span>final Counter helloCounter = context.getCounter("Sensitive Words", "hello");
final String line = v1.toString();
if(line.contains("hello")){
//如果出现hello,则计数一次
helloCounter.increment(1L);
}