您当前的位置: 首页 > 

宝哥大数据

暂无认证

  • 0浏览

    0关注

    1029博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

电商日志流量分析1

宝哥大数据 发布时间:2018-08-25 08:52:13 ,浏览量:0

接上一篇电商日志流量分析 7 模块开发——统计分析 注:每一种统计指标都可以跟各维度表进行叉乘,从而得出各个维度的统计结果,为了在前端展示时速度更快,每一个指标都事先算出各维度结果存入mysql 明细宽表
#etl明细宽表 
drop table ods_weblog_detail;
create table ods_weblog_detail(
valid           string, --有效标识
remote_addr     string, --来源IP
remote_user     string, --用户标识
time_local      string, --访问完整时间
daystr          string, --访问日期
timestr         string, --访问时间
month           string, --访问月
day             string, --访问日
hour            string, --访问时
request         string, --请求的url
status          string, --响应码
body_bytes_sent string, --传输字节数
http_referer    string, --来源url
ref_host        string, --来源的host
ref_path        string, --来源的路径
ref_query       string, --来源参数query
ref_query_id    string, --来源参数query的值
http_user_agent string --客户终端标识
)
partitioned by(datestr string);

提前准备好维表数据,在hive仓库中创建相应维表,如:

时间维表:
create table v_time(year string,month string,day string,hour string)
row format delimited
fields terminated by ',';

load data local inpath '/home/hadoop/v_time.txt' into table v_time;

在实际生产中,究竟需要哪些统计指标通常由相关数据需求部门人员提出,而且会不断有新的统计需求产生,以下为网站流量分析中的一些典型指标示例。

1. PV统计 1.1 多维度统计PV总量 1.1.1 时间维度 计算指定的各个小时pvs
select month,day,hour,count(*) from ods_weblog_detail where datestr='2013-09-18' group by month,day,hour;
将统计结果存入每小时pv统计表
-- 每小时pv统计表
drop table dw_pvs_hour;
create table dw_pvs_hour(month string,day string,hour string,pvs bigint) 
partitioned by(datestr string);


-- 从ods_weblog_detail 中统计每小时的pvs, 插入小时表中。
insert into dw_pvs_hour partition(datestr='2013-09-18')
select month,day,hour,count(*) from ods_weblog_detail 
where datestr='2013-09-18' group by month,day,hour;
1.1.2、天维度
-- 天表
drop table dw_pvs_day;
create table dw_pvs_day(pvs bigint,month string,day string);

-- 从之前算好的小时结果中统计
Insert into table dw_pvs_day
Select sum(pvs) as pvs,month,day from dw_pvs_hour group by month,day having day='18';

-- 也可以通过时间维表 关联 明细表,统计天pvs
insert into table dw_pvs_day
select count(1) as pvs,a.month as month,a.day as day  from v_time a
join ods_weblog_detail b 
on b.datestr='2013-09-18' and a.month=b.month and a.day=b.day
group by a.month,a.day;
1.1.3、月维度
-- 月表
drop table dw_pvs_month;
create table dw_pvs_month (pvs bigint,month string);

-- 关联时间维表
insert into table dw_pvs_month
select count(*) as pvs,a.month from v_time a
join ods_weblog_detail b on a.month=b.month group by a.month;

-- 根据天表聚合
select sum(pvs), month from dw_pvs_day group by month;
1.2、按终端维度统计pv总量
关注
打赏
1587549273
查看更多评论
立即登录/注册

微信扫码登录

0.0415s