java - How to access Hadoop counters values via API? -
in hadoop can increment counter in map/reduce task, looks this:
... context.getcounter(mycountersenum.somecounter).increment(1); ...
than can find value in log.
how access them code after job completes?
what hadoop api read counter value?
counters represent global counters, defined either map-reduce framework or applications.
each counter can of enum type. can define counter enum in driver class
static enum updatecount{ cnt }
and increment counter in map/reduce task
public class cntreducer extends reducer<intwritable, text, intwritable, text>{ public void reduce(intwritable key,iterable<text> values,context context) { //do context.getcounter(updatecount.cnt).increment(1); } }
and access them in driver class
public int run(string[] args) throws exception { . . . job.setinputformatclass(textinputformat.class); job.setoutputformatclass(textoutputformat.class); fileinputformat.setinputpaths(job,in ); fileoutputformat.setoutputpath(job, out); job.waitforcompletion(true); c = job.getcounters().findcounter(updatecount.cnt).getvalue(); //print "c" } }
c gives counter value.
you can find example here
Comments
Post a Comment