| 45 | } |
| 46 | |
| 47 | @SuppressWarnings("unchecked") |
| 48 | public static final void recordJobStatus(String label, Job job, |
| 49 | Map<String, Object> results) { |
| 50 | Map<String, Object> jobs = (Map<String, Object>) results |
| 51 | .get(Nutch.STAT_JOBS); |
| 52 | if (jobs == null) { |
| 53 | jobs = new LinkedHashMap<String, Object>(); |
| 54 | results.put(Nutch.STAT_JOBS, jobs); |
| 55 | } |
| 56 | Map<String, Object> stats = new HashMap<String, Object>(); |
| 57 | Map<String, Object> countStats = new HashMap<String, Object>(); |
| 58 | try { |
| 59 | Counters counters = job.getCounters(); |
| 60 | for (CounterGroup cg : counters) { |
| 61 | Map<String, Object> cnts = new HashMap<String, Object>(); |
| 62 | countStats.put(cg.getDisplayName(), cnts); |
| 63 | for (Counter c : cg) { |
| 64 | cnts.put(c.getName(), c.getValue()); |
| 65 | } |
| 66 | } |
| 67 | } catch (Exception e) { |
| 68 | countStats.put("error", e.toString()); |
| 69 | } |
| 70 | stats.put(Nutch.STAT_COUNTERS, countStats); |
| 71 | stats.put("jobName", job.getJobName()); |
| 72 | stats.put("jobID", job.getJobID()); |
| 73 | if (label == null) { |
| 74 | label = job.getJobName(); |
| 75 | if (job.getJobID() != null) { |
| 76 | label = label + "-" + job.getJobID(); |
| 77 | } |
| 78 | } |
| 79 | jobs.put(label, stats); |
| 80 | } |
| 81 | } |