mapreduce pv

分析网站基本指标PV

网站基本指标

1.     (Page View),网站浏览量,指页面的浏览量或点击次数,用户每次刷新即被计算一次。如果用户刷新了页面100次,那么,流量统计工具就会显示100个“PV”量。这就是“PV”在流量统计中具体的一个定义了;

2.     (Unique Vistor),独立访客数,指1天内访问某站点的人数,以cookie或者用户唯一ID为依据。1天内同一访客的多次访问只计为1个访客;
3.(Visit View),访客的访问次数,用以记录所有访客1天内访问了多少次您的网站。当访客完成所有浏览并最终关掉该网站的所有页面时便完成了一次访问,同一访客1天内可能有多次访问行为,次数累加。

3.     IP(独立IP),指1天内使用不同IP地址的用户访问网站的数量,同一IP无论访问了几个页面,独立IP数均为1。

PV分析和编写程序

pv指标指的是网站的浏览量,通过查看日志的条数就可以知道某一时间端内的pv指标。下面我们统计各个省份的某一时间段内的pV指标。

1.     通过查看字段说明文档,可以查看到省份字段

2.     把省份的ID作为MAP任务输出结果的KEY,VALUE为计数1

3.     目录的创建

bin/hdfsdfs -mkdir -p /user/liangman/mapreduce/webpv/input

4.     文件上传

bin/hdfsdfs -put /home/liangman/2015082818 /user/liangman/mapreduce/webpv/input


1.     程序代码


import java.io.IOException;

import java.util.StringTokenizer;

 

import org.apache.commons.lang.StringUtils;

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.conf.Configured;

import org.apache.hadoop.fs.Path;

import org.apache.hadoop.io.IntWritable;

import org.apache.hadoop.io.LongWritable;

import org.apache.hadoop.io.Text;

import org.apache.hadoop.mapreduce.Job;

import org.apache.hadoop.mapreduce.Mapper;

import org.apache.hadoop.mapreduce.Mapper.Context;

import org.apache.hadoop.mapreduce.Reducer;

import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;

import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import org.apache.hadoop.util.Tool;

import org.apache.hadoop.util.ToolRunner;

 

import com.ibeifeng.bigdata.hadoop.hdfs.LiangmanWordCount.WordCountCombiner;

 

/**

 *

 *@author liangman

 *

 */

public class WebPVMapReduce extends Configuredimplements Tool {

   // 1.map

   public static class PVMap extends

            Mapper<LongWritable, Text, IntWritable,IntWritable> {

       private final static IntWritable mapOutputValue = new IntWritable(1);

       //private IntWritable outputKey = new IntWritable();

       private IntWritable mapOutputKey = new IntWritable();

   

       @Override

       public void map(LongWritable key, Text value, Context context)

                throws IOException, InterruptedException{

           

            String linevalue = value.toString();

//          StringTokenizer tokenizer = new StringTokenizer(linevalue,"\t");

//          int counttoken = tokenizer.countTokens();

//          String[] tokenarray = new String[counttoken];

//          int i = 0;

//          while(tokenizer.hasMoreTokens()){

//              tokenarray[i++] = tokenizer.nextToken();

//          }

            String[] tokenarray = linevalue.split("\t");

            //if length less than 30 return

            if(tokenarray.length < 30){

               

                //counter

                context.getCounter("WEB_PV_MAP_COUNTERS","LENGTH_LT_30_COUNTER").increment(1L);;

                return;

            }

            //if url is null return

            if(StringUtils.isBlank(tokenarray[1])){

                context.getCounter("WEB_PV_MAP_COUNTERS","NULL_OF_URI").increment(1l);

                return ;

            }

            //provinceid

            String provinceID = tokenarray[23];

            //if blank return

            if(StringUtils.isBlank(provinceID)){

                context.getCounter("WEB_PV_MAP_COUNTERS","NULL_OF_PROVICEID").increment(1l);

                return ;

            }

            Integer pID = Integer.MAX_VALUE;

           

            //parse error return

            try{

                pID = Integer.parseInt(provinceID);

               

            }catch(Exception e){

                context.getCounter("WEB_PV_MAP_COUNTERS","PARESEINT_ERROR").increment(1l);

                return;

            }

            //map output

            // map output key

            mapOutputKey.set(pID);

            //

            context.write(mapOutputKey, mapOutputValue);

 

       }

       @Override

       protected void cleanup(Context context) throws IOException,

                InterruptedException {

            // TODO Auto-generated method stub

            super.cleanup(context);

       }

 

       @Override

       protected void setup(Context context) throws IOException,

                InterruptedException {

            // TODO Auto-generated method stub

            super.setup(context);

       }

 

   }

 

   // TODO

   public static class PVCombiner extends

            Reducer<IntWritable, IntWritable,IntWritable, IntWritable> {

 

       IntWritable outputvalue = new IntWritable();

       @Override

       public void reduce(IntWritable key, Iterable<IntWritable> values,

                Context context) throws IOException,InterruptedException {

            int sum = 0;

            for (IntWritable intWritable : values){

                sum = sum + intWritable.get();

            }

            outputvalue.set(sum);

           context.write(key, outputvalue);

       }

 

       @Override

       protected void cleanup(

                org.apache.hadoop.mapreduce.Reducer.Contextcontext)

                throws IOException, InterruptedException{

            // TODO Auto-generated method stub

            super.cleanup(context);

       }

 

       @Override

       protected void setup(org.apache.hadoop.mapreduce.Reducer.Context context)

                throws IOException, InterruptedException{

            // TODO Auto-generated method stub

            super.setup(context);

       }

 

   }

 

   // 2.reducer

   public static class PVReducer extends

            Reducer<IntWritable, IntWritable,IntWritable, IntWritable> {

       IntWritable outputvalue = new IntWritable();

        @Override

       public void reduce(IntWritable key, Iterable<IntWritable> values,

                Context context) throws IOException,InterruptedException {

            int sum = 0;

            for (IntWritable intWritable : values){

                sum = sum + intWritable.get();

            }

            outputvalue.set(sum);

            context.write(key, outputvalue);

       }

       @Override

       protected void cleanup(

                org.apache.hadoop.mapreduce.Reducer.Contextcontext)

                throws IOException, InterruptedException{

            // TODO Auto-generated method stub

            super.cleanup(context);

       }

 

       @Override

       protected void setup(org.apache.hadoop.mapreduce.Reducer.Context context)

                throws IOException, InterruptedException{

            // TODO Auto-generated method stub

            super.setup(context);

       }

 

   

 

   }

 

   // 3.driver

   public int run(String[] args) throws Exception {

       //

       Configuration configuration = this.getConf();

       // one application is a job

       Job job = Job.getInstance(configuration, this.getClass()

                .getSimpleName());

       // run a jar

       job.setJarByClass(WebPVMapReduce.class);

       // the input address

       Path inpath = new Path(args[0]);

       // add an input to the job

       FileInputFormat.addInputPath(job, inpath);

 

       // the output address

       Path outpath = new Path(args[1]);

       FileOutputFormat.setOutputPath(job, outpath);

 

       // mapper

       // TODO

       job.setMapperClass(PVMap.class);

       job.setMapOutputKeyClass(IntWritable.class);

       job.setMapOutputValueClass(IntWritable.class);

 

       // ###################################shuffle

 

       // 1.fen qu

       // job.setPartitionerClass(cls);

       // 2.sort

       // job.setSortComparatorClass(cls);

       // 3.fen zu group

       // job.setGroupingComparatorClass(cls);

 

       job.setCombinerClass(PVCombiner.class);

 

       // reducer

       // TODO

       job.setReducerClass(PVReducer.class);

       job.setOutputKeyClass(IntWritable.class);

       job.setOutputValueClass(IntWritable.class);

       // TODO

       // job.setNumReduceTasks(tasks);

       // submit the job

       boolean isSucess = job.waitForCompletion(true);

 

       return isSucess ? 0 : 1;

 

   }

 

   public static void main(String[] args) throws Exception {

       Configuration configuration = new Configuration();

       // set the compress

       //TODO

//     configuration.set("mapreduce.map.output.compress", "true");

//     configuration.set("mapreduce.map.output.compress.codec",

//              "org.apache.hadoop.io.compress.SnappyCodec");

 

        args=new String[]{

        "hdfs://hadoop02-linux.alibaba.com:8020/user/liangman/mapreduce/webpv/input",

        "hdfs://hadoop02-linux.alibaba.com:8020/user/liangman/mapreduce/webpv/output"

        };

       // run the job

       int status = ToolRunner.run(configuration, new WebPVMapReduce(), args);

       // exit

       System.exit(status);

   }

 

}

 

1.     运行结果

自定义程序计数器

●      自定义程序计数器(组名,计数器名)

context.getCounter("WEB_PV_MAP_COUNTERS","LENGTH_LT_30_COUNTER").increment(1L);;

●      自定义程序计数器输出结果


可以看到数据字段不全,不能很好的进行分析,要和相关部门进行沟通,刷洗数据。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
上层应用业务对实时数据的需求,主要包含两部分内容:1、 整体数据的实时分析。2、 AB实验效果的实时监控。这几部分数据需求,都需要进行的下钻分析支持,我们希望能够建立统一的实时OLAP数据仓库,并提供一套安全、可靠的、灵活的实时数据服务。目前每日新增的曝光日志达到几亿条记录,再细拆到AB实验更细维度时,数据量则多达上百亿记录,多维数据组合下的聚合查询要求秒级响应时间,这样的数据量也给团队带来了不小的挑战。OLAP层的技术选型,需要满足以下几点:1:数据延迟在分钟级,查询响应时间在秒级2:标准SQL交互引擎,降低使用成本3:支持join操作,方便维度增加属性信息4:流量数据可以近似去重,但订单行要精准去重5:高吞吐,每分钟数据量在千W级记录,每天数百亿条新增记录6:前端业务较多,查询并发度不能太低通过对比开源的几款实时OLAP引擎,可以发现Doris和ClickHouse能够满足上面的需求,但是ClickHouse的并发度太低是个潜在的风险,而且ClickHouse的数据导入没有事务支持,无法实现exactly once语义,对标准SQL的支持也是有限的。所以针对以上需求Doris完全能解决我们的问题,DorisDB是一个性能非常高的分布式、面向交互式查询的分布式数据库,非常的强大,随着互联网发展,数据量会越来越大,实时查询需求也会要求越来越高,DorisDB人才需求也会越来越大,越早掌握DorisDB,以后就会有更大的机遇。本课程基于真实热门的互联网电商业务场景为案例讲解,具体分析指标包含:AB版本分析,下砖分析,营销分析,订单分析,终端分析等,能承载海量数据的实时分析,数据分析涵盖全端(PC、移动、小程序)应用。整个课程,会带大家实践一个完整系统,大家可以根据自己的公司业务修改,既可以用到项目中去,价是非常高的。本课程包含的技术:开发工具为:IDEA、WebStormFlink1.9.0DorisDBHadoop2.7.5Hbase2.2.6Kafka2.1.0Hive2.2.0HDFS、MapReduceFlume、ZookeeperBinlog、Canal、MySQLSpringBoot2.0.8.RELEASESpringCloud Finchley.SR2Vue.js、Nodejs、Highcharts、ElementUILinux Shell编程等课程亮点:1.与企业接轨、真实工业界产品2.DorisDB高性能分布式数据库3.大数据热门技术Flink4.支持ABtest版本实时监控分析5.支持下砖分析6.数据分析涵盖全端(PC、移动、小程序)应用7.主流微服务后端系统8.天级别与小时级别多时间方位分析9.数据库实时同步解决方案10.涵盖主流前端技术VUE+jQuery+Ajax+NodeJS+ElementUI11.集成SpringCloud实现统一整合方案12.互联网大数据企业热门技术栈13.支持海量数据的实时分析14.支持全端实时数据分析15.全程代码实操,提供全部代码和资料16.提供答疑和提供企业技术方案咨询企业一线架构师讲授,代码在老师的指导下企业可以复用,提供企业解决方案。  版权归作者所有,盗版将进行法律维权。 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值