一、网站基本指标(即针对于网站用户行为而产生的日志中进行统计分析)

1. PV:网页浏览量(Page View页面浏览次数,只要进入该网页就产生一条记录,不限IP,统计点每天(较多)/每周/每月/..)
2. UV:独立访客数(Unique Vistor,以Cookie为依据,同一天内一个用户多次访问,只记为一个)
3. VV:访客的访问次数(Visit View,以Session为依据,访客访问网站到关掉该网站所有页面即记为一次访问)
4. IP:独立IP数(即记录不同IP,同一IP访问多次算作一次)
5. 通常网站流量(traffic)是指网站的访问量,是用来描述访问一个网站的用户数量以及用户所浏览的网页数量等指标
对于虚拟空间商来说流量是指:用户在访问网站过程中,产生的数据量大小

二、UV统计示例(也就是每天每个省份有多少人访问了该网站)

1. 分析需求
1> 我们得到的是怎样的数据,找出共同点,会议map,shuffle,reduce都做了什么事
2> 我们想要怎样的数据,列举出来
2. 实施计划注意的地方
1> 数据以什么分隔,是否我们需要自定义数据类型
2> 大致上我们需要过滤掉无效的记录
使用自定义数据类型将我们需要的字段组合起来
然后根据省份对记录累加(去重阶段)
3> 数据类型可以不定义,使用Text将字段值组合即可
然后转到reduce方法,建立hashMap对于数据根据时间和省份递增存储
在cleanup中组合成想要的输出数据即可

三、UV统计代码示例

WebUvMr.java
============
package com.bigdata_senior.WebUvMr;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set; import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; public class WebUvMr { //Mapper Class
private static class WordCountMapper extends Mapper<LongWritable, Text, Text, NullWritable>{ private Text mapOutKey = new Text();
@Override
public void map(LongWritable key, Text value, Context context)
throws IOException, InterruptedException { String lineValue = value.toString();
String [] strValue = lineValue.split("\t");
if(30 > strValue.length){
return;
}
String guidIdValue = strValue[5];
if(StringUtils.isBlank(guidIdValue)){
return;
}
String trackTimeValue = strValue[17];
if(StringUtils.isBlank(trackTimeValue)){
return;
}
String dateValue = trackTimeValue.substring(0,10);
Integer proviceIdValue = Integer.MAX_VALUE;
try{
if(StringUtils.isBlank(strValue[23])){
return;
}
proviceIdValue = Integer.valueOf(strValue[23]);
}catch(Exception e){
return;
} mapOutKey.set(dateValue+"\t"+proviceIdValue+"_"+guidIdValue);
//System.out.println("key--> "+mapOutKey+" value--> "+NullWritable.get());
context.write(mapOutKey, NullWritable.get());
}
} //Reduce Class
private static class WordCountReduce extends Reducer<Text, NullWritable, Text, LongWritable>{ private Map<String,Integer> dateMap;
private Text outputKey = new Text();
private LongWritable outputvalue = new LongWritable(); @Override
protected void setup(Context context) throws IOException,
InterruptedException {
dateMap = new HashMap<String,Integer>();
} @Override
public void reduce(Text key, Iterable<NullWritable> values,Context context)
throws IOException, InterruptedException { String date = key.toString().split("_")[0];
if(dateMap.containsKey(date)){ Integer preUv = dateMap.get(date);
//System.out.println("====-> "+preUv);
Integer uv = preUv + 1;
dateMap.put(date, uv);
}else{
dateMap.put(date, 1);
}
//System.out.println(dateMap.toString());
} @Override
protected void cleanup(Context context) throws IOException,
InterruptedException { Set<String> dateSet = dateMap.keySet();
//System.out.println(dateSet.toString());
for(String date : dateSet){
Integer uv = dateMap.get(date);
outputKey.set(date);
outputvalue.set(uv);
System.out.println("result:-->key "+outputKey+" value-->"+outputvalue);
context.write(outputKey, outputvalue);
}
}
} //Driver
public int run(String[] args) throws Exception { Configuration configuration = new Configuration();
Job job = Job.getInstance(configuration, this.getClass().getSimpleName());
job.setJarByClass(this.getClass()); //input
Path inPath = new Path(args[0]);
FileInputFormat.addInputPath(job,inPath); //output
Path outPath = new Path(args[1]);
FileOutputFormat.setOutputPath(job, outPath); //mapper
job.setMapperClass(WordCountMapper.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(NullWritable.class); //Reduce
job.setReducerClass(WordCountReduce.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(LongWritable.class); //submit job
boolean isSuccess = job.waitForCompletion(true); return isSuccess ? 0 : 1;
} public static void main(String[] args) throws Exception { args = new String[]{
"hdfs://hadoop09-linux-01.ibeifeng.com:8020/user/liuwl/tmp/webuv/input",
"hdfs://hadoop09-linux-01.ibeifeng.com:8020/user/liuwl/tmp/webuv/output4"
};
//run job
int status = new WebUvMr().run(args);
System.exit(status);
}
}

Hadoop.2.x_WebUV示例的更多相关文章

  1. 【爬坑】运行 Hadoop 的 MapReduce 示例卡住了

    1. 问题说明 在以伪分布式模式运行 Hadoop 自带的 MapReduce 示例,卡在了 Running job ,如图所示 2. 解决过程 查看日志没得到有用的信息 再次确认配置信息没有错误信息 ...

  2. Hadoop Map/Reduce 示例程序WordCount

    #进入hadoop安装目录 cd /usr/local/hadoop #创建示例文件:input #在里面输入以下内容: #Hello world, Bye world! vim input #在hd ...

  3. hadoop: hdfs API示例

    利用hdfs的api,可以实现向hdfs的文件.目录读写,利用这一套API可以设计一个简易的山寨版云盘,见下图: 为了方便操作,将常用的文件读写操作封装了一个工具类: import org.apach ...

  4. Hadoop - WordCount代码示例

    文章来源:http://www.itnose.net/detail/6197823.html import java.io.IOException; import java.util.Iterator ...

  5. Hadoop应用程序示例2

  6. Hadoop应用程序示例

  7. Hadoop: MapReduce2的几个基本示例

    1) WordCount 这个就不多说了,满大街都是,网上有几篇对WordCount的详细分析 http://www.sxt.cn/u/235/blog/5809 http://www.cnblogs ...

  8. Hadoop示例程序WordCount编译运行

    首先确保Hadoop已正确安装及运行. 将WordCount.java拷贝出来 $ cp ./src/examples/org/apache/hadoop/examples/WordCount.jav ...

  9. 实训任务02:Hadoop基础操作

    实训任务02:Hadoop基础操作 班级            学号               姓名 实训1:创建测试文件上传HDFS,并显示内容 需求说明: 在本地计算机上创建测试文件helloH ...

随机推荐

  1. 注解:【无连接表的】Hibernate单向N->1关联

    Person与Address关联:单向N->1,[无连接表的] Person.java package org.crazyit.app.domain; import javax.persiste ...

  2. Intent传递类实例

    发送方: Intent intent = new Intent(); intent.setClass(mContext, HomeDetailReportActivity.class); intent ...

  3. 函数式编程语言LISP,python,haskell,clojure

    说说我自己的背景吧,我是个半吊子的程序员,做任何事情喜欢比较了解然后再尝试,我接触过很多语言,大多数都把它当成工具来使用 我现在的工作大部分主要在于数据挖掘与机器学习方面,也学习web开发,我第一个拿 ...

  4. pythonchallenge之C++学习篇-02

    第二关任然是一个字符处理的关卡 查看网页源码发现有一大串字符需要处理,这么多的字符如果放在源代码里就很不好了 所以要用到C++对文件的操作,用到的头文件是fstream 这里参照了这个博文 对文件处理 ...

  5. windbg的高级玩法

    详见附件  jpg改zip

  6. CSS3 2D 转换

    2D 转换 在本章中,您将学到如下 2D 转换方法: translate() rotate() scale() skew() matrix() 您将在下一章学习 3D 转换. 实例 div { tra ...

  7. JavaScript 之 document对象

    对象属性document.title //设置文档标题等价于HTML的title标签document.bgColor //设置页面背景色document.fgColor //设置前景色(文本颜色)do ...

  8. Codeforces Round #354 (Div. 2)-D

    D. Theseus and labyrinth 题目链接:http://codeforces.com/contest/676/problem/D Theseus has just arrived t ...

  9. css3写箭头

    左箭头 .left-arrow { position: absolute; left: 6%; top: 31%; overflow: hidden; zoom:; width: 0.4rem; he ...

  10. jquerymobile 基础教程

    http://www.w3cplus.com/blog/tags/331.html?page=1