案例:

  使用电商网站的用户行为日志进行统计分析

一:准备

1.指标

  PV:网页流浪量

  UV:独立访客数

  VV:访客的访问数,session次数

  IP:独立的IP数

2.上传测试数据

  

3.查看第一条记录

  

  注意点(字符显示):

            

二:程序

1.分析

  省份ID-》key

  value-》1

  -》 <proviced,list(1,1,1)>

2.数据类型

  key:Text

  value:IntWritable

3.map 端的业务

  

4.reduce端的业务

  

5.整合运行

  

6.结果

  

三:计数器

1.程序

  

2.结果

  

  

  结果完全吻合。

四:完整程序

1.PV程序

 package com.senior.network;

 import java.io.IOException;

 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; public class WebPvCount extends Configured implements Tool{
//Mapper
public static class WebPvCountMapper extends Mapper<LongWritable,Text,IntWritable,IntWritable>{
private IntWritable mapoutputkey=new IntWritable();
private static final IntWritable mapoutputvalue=new IntWritable(1);
@Override
protected void cleanup(Context context) throws IOException,InterruptedException { }
@Override
protected void setup(Context context) throws IOException,InterruptedException { } @Override
protected void map(LongWritable key, Text value, Context context)throws IOException, InterruptedException {
String lineValue=value.toString();
String[] strs=lineValue.split("\t");
if(30>strs.length){
return;
}
String priviceIdValue=strs[23];
String urlValue=strs[1];
if(StringUtils.isBlank(priviceIdValue)){
return;
}
if(StringUtils.isBlank(urlValue)){
return;
}
Integer priviceId=Integer.MAX_VALUE;
try{
priviceId=Integer.valueOf(priviceIdValue);
}catch(Exception e){
e.printStackTrace();
}
mapoutputkey.set(priviceId);
context.write(mapoutputkey, mapoutputvalue);
} } //Reducer
public static class WebPvCountReducer extends Reducer<IntWritable,IntWritable,IntWritable,IntWritable>{
private IntWritable outputvalue=new IntWritable();
@Override
protected void reduce(IntWritable key, Iterable<IntWritable> values,Context context)throws IOException, InterruptedException {
int sum=0;
for(IntWritable value : values){
sum+=value.get();
}
outputvalue.set(sum);
context.write(key, outputvalue);
} } //Driver
public int run(String[] args)throws Exception{
Configuration conf=this.getConf();
Job job=Job.getInstance(conf,this.getClass().getSimpleName());
job.setJarByClass(WebPvCount.class);
//input
Path inpath=new Path(args[0]);
FileInputFormat.addInputPath(job, inpath); //output
Path outpath=new Path(args[1]);
FileOutputFormat.setOutputPath(job, outpath); //map
job.setMapperClass(WebPvCountMapper.class);
job.setMapOutputKeyClass(IntWritable.class);
job.setMapOutputValueClass(IntWritable.class); //shuffle //reduce
job.setReducerClass(WebPvCountReducer.class);
job.setOutputKeyClass(IntWritable.class);
job.setOutputValueClass(IntWritable.class); //submit
boolean isSucess=job.waitForCompletion(true);
return isSucess?0:1;
} //main
public static void main(String[] args)throws Exception{
Configuration conf=new Configuration();
//compress
conf.set("mapreduce.map.output.compress", "true");
conf.set("mapreduce.map.output.compress.codec", "org.apache.hadoop.io.compress.SnappyCodec");
args=new String[]{
"hdfs://linux-hadoop01.ibeifeng.com:8020/user/beifeng/mapreduce/wordcount/inputWebData",
"hdfs://linux-hadoop01.ibeifeng.com:8020/user/beifeng/mapreduce/wordcount/outputWebData1"
};
int status=ToolRunner.run(new WebPvCount(), args);
System.exit(status);
} }

2.计数器

  这个计数器集中在mapper端。

 package com.senior.network;

 import java.io.IOException;

 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; public class WebPvCount extends Configured implements Tool{
//Mapper
public static class WebPvCountMapper extends Mapper<LongWritable,Text,IntWritable,IntWritable>{
private IntWritable mapoutputkey=new IntWritable();
private static final IntWritable mapoutputvalue=new IntWritable(1);
@Override
protected void cleanup(Context context) throws IOException,InterruptedException { }
@Override
protected void setup(Context context) throws IOException,InterruptedException { } @Override
protected void map(LongWritable key, Text value, Context context)throws IOException, InterruptedException {
String lineValue=value.toString();
String[] strs=lineValue.split("\t");
if(30>strs.length){
context.getCounter("webPvMapper_counter", "length_LT_30").increment(1L);
return;
}
String priviceIdValue=strs[23];
String urlValue=strs[1];
if(StringUtils.isBlank(priviceIdValue)){
context.getCounter("webPvMapper_counter", "priviceIdValue_null").increment(1L);
return; }
if(StringUtils.isBlank(urlValue)){
context.getCounter("webPvMapper_counter", "url_null").increment(1L);
return;
}
Integer priviceId=Integer.MAX_VALUE;
try{
priviceId=Integer.valueOf(priviceIdValue);
}catch(Exception e){
context.getCounter("webPvMapper_counter", "switch_fail").increment(1L);
e.printStackTrace();
}
mapoutputkey.set(priviceId);
context.write(mapoutputkey, mapoutputvalue);
} } //Reducer
public static class WebPvCountReducer extends Reducer<IntWritable,IntWritable,IntWritable,IntWritable>{
private IntWritable outputvalue=new IntWritable();
@Override
protected void reduce(IntWritable key, Iterable<IntWritable> values,Context context)throws IOException, InterruptedException {
int sum=0;
for(IntWritable value : values){
sum+=value.get();
}
outputvalue.set(sum);
context.write(key, outputvalue);
} } //Driver
public int run(String[] args)throws Exception{
Configuration conf=this.getConf();
Job job=Job.getInstance(conf,this.getClass().getSimpleName());
job.setJarByClass(WebPvCount.class);
//input
Path inpath=new Path(args[0]);
FileInputFormat.addInputPath(job, inpath); //output
Path outpath=new Path(args[1]);
FileOutputFormat.setOutputPath(job, outpath); //map
job.setMapperClass(WebPvCountMapper.class);
job.setMapOutputKeyClass(IntWritable.class);
job.setMapOutputValueClass(IntWritable.class); //shuffle //reduce
job.setReducerClass(WebPvCountReducer.class);
job.setOutputKeyClass(IntWritable.class);
job.setOutputValueClass(IntWritable.class); //submit
boolean isSucess=job.waitForCompletion(true);
return isSucess?0:1;
} //main
public static void main(String[] args)throws Exception{
Configuration conf=new Configuration();
//compress
conf.set("mapreduce.map.output.compress", "true");
conf.set("mapreduce.map.output.compress.codec", "org.apache.hadoop.io.compress.SnappyCodec");
args=new String[]{
"hdfs://linux-hadoop01.ibeifeng.com:8020/user/beifeng/mapreduce/wordcount/inputWebData",
"hdfs://linux-hadoop01.ibeifeng.com:8020/user/beifeng/mapreduce/wordcount/outputWebData2"
};
int status=ToolRunner.run(new WebPvCount(), args);
System.exit(status);
} }

026 使用大数据对网站基本指标PV案例的分析的更多相关文章

  1. 数据科学中的R和Python: 30个免费数据资源网站

    1 政府数据 Data.gov:这是美国政府收集的数据资源.声称有多达40万个数据集,包括了原始数据和地理空间格式数据.使用这些数据集需要注意的是:你要进行必要的清理工作,因为许多数据是字符型的或是有 ...

  2. 网站流量分析指标-PV/UV/PR/ip分析及区别

    1.什么是pv? PV(page view),即页面浏览量,或点击量;通常是衡量一个网络新闻频道或网站甚至一条网络新闻的主要指标. 高手对pv的解释是,一个访问者在24小时(0点到24点)内到底看了你 ...

  3. 网站性能测试指标(QPS,TPS,吞吐量,响应时间)详解

    转载:http://www.51testing.com/html/16/n-3723016.html   常用的网站性能测试指标有:吞吐量.并发数.响应时间.性能计数器等. 并发数 并发数是指系统同时 ...

  4. 70路小报:用PV和UV作为网站衡量指标已经过时

    方法]投资人呼吁:PV和UV不应该再作为产品衡量指标 风险投资机构Andreessen Horowitz近日一直反对再用传统的网站衡量指标去评价互联网产品,比如PV和UV,甚至包括应用的下载量. 他们 ...

  5. UC打通高德POI数据,用大数据描绘周边热点地图

    UC打通高德POI数据,用大数据描绘周边热点地图   2016-10-25 11:13  来源:互联网  我来投稿  我要评论   在北京工作的小李最近很苦恼,房东因小区周边规划了大型商场而坚持涨价. ...

  6. Delphi使用大图标编译程序

    在Windows Vista. Windows7以上Windows系统中可以支持大图标显示了,但是Delphi编译出来的程序却只能显示32x32的图标,这使Delphi编译的程序看起来很不专业.下面就 ...

  7. Saiku多用户使用时数据同步刷新(十七)

    Saiku多用户使用时数据同步刷新 这里我们需要了解一下关于saiku的刷新主要有两种数据需要刷新: >1 刷新数据库的表中的数据,得到最新的表数据进行展示. >2 刷新cube信息,得到 ...

  8. 超级好用的解析JSON数据的网站

    超级好用的解析JSON数据的网站 网址 http://json.parser.online.fr/beta/ 效果图 测试数据 {,},,,,,,},{,,,,},{,,,,},{,,,,,,,,,, ...

  9. GIS专业书籍、文档、数据、网站、工具等干货

    整理.分享一些个人整理的GIS专业书籍.文档.数据.网站.工具等.也希望大家将自己的心得也分享出来,一起交流,共同进步. 如果下载链接失效,请到这里去:地信网 一.原理应用类 GIS基础类 01.地理 ...

随机推荐

  1. 20155334 2016-2017-2 《Java程序设计》第九周学习总结

    20155334 2016-2017-2 <Java程序设计>第九周学习总结 教材学习内容总结 第十六章:整合数据库 16.1 JDBC入门 JDBC(Java DataBase Conn ...

  2. HDU 1569 - 方格取数(2) - [最大点权独立集与最小点权覆盖集]

    嗯,这是关于最大点权独立集与最小点权覆盖集的姿势,很简单对吧,然后开始看题. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1569 Time Limi ...

  3. [CQOI2018]交错序列 (矩阵快速幂,数论)

    [CQOI2018]交错序列 \(solution:\) 这一题出得真的很好,将原本一道矩阵快速幂硬生生加入组合数的标签,还那么没有违和感,那么让人看不出来.所以做这道题必须先知道(矩阵快速幂及如何构 ...

  4. 记录一个PHP安装redis扩展时的问题

    安装过程:https://www.cnblogs.com/pengyunjing/p/8688320.html 由于我之前安装过该扩展,重新安装时没有执行make clean命令,所以安装好出现了下面 ...

  5. Android APP常见的5类内存泄露及解决方法

    1.static变量引起的内存泄漏 因为static变量的生命周期是在类加载时开始 类卸载时结束,也就是说static变量是在程序进程死亡时才释放,如果在static变量中 引用了Activity 那 ...

  6. python函数——形参中的:*args和**kwargs

    python函数——形参中的:*args和**kwargs   多个实参,放到一个元组里面,以*开头,可以传多个参数:**是形参中按照关键字传值把多余的传值以字典的方式呈现 *args:(表示的就是将 ...

  7. Python学习之not,and,or篇

    Python学习之not,and,or篇 运算符示意 not –表示取反运算. and –表示取与运算. or –表示取或运算. 运算符优先级 not > and > or. 举例如下: ...

  8. STM32F103X datasheet学习笔记---DMA

    1.前言 直接存储器存取(DMA)用来提供在外设和存储器之间或者存储器和存储器之间的高速数据传输. 无须CPU干预,数据可以通过DMA快速地移动,这就节省了CPU的资源来做其他操作. 两个DMA控制器 ...

  9. 使用光盘搭建本地yum源

    刚装好的系统,想安装一些常用软件和一些包组的时候,就可以使用安装光盘搭建本地yum 第一步:挂载安装光盘 mount /dev/cdrom /mnt 第二步:编辑repo yum源文件 [root@l ...

  10. 通达OA2008优化前端web为lnmp环境及后续优化

    1.安装lnmp环境 具体参考:CentOS6.5编译安装Nginx1.8.1+MySQL5.5.48+PHP5.2.17+xcache3.2+ZendOptimizer-3.3.9 http://b ...