yhd日志分析(二)

继续yhd日志分析,统计数据

日期 uv pv 登录人数 游客人数 平均访问时长 二跳率 独立ip数

1 分析

登录人数

count(distinct endUserId)

游客人数

count(distinct guid) - count(distinct endUserId)

平均访问时长

先把tracktime转换为unix timestamp, 相同sessionId的tracktime中,max(tracktime)-min(tracktime),得到用户停留时间。所有用户的停留时间相加,得到总停留时间。总停留时间和总访问次数的比例,就是平均访问时长

select sum(stay_time) as total_stay_time
from (select max(to_unix_timestamp(trackTime)) - min(to_unix_timestamp(trackTime)) as stay_time from yhd_log group by sessionId) stay

用户访问总数

count(distinct sessionId)

二跳率

sessionViewNo=2的用户,即为二跳用户。统计出二跳用户和uv的比例

select count(distinct guid) from yhd_log where sessionViewNo=2

独立ip数

count(distinct ip)

实现

  1. 借助中间表,分别存放停留时间和二次跳用户总数

     // 存放总停留时间
    
     create table if not exists yhd_log_total_stay_time(
    date string,
    total_stay_time bigint
    )
    row format delimited fields terminated by '\t'
    stored as textfile; // 存放二次跳用户总数 create table if not exists yhd_log_total_second_jump(
    date string,
    total_second_jump bigint
    )
    row format delimited fields terminated by '\t'
    stored as textfile;
  2. 计算总停留时间,存放在yhd_log_total_stay_time, 按日期分组

     insert overwrite table yhd_log_total_stay_time
    select date, sum(stay_time) as total_stay_time
    from (select max(to_unix_timestamp(trackTime)) - min(to_unix_timestamp(trackTime)) as stay_time, date from yhd_log group by date, sessionId) stay
    group by date
  3. 计算二次跳用户总数,存放在yhd_log_total_second_jump, 按日期分组

     insert overwrite table yhd_log_total_second_jump
    select date, count(distinct guid)
    from yhd_log
    where sessionViewNo=2
    group by date
  4. 统计

     把yhd_log_total_stay_time,yhd_log_total_second_jump和yhd_log按照 date连接查询
    
     select date, pv, uv, user_count, guest_count,
    total_stay_time/total_visit as average_stay_time,
    total_second_jump/ uv as second_jump_rate, indepent_ip
    from (
    select log.date,
    count(url) as pv,
    count(distinct guid) as uv,
    count(distinct endUserId) as user_count,
    count(distinct guid) - count(distinct endUserId) as guest_count,
    count(distinct sessionId) as total_visit,
    min(stay.total_stay_time) as total_stay_time,
    min(second.total_second_jump) as total_second_jump,
    count(distinct ip) as indepent_ip
    from yhd_log log inner join yhd_log_total_stay_time stay on stay.date=log.date inner join yhd_log_total_second_jump second on second.date=log.date
    group by log.date
    ) stat

结果

date pv uv user_count guest_count average_stay_time second_jump_rate indepent_ip
20150828 126134 39007 17687 21320 745.9797393244751 0.13118158279283207 30462

yhd日志分析(二)的更多相关文章

  1. yhd日志分析(一)

    yhd日志分析(一) 依据yhd日志文件统计分析每日各时段的pv和uv 建hive表, 表列分隔符和文件保持一致 load数据到hive表 写hive sql统计pv和uv, 结果保存到hive表2 ...

  2. 日志分析(二) logstash patterns

    grok-patterns内置了很多基础变量的正则表达式的log解析规则,其中包括apache的log解析(同样可以用于nginx的log解析).   基于nginx日志分析配置: 1.配置nginx ...

  3. Apache 日志分析(二)

    01.查看IP cat access_log | awk ‘{print $1}’   02.对IP排序 cat access_log | awk ‘{print $1}’ | sort   03.打 ...

  4. ELK 日志分析实例

    ELK 日志分析实例一.ELK-web日志分析二.ELK-MySQL 慢查询日志分析三.ELK-SSH登陆日志分析四.ELK-vsftpd 日志分析 一.ELK-web日志分析 通过logstash ...

  5. Hadoop学习笔记—20.网站日志分析项目案例(二)数据清洗

    网站日志分析项目案例(一)项目介绍:http://www.cnblogs.com/edisonchou/p/4449082.html 网站日志分析项目案例(二)数据清洗:当前页面 网站日志分析项目案例 ...

  6. Linux服务器access_log日志分析及配置详解(二)

    默认nginx / Linux日志在哪个文件夹? 一般在 xxx.xxx.xxxx.com/home/admin 路径下面的error.log文件和access.log文件error_log logs ...

  7. MySQL慢查询(二) - pt-query-digest详解慢查询日志 pt-query-digest 慢日志分析

    随笔 - 66 文章 - 0 评论 - 19 MySQL慢查询(二) - pt-query-digest详解慢查询日志 一.简介 pt-query-digest是用于分析mysql慢查询的一个工具,它 ...

  8. centos7搭建ELK Cluster集群日志分析平台(二):Logstash

    续  centos7搭建ELK Cluster集群日志分析平台(一) 已经安装完Elasticsearch 5.4 集群. 安装Logstash步骤 . 安装Java 8 官方说明:需要安装Java ...

  9. ELK搭建实时日志分析平台之二Logstash和Kibana搭建

    本文书接前回<ELK搭建实时日志分析平台之一ElasticSearch> 文:铁乐与猫 四.安装Logstash logstash是一个数据分析软件,主要目的是分析log日志. 1)下载和 ...

随机推荐

  1. JDBC数据更新

    在JDBC中通常用Statement类的对象实现对数据库的更新(增.删.查.改)操作 //1.获取数据库连接 connection = getConnection(); //2.准备sql语句 Str ...

  2. ASP.NET MVC开发微信(一)

    public string index() { return Content(""); }

  3. 组合vs继承

    继承,建立子类. 组合(或聚集),在类定义中引用其它类的实例.

  4. js对象3.1--什么是类,对象--杂志

    先来吹吹牛 大家都见过那种做的很精致的小蛋糕吧,给我的感觉就是(很精致,很好看,不经吃太少了,还忒TM的贵).那么这些蛋糕是怎么做出来的呢,反正我不相信是一个一个的扭出来的(除非老板不想赚钱了,那个一 ...

  5. QQ音乐API

    今天分享的是QQ音乐API 搜索歌曲API:http://s.music.qq.com/fcgi-bin/music_search_new_platform?t=0& amp;n={2}&am ...

  6. 基本的git命令

    git是一个分布式管理工具,可以用于代码的管理和维护(每次更新,修改,增加,删除); -->初始化一个仓库 git init 然后会在你所在的文件夹中添加一个隐藏文件.git(这是一个本地数据库 ...

  7. 关于MPEG2中的图像序列和图像组头GOP

    图像序列 图像序列是由图像组构成的,是随机存取段落. sequence_header_code – The sequence_header_code is the bit string ‘000001 ...

  8. 洛谷P1983 车站分级

    P1983 车站分级 297通过 1.1K提交 题目提供者该用户不存在 标签图论贪心NOIp普及组2013 难度普及/提高- 提交该题 讨论 题解 记录 最新讨论 求帮忙指出问题! 我这么和(diao ...

  9. JS常用的设计模式(9)——策略模式

    策略模式的意义是定义一系列的算法,把它们一个个封装起来,并且使它们可相互替换.一个小例子就能让我们一目了然. 回忆下jquery里的animate方法. $( div ).animate( {&quo ...

  10. Threatening letter in Naver Line App

    A suspect sent a threatening letter in Naver Line App to Richman, and said that he wanted those mone ...