Example usage for org.apache.hadoop.mapreduce Job getCounters

List of usage examples for org.apache.hadoop.mapreduce Job getCounters

Introduction

In this page you can find the example usage for org.apache.hadoop.mapreduce Job getCounters.

Prototype

public Counters getCounters() throws IOException 

Source Link

Document

Gets the counters for this job.

Usage

From source file:sixdegrees.LevelData.java

License:Apache License

public void execute(String args[]) throws IOException, ClassNotFoundException, InterruptedException {
    Configuration conf = new Configuration();
    String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
    if (otherArgs.length != 2) {
        System.err.println("Usage: Level Data <in> <out>");
        System.exit(2);// ww  w . j a v a2s.  co m
    }
    Job job = new Job(conf, "level data");
    job.setJarByClass(LevelData.class);
    job.setMapperClass(LevelMapper.class);
    // No Combiner

    job.setReducerClass(LevelReducer.class);
    job.setOutputKeyClass(IntWritable.class);
    job.setOutputValueClass(IntWritable.class);
    job.setNumReduceTasks(6);
    FileInputFormat.addInputPath(job, new Path(args[1] + "6"));
    FileOutputFormat.setOutputPath(job, new Path(args[1] + "final"));
    job.waitForCompletion(true);
    Counters counters = job.getCounters();
    Counter c1 = (Counter) counters.findCounter(NODE_COUNTER.TOTAL_NODES);
    int totalNodes = (int) c1.getValue();
    Counter c2 = (Counter) counters.findCounter(NODE_COUNTER.DEGREE_COUNT);
    int totalDegrees = (int) c2.getValue();
    System.out.println("Average: " + (float) totalDegrees / (totalNodes - 1));
}