MongDB日志分析
石家庄铁道大学2021年秋季
2019 级课堂测试试卷-MongDB日志分析
课程名称:大型数据库应用技术 任课教师:王建民 测试时间:150分钟
Result文件数据说明:
Ip:106.39.41.166,(城市)
Date:10/Nov/2016:00:01:02 +0800,(日期)
Day:10,(天数)
Traffic: 54 ,(流量)
Type: video,(类型:视频video或文章article)
Id: 8701(视频或者文章的id)
测试要求:
1、 数据清洗:按照进行数据清洗,并将清洗后的数据导入MongDB数据库中。
两阶段数据清洗:
(1)第一阶段:把需要的信息从原始日志中提取出来
ip: 199.30.25.88
time: 10/Nov/2016:00:01:03 +0800
day:10
traffic: 62
文章: article/11325
视频: video/3235
create table result(ip varchar(30),times varchar(30),day varchar(30),traffic varchar(30),type varchar(30),id varchar(30)) row format delimited fields terminated by ',' ;
load data local inpath '/linmob/data/result.txt' overwrite into table result;
(2)第二阶段:根据提取出来的信息做精细化操作
ip--->城市 city(IP)
date--> time:2016-11-10 00:01:03
day: 10
traffic:62
type:article/video
id:11325
create temporary function rm as "hiveUDF.RemoveQuote";
create temporary function df as "hiveUDF.DateTransform";
create table clean_result(ip varchar(30),times varchar(30),day varchar(30),traffic varchar(30),type varchar(30),id varchar(30)) row format delimited fields terminated by ',' ;
insert overwrite table clean_result select ip,df(rm(times)),day,traffic,type,id from result;
(3)MongDB数据库表结构:
create table data( ip string, time string , day string, traffic bigint,
type string, id string )
2、数据处理:
·统计最受欢迎的视频/文章的Top10访问次数 (video/article)
insert into result_visit(visit,id)
select count(*) as visit, id as id from clean_result
group by id order by count(*) desc limit 10;
·按照地市统计最受欢迎的Top10课程 (ip)
insert into result_city(id,count)
select id as id,count(*) as count from clean_result
group by id order by count(*) desc limit 10;
·按照流量统计最受欢迎的Top10课程 (traffic)
insert into result_traffic(id,traffic)
select id as id,sum(traffic) as traffic from clean_result
group by id order by sum(traffic) desc limit 10;
3、 数据可视化:将统计结果倒入MySql数据库中,通过图形化展示的方式展现出来。