private Map<String, Double> extractAllCounterValues(Counters counters) { Map<String, Double> exctractedCounters = new HashMap<String, Double>(); for (Counters.Group cg : counters) { for (Counter c : cg) { exctractedCounters.put(cg.getName() + "::" + c.getName(), new Double(c.getCounter())); } } return exctractedCounters; }
private Map<String, Double> extractAllCounterValues(Counters counters) { Map<String, Double> exctractedCounters = new HashMap<String, Double>(); for (Counters.Group cg : counters) { for (Counter c : cg) { exctractedCounters.put(cg.getName() + "::" + c.getName(), new Double(c.getCounter())); } } return exctractedCounters; }
public CounterGroup(Counters.Group group) { this.groupName = group.getName(); this.groupDisplayName = group.getDisplayName(); this.counterInfoMap = Maps.newHashMap(); for (Counter counter : group) { CounterInfo counterInfo = new CounterInfo(counter); counterInfoMap.put(counterInfo.getName(), counterInfo); } }
/** * Write the set of groups. * The external format is: * #groups (groupName group)* * * i.e. the number of groups followed by 0 or more groups, where each * group is of the form: * * groupDisplayName #counters (false | true counter)* * * where each counter is of the form: * * name (false | true displayName) value */ public synchronized void write(DataOutput out) throws IOException { out.writeInt(counters.size()); for (Group group: counters.values()) { Text.writeString(out, group.getName()); group.write(out); } }
public static Counters toYarn(org.apache.hadoop.mapred.Counters counters) { if (counters == null) { return null; } Counters yCntrs = recordFactory.newRecordInstance(Counters.class); yCntrs.addAllCounterGroups(new HashMap<String, CounterGroup>()); for (org.apache.hadoop.mapred.Counters.Group grp : counters) { CounterGroup yGrp = recordFactory.newRecordInstance(CounterGroup.class); yGrp.setName(grp.getName()); yGrp.setDisplayName(grp.getDisplayName()); yGrp.addAllCounters(new HashMap<String, Counter>()); for (org.apache.hadoop.mapred.Counters.Counter cntr : grp) { Counter yCntr = recordFactory.newRecordInstance(Counter.class); yCntr.setName(cntr.getName()); yCntr.setDisplayName(cntr.getDisplayName()); yCntr.setValue(cntr.getValue()); yGrp.setCounter(yCntr.getName(), yCntr); } yCntrs.setCounterGroup(yGrp.getName(), yGrp); } return yCntrs; }
public static Counters toYarn(org.apache.hadoop.mapred.Counters counters) { if (counters == null) { return null; } Counters yCntrs = recordFactory.newRecordInstance(Counters.class); yCntrs.addAllCounterGroups(new HashMap<String, CounterGroup>()); for (org.apache.hadoop.mapred.Counters.Group grp : counters) { CounterGroup yGrp = recordFactory.newRecordInstance(CounterGroup.class); yGrp.setName(grp.getName()); yGrp.setDisplayName(grp.getDisplayName()); yGrp.addAllCounters(new HashMap<String, Counter>()); for (org.apache.hadoop.mapred.Counters.Counter cntr : grp) { Counter yCntr = recordFactory.newRecordInstance(Counter.class); yCntr.setName(cntr.getName()); yCntr.setDisplayName(cntr.getDisplayName()); yCntr.setValue(cntr.getValue()); yGrp.setCounter(yCntr.getName(), yCntr); } yCntrs.setCounterGroup(yGrp.getName(), yGrp); } return yCntrs; }
public static void main(String[] args) throws Exception { if (args.length != 1) { System.out.println ("Usage : java PrintCounters <job id>"); System.exit(1); } RunningJob job = new JobClient().getJob(JobID.forName(args[0])); // RunningJob job = new JobClient().getJob(new JobID("job_201309211454", 9)); // RunningJob job = new JobClient().getJob(args[0]); Counters counters = job.getCounters(); for (Counters.Group group : counters) { System.out.println("- Counter Group: " + group.getDisplayName() + " (" + group.getName() + ")"); System.out.println(" number of counters in this group: " + group.size()); for (Counters.Counter counter : group) { System.out.println(" - " + counter.getDisplayName() + ": " + counter.getName()); } } }
/** * Increments multiple counters by their amounts in another Counters * instance. * @param other the other Counters instance */ public synchronized void incrAllCounters(Counters other) { for (Group otherGroup: other) { Group group = getGroup(otherGroup.getName()); group.displayName = otherGroup.displayName; for (Counter otherCounter : otherGroup) { Counter counter = group.getCounterForName(otherCounter.getName()); counter.setDisplayName(otherCounter.getDisplayName()); counter.increment(otherCounter.getValue()); } } }
/** * Increments multiple counters by their amounts in another Counters * instance. * @param other the other Counters instance */ public synchronized void incrAllCounters(Counters other) { for (Group otherGroup: other) { Group group = getGroup(otherGroup.getName()); group.setDisplayName(otherGroup.getDisplayName()); for (Counter otherCounter : otherGroup) { Counter counter = group.getCounterForName(otherCounter.getName()); counter.setDisplayName(otherCounter.getDisplayName()); counter.increment(otherCounter.getValue()); } } }
/** * Increments multiple counters by their amounts in another Counters * instance. * @param other the other Counters instance */ public synchronized void incrAllCounters(Counters other) { for (Group otherGroup: other) { Group group = getGroup(otherGroup.getName()); group.displayName = otherGroup.displayName; for (Counter otherCounter : otherGroup) { Counter counter = group.getCounterForName(otherCounter.getName()); counter.setDisplayName(otherCounter.getDisplayName()); counter.increment(otherCounter.getValue()); } } }
/** * Increments multiple counters by their amounts in another Counters * instance. * @param other the other Counters instance */ public synchronized void incrAllCounters(Counters other) { for (Group otherGroup: other) { Group group = getGroup(otherGroup.getName()); group.setDisplayName(otherGroup.getDisplayName()); for (Counter otherCounter : otherGroup) { Counter counter = group.getCounterForName(otherCounter.getName()); counter.setDisplayName(otherCounter.getDisplayName()); counter.increment(otherCounter.getValue()); } } }
/** * Utility method to create a Counters object from the * org.apache.hadoop.mapred counters * @param counters */ public Counters(org.apache.hadoop.mapred.Counters counters) { for(org.apache.hadoop.mapred.Counters.Group group: counters) { String name = group.getName(); CounterGroup newGroup = new CounterGroup(name, group.getDisplayName()); groups.put(name, newGroup); for(Counter counter: group) { newGroup.addCounter(counter); } } }
/** * Increments multiple counters by their amounts in another Counters * instance. * @param other the other Counters instance */ public synchronized void incrAllCounters(Counters other) { for (Group otherGroup: other) { Group group = getGroup(otherGroup.getName()); group.setDisplayName(otherGroup.getDisplayName()); for (Counter otherCounter : otherGroup) { Counter counter = group.getCounterForName(otherCounter.getName()); counter.setDisplayName(otherCounter.getDisplayName()); counter.increment(otherCounter.getValue()); } } }
/** * Increments multiple counters by their amounts in another Counters * instance. * @param other the other Counters instance */ public synchronized void incrAllCounters(Counters other) { for (Group otherGroup: other) { Group group = getGroup(otherGroup.getName()); group.setDisplayName(otherGroup.getDisplayName()); for (Counter otherCounter : otherGroup) { Counter counter = group.getCounterForName(otherCounter.getName()); counter.setDisplayName(otherCounter.getDisplayName()); counter.increment(otherCounter.getValue()); } } }
/** * Increments multiple counters by their amounts in another Counters * instance. * @param other the other Counters instance */ public synchronized void incrAllCounters(Counters other) { for (Group otherGroup: other) { Group group = getGroup(otherGroup.getName()); group.displayName = otherGroup.displayName; for (Counter otherCounter : otherGroup) { Counter counter = group.getCounterForName(otherCounter.getName()); counter.displayName = otherCounter.displayName; counter.value += otherCounter.value; } } }
@Override public synchronized void incrAllCounters( org.apache.hadoop.mapred.Counters other) { for (Group otherGroup: other) { Group group = getGroup(otherGroup.getName()); group.setDisplayName(otherGroup.getDisplayName()); for (Counter otherCounter : otherGroup) { Counter counter = group.getCounterForName(otherCounter.getName()); counter.setDisplayName(otherCounter.getDisplayName()); counter.increment(otherCounter.getValue()); } } }
private static List<Counter> getAllFromHadoopGroup(org.apache.hadoop.mapred.Counters.Group counterGroup) { Iterator<org.apache.hadoop.mapred.Counters.Counter> counterIterator = counterGroup.iterator(); List<Counter> counters = new ArrayList<>(); while (counterIterator.hasNext()) { org.apache.hadoop.mapred.Counters.Counter counter = counterIterator.next(); counters.add(new Counter(counterGroup.getName(), counter.getName(), counter.getValue())); } return counters; }
@Override public void map(Counters key, NullWritable value, OutputCollector<Text, Text> collector, Reporter reporter) throws IOException { for (Group group : key) { for (Counter counter : group) { reporter.incrCounter(group.getName(), counter.getName(), counter.getValue()); } } }
Counters(org.apache.hadoop.mapred.Counters counters) { for(org.apache.hadoop.mapred.Counters.Group group: counters) { String name = group.getName(); CounterGroup newGroup = new CounterGroup(name, group.getDisplayName()); groups.put(name, newGroup); for(Counter counter: group) { newGroup.addCounter(counter); } } }
private Map<String, Double> extractAllCounterValues(Counters counters) { Map<String, Double> exctractedCounters = new HashMap<String, Double>(); for (Counters.Group cg : counters) { for (Counter c : cg) { exctractedCounters.put(cg.getName() + "::" + c.getName(), new Double(c.getCounter())); } } return exctractedCounters; }