1

当我们在 Hadoop 上运行数据密集型作业时。Hadoop 执行该作业。现在我想要的是工作完成时。它会给我有关已执行工作的统计信息,即;消耗的时间、mapper 数量、reducer 数量和其他有用信息。

作业执行期间在浏览器中显示的信息,如作业跟踪器、数据节点。但是我怎样才能在我的应用程序中获得统计数据,该应用程序通过 Hadoop 运行作业并在作业完成结束时给我提供报告之类的结果。我的应用程序是 JAVA

任何可以帮助我的 API。建议将不胜感激。

4

2 回答 2

1

Chirs is correct. The documentation of TaskReport states that org.apache.hadoop.mapred.TaskReport inherits those methods from org.apache.hadoop.mapreduce.TaskReport. So, one could get such values.

Here are the codes to get the start and end time of a job, grouped for each Map and Reduce tasks.

import org.apache.hadoop.mapred.JobClient;
import org.apache.hadoop.mapred.JobStatus;
import org.apache.hadoop.conf.Configuration;
import java.net.InetSocketAddress;
import java.util.*;
import org.apache.hadoop.mapred.TaskReport;
import org.apache.hadoop.mapred.RunningJob;
import org.apache.hadoop.util.StringUtils;
import java.text.SimpleDateFormat;

public class mini{
        public static void main(String args[]){
                String jobTrackerHost = "192.168.151.14";
                int jobTrackerPort = 54311;

                try{
                        Configuration conf = new Configuration();
                        JobClient jobClient = new JobClient(new InetSocketAddress(jobTrackerHost, jobTrackerPort), conf);
                        JobStatus[] activeJobs = jobClient.jobsToComplete();
                        SimpleDateFormat dateFormat = new SimpleDateFormat("d-MMM-yyyy HH:mm:ss");
                        for(JobStatus js: activeJobs){
                                System.out.println(js.getJobID());
                                RunningJob runningjob = jobClient.getJob(js.getJobID());
                                            while(runningjob.isComplete() == false){ /*Wait till the job completes.*/}
                                TaskReport[] maptaskreports = jobClient.getMapTaskReports(js.getJobID());
                                for(TaskReport tr: maptaskreports){
                                        System.out.println("Task ID: "+tr.getTaskID()+" Start TIme: "+StringUtils.getFormattedTimeWithDiff(dateFormat, tr.getStartTime(), 0)+" Finish Time: "+StringUtils.getFormattedTimeWithDiff(dateFormat, tr.getFinishTime(), tr.getStartTime()));
                                }
                                TaskReport[] reducetaskreports = jobClient.getReduceTaskReports(js.getJobID());
                                for(TaskReport tr: reducetaskreports){
                                        System.out.println("Task ID: "+tr.getTaskID()+" Start TIme: "+StringUtils.getFormattedTimeWithDiff(dateFormat, tr.getStartTime(), 0)+" Finish Time: "+StringUtils.getFormattedTimeWithDiff(dateFormat, tr.getFinishTime(), tr.getStartTime()));
                                }

                        }
                }catch(Exception ex){
                        ex.printStackTrace();
                }
        }
}

This is a simple example to get the Start and Finish time of a running job. You can in the way you want.

And here is the run of this program for a "Word Count" MapReduce job.

[root@dev1-slave1 ~]# java -classpath /usr/lib/hadoop/hadoop-core.jar:/usr/lib/hadoop/lib/jackson-core-asl-1.8.8.jar:/usr/lib/hadoop/lib/jackson-mapper-asl-1.8.8.jar:/usr/lib/hadoop/lib/commons-logging-1.1.1.jar:/usr/lib/hadoop/lib/commons-configuration-1.6.jar:/usr/lib/hadoop/lib/commons-lang-2.4.jar:. mini
job_201501151144_0042
Task ID: task_201501151144_0042_m_000000 Start TIme: 16-Jan-2015 17:07:35 Finish Time: 16-Jan-2015 17:07:43 (7sec)
Task ID: task_201501151144_0042_m_000001 Start TIme: 16-Jan-2015 17:07:35 Finish Time: 16-Jan-2015 17:07:56 (20sec)
Task ID: task_201501151144_0042_m_000002 Start TIme: 16-Jan-2015 17:07:35 Finish Time: 16-Jan-2015 17:07:43 (7sec)
Task ID: task_201501151144_0042_m_000003 Start TIme: 16-Jan-2015 17:07:43 Finish Time: 16-Jan-2015 17:07:53 (10sec)
Task ID: task_201501151144_0042_m_000004 Start TIme: 16-Jan-2015 17:07:43 Finish Time: 16-Jan-2015 17:07:53 (10sec)
Task ID: task_201501151144_0042_r_000000 Start TIme: 16-Jan-2015 17:07:43 Finish Time: 16-Jan-2015 17:08:00 (17sec)
Task ID: task_201501151144_0042_r_000001 Start TIme: 16-Jan-2015 17:07:43 Finish Time: 16-Jan-2015 17:08:05 (22sec)
Task ID: task_201501151144_0042_r_000002 Start TIme: 16-Jan-2015 17:07:43 Finish Time: 16-Jan-2015 17:08:05 (21sec)

Its good to open the desired jsp files of hadoop in its mapreduce/src/webapps/job/ directory and figure out how JOBTRACKER Web UI is displaying information.

I have derived above codes from jobtasks.jsp.

Hope it helps. :)

于 2015-01-16T11:45:08.343 回答
1

查看JobClient的以下方法:

这两个调用都返回TaskReport对象的数组,您可以从中提取开始/完成时间以及每个任务的单独计数器

于 2013-04-23T23:24:54.727 回答