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

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. 学生成绩管理系统[C]

    #include<stdio.h> #include<stdlib.h> #include<string.h> #include<conio.h> #d ...

  2. Ubuntu 安装OpenCV3.0.0

    Ubuntu安装OpenCV3.0.0 为了看看opencv3.0的HDR效果,尝试安装opencv3.0到ubuntu12.04上面,安装了好几次终于成功了. 参考博客: http://www.sa ...

  3. java + jni + mingw实例开发(基于命令行窗口模式)

    java+ jni + mingw 参考网址: http://wenku.baidu.com/link?url=9aQ88d2ieO7IgKLlNhJi5d3mb3xwzbezLPzSIX3ixz4_ ...

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

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

  5. pythonchallenge之C++学习篇-00

    前言 最近学习下C++,之前是python的用户,python解释器有诸多实现,其中最出名的要数C实现了,而且很多python的扩展模块可能要用C或者C++来写的,所以很有必要学习下C++了 为了避免 ...

  6. Linux查看系统配置常用命令

    Linux查看系统配置常用命令: 系统 # uname -a # 查看内核/操作系统/CPU信息# head -n 1 /etc/issue # 查看操作系统版本# cat /proc/cpuinfo ...

  7. WPF三种基本触发器与【与或】逻辑触发器

    wpf中的触发器是应用于程序界面模板.样式.皮肤.主题的基础.以下作为学习的记录. 1,三种基本触发器,属性触发器.数据触发器.事件触发器 属性触发器 <!--属性触发器--> <T ...

  8. hdu5057 Argestes and Sequence 分块

    Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Submiss ...

  9. set UVA 11136 Hoax or what

    题目传送门 题意:训练指南P245 分析:set维护,查询删除最大最小值 #include <bits/stdc++.h> using namespace std; typedef lon ...

  10. Django的cookie和session

    http://www.cnblogs.com/lhj588/archive/2011/10/27/2226976.html