电商日志流量分析1

接上一篇电商日志流量分析

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总量

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值