分析

数据源格式

121508281810000000 http://www.yhd.com/?union_ref=7&cp=0 3 PR4E9HWE38DMN4Z6HUG667SCJNZXMHSPJRER VFA5QRQ1N4UJNS9P6MH6HPA76SXZ737P 10977119545 124.65.159.122 unionKey:10977119545 2015-08-28 18:10:00 50116447 http://image.yihaodianimg.com/virtual-web_static/virtual_yhd_iframe_index_widthscreen.html?randid=2015828 6 1000 Mozilla/5.0 (Windows NT 6.1; rv:40.0) Gecko/20100101 Firefox/40.0 Win32 lunbo_tab_3 北京市 2 北京市 1 1 1 1 1440*900 1440756285639

yAnAvm.png Paste_Image.png

需求分析

现在每天中的每一个小时,都有一个日志文件,想要统计每天内每个时段的PV和UV(根据guid然后去重计数)。最后的结果形式:

日期

时间

PV

UV

数据清洗

从日志文件中获取需要的字段id,url,guid,trackTime

时间字段trackTime的格式转换

数据分析后导出到MySQL

实现流程

在Hive中建源表并导入日志数据

create database count_log;

use count_log;

create table source_log(

id string,

url string,

referer string,

keyword string,

type string,

guid string,

pageId string,

moduleId string,

linkId string,

attachedInfo string,

sessionId string,

trackerU string,

trackerType string,

ip string,

trackerSrc string,

cookie string,

orderCode string,

trackTime string,

endUserId string,

firstLink string,

sessionViewNo string,

productId string,

curMerchantId string,

provinceId string,

cityId string,

fee string,

edmActivity string,

edmEmail string,

edmJobId string,

ieVersion string,

platform string,

internalKeyword string,

resultSum string,

currentPage string,

linkPosition string,

buttonPosition string

)

row format delimited fields terminated by '\t'

stored as textfile;

load data local inpath '/opt/datas/2015082818' into table source_log;

load data local inpath '/opt/datas/2015082819' into table source_log;

ANVNnm.png hive16.png

建一个清洗表用来存储转换后的时间字段

hive (count_log)> create table date_clear(

> id string,

> url string,

> guid string,

> date string,

> hour string

> )

> row format delimited fields terminated by '\t';

insert into table date_clear

hive (count_log)> insert into table date_clear

> select id,url,guid ,substring(trackTime,9,2) date,substring(trackTime,12,2) hour from source_log;

7r63Qf.png hive22.png

创建分区表(以日期和时间分区,方便实现每小时进行PV、UV统计)

方式一: 创建静态分区表

hive (count_log)> create table part1(

> id string,

> url string,

> guid string

> )

> partitioned by (date string,hour string)

> row format delimited fields terminated by '\t';

hive (count_log)> insert into table part1 partition (data='20150828',hour='18')

> select id,url,guid from date_clear where date;

hive (count_log)> insert into table part1 partition (date='20150828',hour='18')

> select id,url,guid from date_clear where date='28' and hour='18';

e6JJZz.png hive20.png

方式二:创建动态分区表(会自动的根据与分区列字段名相同的列进行分区)

使用动态分区表前,需要设置两个参数值

hive (count_log)> set hive.exec.dynamic.partition=true;

hive (count_log)> set hive.exec.dynamic.partition.mode=nonstrict;

hive (count_log)> create table part2(

> id string,

> url string,

> guid string

> )

> partitioned by (date string,hour string)

> row format delimited fields terminated by '\t';

hive (count_log)> insert into table part2 partition (date,hour)

> select * from date_clear;

uuI7f2.png hive21.png

实现统计PV和UV

PV统计

hive (count_log)> select date,hour,count(url) PV from part1 group by date,hour;

nEvIbe.png hive23.png

UV统计

hive (count_log)> select date,hour,count(distinct guid) uv from part1 group by date,hour;

3MZrQv.png hive24.png

在hive中保存PV数和UV数

hive (count_log)> create table if not exists result row format delimited fields terminated by '\t' as

> select date ,hour,count(url) PV ,count(distinct guid) UV from part1 group by date,hour;```

![hive25.png](http://upload-images.jianshu.io/upload_images/3068725-ce760cae9262864c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

6. 利用sqoop把最后结果导出到MySQL

![hive26.png](http://upload-images.jianshu.io/upload_images/3068725-d8c653f40c7798ce.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

![hive27.png](http://upload-images.jianshu.io/upload_images/3068725-552fb9cd6f4151c3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

![hive28.png](http://upload-images.jianshu.io/upload_images/3068725-d4d48657763fa7c0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

mysql 统计 uv pv_结合Hive、Sqoop统计日志pv和uv相关推荐

  1. 如何统计网站各页面一天内的 PV 和 UV?

    大数据开发最常统计的需求可能就是 PV.UV.PV 全拼 PageView,即页面访问量,用户每次对网站的访问均被记录,按照访问量进行累计,假如用户对同一页面访问了 5 次,那该页面的 PV 就应该加 ...

  2. 大数据离线分析系统:统计网站PV、UV

    目录 一.业务需求 二.业务实现方案 1.技术栈 2.业务实现流程 3.离线分析系统架构图 三.技术实现 1.Hadoop CDH集群管理平台 2.Flume采集服务器日志数据到HDFS 3.Spar ...

  3. Vue+百度统计 实现网页的PV和UV统计

    目录 什么是PV和UV? 百度统计 VUE 验证安装 查看统计 拓展 什么是PV和UV? 这里我懒得打字了,直接百度扒过来吧,这个了解知道是啥就行 百度统计 首先你要有个百度账号,自己测试的时候可以用 ...

  4. PV、UV、IP的区别

    PV.UV.IP的区别 作者:段漫 日期:2010/6/2 23:06:47 网站推广需要一个网站访问统计工具,常用的统计工具有百度统计.51la.量子恒道统计等.网站访问量常用的指标为PV.UV.I ...

  5. 网站中PV、UV、IP的区别

    网站推广需要一个网站访问统计工具,常用的统计工具有百度统计.51la.量子恒道统计等.网站访问量常用的指标为PV.UV.IP.那么什么是PV.UV和IP,PV.UV.IP的区别是什么? 首先来看看ip ...

  6. Shell - 一行脚本统计分组 PV、UV

    目录 一.引言 二.数据样式 三.统计分组 PV 四.统计分组 UV 一.引言 本地文件计算用户 PV.UV 时,每次需要使用 py 脚本进行分析处理,十分的麻烦,下面用 shell 命令轻松实现分组 ...

  7. 使用hive和sqoop来实现统计24小时每个时段的PV和UV,storm计算网站UV(去重计算模式)

    [案例]使用hive和sqoop来实现网站基本指标,PV和UV 1.PV统计网页浏览总量 2.UV去重 ->[需求]统计24小时每个时段的PV和UV ->建分区表,按天一级,按小时一级,多 ...

  8. MYSQL统计UV和PV_使用redis做pv、uv、click统计

    redis实时统计 设计思路: 1. 前端smarty插件(smarty_function_murl),将网站所有的连接生成一个urlid,后端根据获取的参数将需要的数据存入redis. 2.后端插件 ...

  9. hadoop2.20+hive+sqoop+mysql数据处理案例

    一.业务说明 使用Hadoop2及其他开源框架,对本地的日志文件进行处理,将处理后需要的数据(PV.UV...)重新导入到关系型数据库(Mysql)中,使用Java程序对结果数据进行处理,组织成报表的 ...

最新文章

  1. 包钢集团、云南建投、南粤交通等大型国企选择用友BIP 实现财务数智能化
  2. mysql 5.7变化_从MySQL 5.5到5.7看复制的演进
  3. MySQL水平分区代理Spock Proxy(一)
  4. 迷你世界显示未连接服务器成功,迷你世界登录未成功是什么意思 | 手游网游页游攻略大全...
  5. 不用担心越界,不用中间变量的数值交换
  6. 如何在官网下载java JDK的历史版本
  7. pyecharts绘制地铁图_安利一个绘制地铁线路KMZ的利器 号称国产谷歌地球
  8. 线段树i hate it
  9. SwiftUI实战三:创建List视图和导航Navigation
  10. android平板改成电视盒子,安卓平板改裝成電視盒子
  11. 不同内核浏览器的差异以及浏览器渲染简介
  12. Layabox 实现 PageView 翻页
  13. 关于人工智能的天马行空
  14. that being said
  15. 必应(bing)广告的费用是多少?bing搜索广告推广简介
  16. c语言之数据类型长度
  17. Python-Snap7与 1212 PLC通信并保存到sqlite3中
  18. RabbitMQ - 4种Exchange类型
  19. Javascript数组部分
  20. ESXI6.7升级至ESXI7及各问题的解决

热门文章

  1. 从程序员到架构师,有捷径吗?
  2. 爬虫-requests,微信公众号推送
  3. 天玑oracle一体机,天玑720处理器相当于哪款麒麟处理器?
  4. 程序员接私活的请注意了
  5. 联合主键的用法及注意事项
  6. SpringBoot配置文件中文乱码
  7. 从事IT行业最开始一年的工作总结(忆往昔-001)
  8. JDK发展历史以及版本特性
  9. PHP二维数组排序 array_multisort
  10. 仓央嘉措--最美的诗