日志分析_统计每日各时段的的PV,UV

时间:2022-09-05 08:49:57

第一步: 需求分析

需要哪些字段(时间:每一天,各个时段,id,url,guid,tracTime)
需要分区为天/时
PV(统计记录数)
UV(guid去重)

第二步: 实施步骤

建Hive表,表列分隔符和文件保持一至
Load数据到Hive表中
写HiveSql进行统计,将结果放入Hive另一张表中(数据清洗)
从Hive的另一张表中的数据导出到Mysql,使用sqoop
网站项目从Mysql读取这张表的信息

预期结果

日期		小时		PV		UV

第三步: 实施

# 建源表(注意进入beeline用户名密码是linux的)
  create database if not exists track_log;
  use track_log;
  create table if not exists yhd_source(
  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 '/home/liuwl/opt/datas/2015082818' into table yhd_source;
  load data local inpath '/home/liuwl/opt/datas/2015082819' into table yhd_source;
# 创建清洗表
  create table if not exists yhd_clean(
  id string,
  url string,
  guid string,
  date string,
  hour string)
  row format delimited fields terminated by '\t'
  insert into table yhd_clean select id,url,guid,substring(trackTime,9,2) date,substring(trackTime,12,2) hour from yhd_source;
  select id,date,hour from yhd_clean limit 5;
# 改建分区表(静态分区)
  create table if not exists yhd_part1(
  id string,
  url string,
  guid string
  ) partitioned by (date string,hour string)
  row format delimited fields terminated by '\t'
  insert into table yhd_part1 partition (date='28',hour='18') select id,url,guid from yhd_clean where date='28' and hour='18';
  insert into table yhd_part1 partition (date='28',hour='19') select id,url,guid from yhd_clean where date='28' and hour='19';
  select id,date ,hour from yhd_part1 where date ='28' and hour='18' limit 10;
# 使用动态分区需要修改部分参数
 hive.exec.dynamic.partition--true
 hive.exec.dynamic.partition.mode--nonstrict
  create table if not exists yhd_part2(
  id string,
  url string,
  guid string
  ) partitioned by (date string,hour string)
  row format delimited fields terminated by '\t'
# 动态分区根据partition字段进行匹配
  insert into table yhd_part2 partition (date,hour) select * from yhd_clean;
  select id,date ,hour from yhd_part2 where date ='28' and hour='18' limit 10;
# 实现需求
  PV: select date,hour,count(url) PV from yhd_part1 group by date,hour;
  0: jdbc:hive2://hadoop09-linux-01.ibeifeng.co> select date,hour,count(url) PV from yhd_part1 group by date,hour;
  +-------+-------+--------+--+
  | date | hour | pv |
  +-------+-------+--------+--+
  | 28 | 18 | 64972 |
  | 28 | 19 | 61162 |
  +-------+-------+--------+--+
  UV: select date,hour,count(distinct(guid)) UV from yhd_part1 group by date,hour;
  0: jdbc:hive2://hadoop09-linux-01.ibeifeng.co> select date,hour,count(distinct(guid)) UV from yhd_part1 group by date,hour;
  +-------+-------+--------+--+
  | date | hour | uv |
  +-------+-------+--------+--+
  | 28 | 18 | 23938 |
  | 28 | 19 | 22330 |
  +-------+-------+--------+--+
# 结合放入log_result表
  create table if not exists log_result as select date,hour,count(url) PV,count(distinct(guid)) UV from yhd_part1 group by date,hour;
  select date,hour,pv,uv from log_result;
  0: jdbc:hive2://hadoop09-linux-01.ibeifeng.co> select date,hour,pv,uv from log_result;
  +-------+-------+--------+--------+--+
  | date | hour | pv | uv |
  +-------+-------+--------+--------+--+
  | 28 | 18 | 64972 | 23938 |
  | 28 | 19 | 61162 | 22330 |
  +-------+-------+--------+--------+--+
# 将结果表导出到Mysql,使用Sqoop
# 在Mysql中创建数据库和表
  create database if not exists track_result;
  use track_result;
  create table if not exists log_track_result(
  date varchar(10) not null,
  hour varchar(10) not null,
  pv varchar(10) not null,
  uv varchar(10) not null,
  primary key(date,hour)
  );
# 使用sqoop export 导出到log_track_result表
  bin/sqoop export \
  --connect jdbc:mysql://hadoop09-linux-01.ibeifeng.com:3306/track_result \
  --username root \
  --password root \
  --table log_track_result \
  --export-dir /user/hive/warehouse/track_log.db/log_result \
  --num-mappers 1 \
  --input-fields-terminated-by '\001'
# 在Mysql中查询测试
  select * from log_track_result;
  mysql> select * from log_track_result;
  +------+------+-------+-------+
  | date | hour | pv | uv |
  +------+------+-------+-------+
  | 28 | 18 | 64972 | 23938 |
  | 28 | 19 | 61162 | 22330 |
  +------+------+-------+-------+
  2 rows in set (0.00 sec)  

日志分析_统计每日各时段的的PV,UV的更多相关文章

  1. 日志分析_使用shell完整日志分析案例

    一.需求分析 1. 日志文件每天生成一份(需要将日志文件定时上传至hdfs) 2. 分析日志文件中包含的字段:访问IP,访问时间,访问URL,访问状态,访问流量 3. 现在有"昨日&quot ...

  2. 统计_statistics_不同的人_大样本_分析_统计方法_useful ?

    统计_statistics_不同的人_大样本_分析_

  3. 日志分析-mime统计

    提取日志中未落入标准字段的mime,分adx,adtype 统计mime的数量和包含js的数量占比 require 'date' require 'net/http' require 'uri' re ...

  4. 使用Spark进行搜狗日志分析实例——统计每个小时的搜索量

    package sogolog import org.apache.spark.rdd.RDD import org.apache.spark.{SparkConf, SparkContext} /* ...

  5. nginx日志分析及其统计PV、UV、IP

    一.nginx日志结构 nginx中access.log 的日志结构: $remote_addr 客户端地址 211.28.65.253 $remote_user 客户端用户名称 -- $time_l ...

  6. yhd日志分析(二)

    yhd日志分析(二) 继续yhd日志分析,统计数据 日期 uv pv 登录人数 游客人数 平均访问时长 二跳率 独立ip数 1 分析 登录人数 count(distinct endUserId) 游客 ...

  7. Spark SQL慕课网日志分析(1)--系列软件(单机)安装配置使用

    来源: 慕课网 Spark SQL慕课网日志分析_大数据实战 目标: spark系列软件的伪分布式的安装.配置.编译 spark的使用 系统: mac 10.13.3 /ubuntu 16.06,两个 ...

  8. mtools 是由MongoDB 官方工程师实现的一套工具集,可以很快速的日志查询分析、统计功能,此外还支持本地集群部署管理.

    mtools 是由MongoDB 官方工程师实现的一套工具集,可以很快速的日志查询分析.统计功能,此外还支持本地集群部署管理 https://www.cnblogs.com/littleatp/p/9 ...

  9. shell常用命令及正则辅助日志分析统计

    https://www.cnblogs.com/wj033/p/3451618.html 正则日志分析统计 3 grep 'onerror'  v3-0621.log | egrep  -v '(\d ...

随机推荐

  1. 移动应用平台的开发环境的发展演变-elcipse与android studio

    这题目摆出来是要谈平台开发和演变和使用经验的,然而,并没有开发相关项目的经验,所以只好说说安装过程了. 1.android环境搭建到hello world(费时7小时....) 原以为android环 ...

  2. 自动打开Accesibility Service 可以自动安装APP

    package com.venscor.helloworld;import java.io.BufferedReader;import java.io.IOException;import java. ...

  3. sql sever跨数据库复制数据的方法【转】

    1,用Opendatasource系统函数 详细的用法已经注释在sql代码中了.这个是在sqlserver到sqlserver之间的倒数据.2005,2008,2012应该都是适用的. --从远程服务 ...

  4. AngularJS尝鲜一

    第一个小例子,体验一下: <!DOCTYPE html> <html> <head> <title>Index</title> </h ...

  5. Android 性能优化——之图片的优化

    Android 性能优化——之图片的优化 在Android性能优化中,我们会发现占内存最大的和对性能影响最大的往往是图片资源,其次是控件资源.相对来说,其他的资源的影响会小一点.这里我就先对图片资源的 ...

  6. nrm是什么?以及nrm的安装与命令

    nrm的作用与安装使用 一.nrm是什么? 这是官方的原话: 开发的npm registry 管理工具 nrm, 能够查看和切换当前使用的registry, 最近NPM经常 down 掉, 这个还是很 ...

  7. 销售订单-修改量-高级定价关联sql

    修改量消耗明细 --修改量消耗明细 SELECT t.name, t.comments, t.version_no, cux_rebate_pub.get_hou_name(p_organizatio ...

  8. Mac下使用国内镜像安装Homebrew

    First MBP上的brew很老了,就想把brew更新一下,顺便安装一下NodeJs.无奈更新的过程一直卡在网络下载,毫不动弹.想想,应该是Repo访问不到的原因,于是重装brew. 根据官网上的方 ...

  9. vue项目部署到服务器

    1.配置config目录下index.js index: path.resolve(__dirname, '../dist/index.html'), assetsRoot: path.resolve ...

  10. python大法好——装饰器、生成器、迭代器

    1.装饰器 1. 不能修改被装饰的函数的源代码  2. 不能修改被装饰的函数的调用方式 实现装饰器知识储备: 1 函数即“变量” 2 高阶函数     a:把一个函数名当做实参传给另外一个函数(不修改 ...