用户行为收集到hive

用户日志如何收集

为用户建立画像提供依据
便于了解分析用户的行为、喜好变化

  1. 埋点开发测试流程
    一般用户有很多日志,我们当前黑马头条推荐场景统一到行为日志中,还有其它业务场景如(下单日志、支付日志)
  • 埋点参数

    • 就是在应用中特定的流程收集一些信息,用来跟踪应用使用的状况,后续用来进一步优化产品或是提供运营的数据支撑
    • 重要性:埋点数据是推荐系统的基石,模型训练和效果数据统计都基于埋点数据,需保证埋点数据的正确无误
  1. 流程
    1、PM(项目经理)、算法推荐工程师一起指定埋点需求文档
    2、后端、客户端 APP集成
    3、推荐人员基于文档埋点测试与梳理

文章推荐埋点需求整理
文章行为特点:点击、浏览、收藏、分享等行为,基于这些我们制定需求

  • 埋点场景
    首页中的各频道推荐
  • 埋点事件号
    停留时间 read
    点击事件 click
    曝光事件(相当于刷新一次请求推荐新文章) exposure
    收藏事件 collect
    分享事件 share
    埋点参数文件结构
# 曝光的参数,(下拉刷新)
{"actionTime":"2019-04-10 18:15:35","readTime":"","channelId":0,"param":{"action": "exposure", "userId": "2", "articleId": "[18577, 14299]", "algorithmCombine": "C2"}}

# 对文章发生行为的参数
{"actionTime":"2019-04-10 18:12:11","readTime":"2886","channelId":18,"param":{"action": "read", "userId": "2", "articleId": "18005", "algorithmCombine": "C2"}}
{"actionTime":"2019-04-10 18:15:32","readTime":"","channelId":18,"param":{"action": "click", "userId": "2", "articleId": "18005", "algorithmCombine": "C2"}}
{"actionTime":"2019-04-10 18:15:34","readTime":"1053","channelId":18,"param":{"action": "read", "userId": "2", "articleId": "18005", "algorithmCombine": "C2"}}
{"actionTime":"2019-04-10 18:15:36","readTime":"","channelId":18,"param":{"action": "click", "userId": "2", "articleId": "18577", "algorithmCombine": "C2"}}
{"actionTime":"2019-04-10 18:15:38","readTime":"1621","channelId":18,"param":{"action": "read", "userId": "2", "articleId": "18577", "algorithmCombine": "C2"}}
{"actionTime":"2019-04-10 18:15:39","readTime":"","channelId":18,"param":{"action": "click", "userId": "1", "articleId": "14299", "algorithmCombine": "C2"}}
{"actionTime":"2019-04-10 18:15:39","readTime":"","channelId":18,"param":{"action": "click", "userId": "2", "articleId": "14299", "algorithmCombine": "C2"}}
{"actionTime":"2019-04-10 18:15:41","readTime":"914","channelId":18,"param":{"action": "read", "userId": "2", "articleId": "14299", "algorithmCombine": "C2"}}
{"actionTime":"2019-04-10 18:15:47","readTime":"7256","channelId":18,"param":{"action": "read", "userId": "1", "articleId": "14299", "algorithmCombine": "C2"}}

我们将埋点参数设计成一个固定格式的json字符串,它包含了事件发生事件、算法推荐号、获取行为的频道号、帖子id列表、帖子id、用户id、事件号字段。

离线部分-用户日志收集

目的:通过flume将业务数据服务器A的日志收集到hadoop服务器hdfs的hive中
注意:这里我们都在hadoop-master上操作

收集步骤
  • 创建HIVE对应日志收集表
    收集到新的数据库中
    在这里我们创建一个新的数据库profile,表示用户相关数据,画像存储到这里
# 创建profile数据库
create database if not exists profile comment "use action" location '/user/hive/warehouse/profile.db/';
# 在profile数据库中创建user_action表,指定格式
create table user_action(
actionTime STRING comment "user actions time",
readTime STRING comment "user reading time",
channelId INT comment "article channel id",
param map comment "action parameter")
COMMENT "user primitive action"
PARTITIONED BY(dt STRING)
ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe'
LOCATION '/user/hive/warehouse/profile.db/user_action';

在这里插入图片描述
hive进行分区的原因
1.为了更快的查询
2.hive适合大文件处理,
3.日志一般是按时间进行分区,也就是有365个分区,面对大量文件已经是大分区了

# 知识补充
# 什么是分区,以及为什么分区?
# 1 分区是储存位置的物理区别,表 实质上是被分割了;分区表指的是在创建表时指定的partition的分区空间。
# 1.在Hive Select查询中一般会扫描整个表内容,会消耗很多时间做没必要的工作。有时候只需要扫描表中关心的一部分数据,因此建表时引入了partition概念

# 分区建表分为2种,一种是单分区,也就是说在表文件夹目录下只有一级文件夹目录。另外一种是多分区,表文件夹下出现多文件夹嵌套模式。


# a、单分区建表语句:create table day_table (id int, content string) partitioned by (dt string);单分区表,按天分区,在表结构中存在id,content,dt三列。
# b、双分区建表语句:create table day_hour_table (id int, content string) partitioned by (dt string, hour string);双分区表,按天和小时分区,在表结构中新增加了dt和hour两列。

  • flume收集日志配置

1、flume读取设置
进入flume/conf目录
创建一个collect_click.conf的文件,写入flume的配置

sources:为实时查看文件末尾,interceptors解析json文件
channels:指定内存存储,并且制定batchData的大小,PutList和TakeList的大小见参数,Channel总容量大小见参数
指定sink:形式直接到hdfs,以及路径,文件大小策略默认1024、event数量策略、文件闲置时间
在这里插入图片描述
在这里插入图片描述

在 137服务器上 找进入logs
在这里插入图片描述

  • 开启收集命令
/root/bigdata/flume/bin/flume-ng agent -c /root/bigdata/flume/conf -f /root/bigdata/flume/conf/collect_click.conf -Dflume.root.logger=INFO,console -name a1

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

# 同时我们可以通过向userClick.log数据进行测试
echo {\"actionTime\":\"2019-04-10 21:04:39\",\"readTime\":\"\",\"channelId\":18,\"param\":{\"action\": \"click\", \"userId\": \"2\", \"articleId\": \"14299\", \"algorithmCombine\": \"C2\"}} >> userClick.log

在这里插入图片描述

select * from user_action where dt='yy-mm-dd'

# 如果flume自动生成目录后,需要手动关联分区
alter table user_action add partition (dt='2018-12-11') location "/user/hive/warehouse/profile.db/user_action/2018-12-11/"

select * from user_action where dt='yy-mm-dd' limit 1;

Supervisor进程管理

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值