這篇文章將為大家詳細(xì)講解有關(guān)hadoop如何實(shí)現(xiàn)計(jì)數(shù)器,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
創(chuàng)新互聯(lián)于2013年創(chuàng)立,先為商洛等服務(wù)建站,商洛等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為商洛企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
1)枚舉聲明計(jì)數(shù)器
Context context...//自定義枚舉變量Enum Counter counter = context.getCounter(Enum enum)
2)自定義計(jì)數(shù)器
Context context...//自己命名groupName和counterName Counter counter = context.getCounter(String groupName,String counterName)
1)初始化計(jì)數(shù)器
counter.setValue(long value);//設(shè)置初始值
2)計(jì)數(shù)器自增
counter.increment(long incr);//增加計(jì)數(shù)
1) 獲取枚舉計(jì)數(shù)器的值
Job job... job.waitForCompletion(true); Counters counters=job.getCounters(); Counter counter=counters.findCounter("BAD_RECORDS");//查找枚舉計(jì)數(shù)器,假如Enum的變量為BAD_RECORDS long value=counter.getValue();//獲取計(jì)數(shù)值
2) 獲取自定義計(jì)數(shù)器的值
Job job...job.waitForCompletion(true); Counters counters=job.getCounters(); Counter counter=counters.findCounter("ErrorCounter","toolong");//假如groupName為ErrorCounter,counterName為toolong long value=counter.getValue();//獲取計(jì)數(shù)值
3) 獲取內(nèi)置計(jì)數(shù)器的值
textpop-up
Job job...job.waitForCompletion(true); Counters counters=job.getCounters();//查找作業(yè)運(yùn)行啟動(dòng)的reduce個(gè)數(shù)的計(jì)數(shù)器,groupName和counterName可以從內(nèi)置計(jì)數(shù)器表格查詢(前面已經(jīng)列舉有) Counter counter=counters.findCounter("org.apache.hadoop.mapreduce.JobCounter","TOTAL_LAUNCHED_REDUCES");//假如groupName為org.apache.hadoop.mapreduce.JobCounter,counterName為TOTAL_LAUNCHED_REDUCES long value=counter.getValue();//獲取計(jì)數(shù)值
4) 獲取所有計(jì)數(shù)器的值
Counters counters = job.getCounters(); for (CounterGroup group : counters) { for (Counter counter : group) { System.out.println(counter.getDisplayName() + ": " + counter.getName() + ": "+ counter.getValue()); } }
關(guān)于“hadoop如何實(shí)現(xiàn)計(jì)數(shù)器”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯(cuò),請把它分享出去讓更多的人看到。