hadoop 计数器

一、hadoop有非常多自带的计数器,相信看过执行log的都会看到各种数据
二、用户自己定义计数器
在开发中常常须要记录错误的数据条数,就能够用计数器来解决。

1、定义:用一个枚举来定义一组计数器,枚举中的每一个元素都是一个计数器

在main类中定义

enum RecordsCounter{
    RIGHT_COUNTER,
    WRONG_COUNTER
  };

2、使用
在map和reduce端均可使用,job会在技术后收集数据。
在须要记录的地方:
context.getCounter(RecordsCounter.WRONG_COUNTER).increment(1);

在run函数中,在job运行完后得到结果:

Counters counters = job.getCounters();
Counter counter = counters.findCounter(RecordsCounter.WRONG_COUNTER);
Long wrongCount = counter.getValue();


原文地址:https://www.cnblogs.com/jzssuanfa/p/7121243.html