2 Star 2 Fork 0

HuaweiCloudDeveloper / huaweicloud-analytics-reference-architecture

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

项目介绍

本项目是是华为云开发者团队基于SaaS项目技术支持实践,通过前端埋点产生的日志行为数据以及后端产生的业务数据为基准,通过在hive数仓中进行离线分析,按天分区存储,将结果存储在obs中,最后通过dlv进行可视化展示。

数据来源

大数据解决方案有一个或者多个数据源对接,包括:

  • 关系型数据库(Relational Database Service,简称RDS)业务数据。
  • 应用程序运行过程中产生的静态数据,比如日志数据。

数据接入

日志数据数据采集。用户使用和网页,app等,在与客户端交互过程,比如浏览网页,点击,评论等,会产生一些日志数据,通过数据埋点,将数据从日志服务器采集到分布式存储系统。

  • 采用高可用的分布式海量日志采集系统Flume,提供拦截器对数据进行ETL处理,支持在日志系统中定制各类数据发送方,用于收集数据。

业务数据接入。用户登录网站进行浏览,可以通过分类查询和全文检索寻找需要的产品,这些产品数据存在业务数据库中。

  • 采用华为的数据接入服务(Data Ingestion Service,简称DIS)可让您轻松收集、处理和分发实时流数据,以便您对新信息快速做出响应。
  • 采用datax工具实现大数据存储系统和关系型数据库之间进行数据交换。datax 是一个异构数据源同步工具,采用Framework + plugin架构构建,可以在关系型数据库、文件存储系统、Hive、HBase等各种异构数据源之间进行数据同步,支持流量控制和运行信息收集,跟踪数据同步情况。

消息队列

对于采集到的日志数据我们可以同步接入到消息队列,可以起到系统之间解耦,峰值缓冲和异步通信的作用,消息队列可以有支持横向扩展,吞吐量高,延时低的特点,为后续实时流式计算提供数据来源。

  • 可以采用Kafka作为消息队列。kafka是一个高吞吐,低延时的分部式消息发布和订阅系统, Kafka是天生是分布式的,数据副本冗余、流量负载均衡、可扩展有较长时间持久化,顺序读和顺序写,通过零拷贝的技术消息直接持久化磁盘等特点。在大数据场景中广泛应用于实时数据计算和日志采集。

数据存储

批处理的数据一般存储在分布式文件存储系统中,该存储系统可以存放各种格式的文件。本文采用obs对象存储服务进行数据的存储。

  • 对象存储服务(Object Storage Service,简称OBS),是一个基于对象的海量存储服务,为客户提供海量、安全、高可靠、低成本的数据存储能力。数据存储和计算分离,使用时无需考虑容量限制,并且提供多种存储类型供选择,满足客户各类业务场景诉求。OBS服务实现了hadoop的HDFS协议,在大数据场景中可以替代hadoop系统中的HDFS服务,实现Spark、MapReduce、Hive、HBase等大数据生态与OBS服务的对接,为大数据计算提供“数据湖”存储。

全流程调度

本分析运营平台由多个任务组成,各个任务单元有前后依赖关系。需要一个批量工作流任务调度器,在一个工作流内以一个特定的顺序运行一组工作和流程

  • 使用任务流调度工具azkaban,每天凌晨进行跑批操作,将shell脚本,hive脚本,java程序进行全流程调度执行。Executor Server处理工作流和作业的实际执行,Web Server处理项目管理,身份验证,计划和执行触发。

BI工具可视化

大多数大数据处理的目的都是通过分析和报告,把运营数据转换成战略决策信息,对企业的发展历程和未来趋势做出定量分析和预测,最终是要给到公司管理决策层进行直观可视化展示的。

  • BI可视化可以使用到华为的数据可视化服务(Data Lake Visualization,简称DLV)是一站式数据可视化平台,适配云上云下多种数据源,提供各种可视化组件,采用拖拽式自由布局,快速定制和应用属于您自己的数据大屏。

可视化展示方案

本项目有两种可视化展示方案,方案一为通过obs对象存储系统直接对接可视化工具DLV,方案二为通过MySQL数据库对接可视化工具DLV。其中OBS系统中将查询语句以csv文件进行存储,而MySQL数据库则需要先行创建好表。

方案一

1.将文件下载到本地,以.csv文件进行保存

执行语句:

###hive -e "set hive.cli.print.header=true;select * from ods_t_order" | sed 's/[\t]/,/g' > /home/huaweicloud/tmp_t_order.csv

2.将本地.csv文件上传至obs中

执行语句:

hadoop fs -put /home/huaweicloud/tmp_t_order.csv obs://obs-east-bkt002/warehouse/hive/ads/tmp_t_order1.csv

3.在dlv数据可视化界面中实现可视化展示

方案二

将obs数据导入到MYSQL,此处以”统计近60天各租户下单省份地图“为例

1.创建HIVE表

DROP TABLE IF EXISTS ads_days_province;
CREATE EXTERNAL TABLE ads_days_province(
domain String,
province String,
amount bigint,
) COMMENT 'ads_days_province'
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
LOCATION 'obs://obs-east-bkt002/warehouse/hive/ads/ads_days_province/';

2.将数据填入到HIVE表

inseret overwrite table ads_days_province SELECT *from ads_days_province

3.将HIVE表obs数据导入到云数据库MYSQL中

 python /opt/module/datax/bin/datax.py  /opt/module/datax/job/ads_province.json

4.在DLV中创建连接,并进行可视化展示

sql查询指标展示

1.统计近60天各租户的营业额

ads_days_amount

hive - e "set hive.cli.print.header=true;
SELECT
domain,
sum( payment ) 
FROM
ods_t_order 
WHERE
to_date ( CURRENT_DATE )<= date_add( to_date ( created_time ), 60 ) 
GROUP BY
domain " | sed 's/[\t]/,/g' > /home/huaweicloud/ads_days_amount.csv ;
hadoop fs -put /home/huaweicloud/ads_days_amount.csv obs://obs-east-bkt002/warehouse/hive/ads/ads_days_amount.csv

​ 字段定义:

current_date 系统当前时间

created_time 订单表中订单的创建时间

domain 租户的域名

payment 每个订单的实际付款

2.统计近60天各租户下单省份地图

SELECT DISTINCT
	c.domain,
	c.province,
	count() over (
	partition BY ( c.domain, c.province )) amount 
FROM
	(
	SELECT
		b.domain,
		province,
		count() over (
		PARTITION BY ( domain, province )) rank 
	FROM
		(
		SELECT
			domain,
			substr( address, 0, 2 ) province 
		FROM
			ods_t_order 
		WHERE
			address NOT LIKE "黑龙%" 
			AND address NOT LIKE "内蒙%" 
			AND address NOT LIKE "钓鱼%" 
			AND to_date ( CURRENT_DATE )<= date_add( to_date ( created_time ), 60 ) 
		) b UNION ALL
		(
		SELECT
			b.domain,
			province,
			count() over (
			PARTITION BY ( domain, province )) rank 
		FROM
			(
			SELECT
				domain,
				substr( address, 0, 3 ) province 
			FROM
				ods_t_order 
			WHERE
				address LIKE "黑龙%" 
				AND address LIKE "内蒙%" 
				AND address LIKE "钓鱼%" 
				AND to_date ( CURRENT_DATE )<= date_add( to_date ( created_time ), 60 ) 
			) b 
		) 
	)c

字段定义:

address 订单表中各订单的下单地址

domain 各租户的域名

province 各订单下单省份

amount 各租户下的各省份订单数量

3.统计近30天各租户top5热销产品

SELECT
			* 
		FROM
			(
			SELECT
				a.domain,
				a.sku_id,
				a.amount,
				row_number() over ( PARTITION BY a.domain ORDER BY a.domain, a.amount DESC ) rank 
			FROM
				(
				SELECT DISTINCT
					domain,
					sku_id,
					count() over ( PARTITION BY domain, sku_id ) amount 
				FROM
					ods_t_order 
				WHERE
					to_date ( CURRENT_DATE )<= date_add( to_date ( created_time ), 30 ) 
				) a 
			) b 
		WHERE
			b.rank <= 5;
	

字段定义:

domain 各租户的域名

sku_id 各服务下的商品id

amount 各租户订单下的各商品销售数量

rank 对各租户下根据商品销售数量进行排序

4.统计出各租户30天内销售的sku_id 及数量

		SELECT DISTINCT
			domain,
			sku_id,
			count() over ( PARTITION BY domain, sku_id ) amount 
		FROM
			ods_t_order 
		WHERE
			to_date ( CURRENT_DATE )<= date_add( to_date ( created_time ), 30 ) 
		ORDER BY
			domain,
			amount DESC;

domain 各租户的域名

sku_id 各服务下的商品id

amount 各租户订单下的各商品销售数量

5.统计各租户近30天每日新增用户数

	SELECT DISTINCT
			a.domain,
			a.day,
			count() over (
			PARTITION BY ( a.domain, a.DAY )) num 
		FROM
			(
			SELECT
				domain,
				to_date ( created_time ) DAY 
			FROM
				ods_user 
			WHERE
				to_date ( CURRENT_DATE )<= date_add( to_date ( created_time ), 30 ) 
				AND account_type = 1 
			)a

domain 各租户的域名

created_time 各用户的创建时间

day 各用户账号的创建日期

num 各租户每天的用户创建数

6.统计各租户用户一周内所登录的时间段(一小时为一个时段)

 SELECT DISTINCT
			a.tenantDomain,
			HOUR,
			count() over (
			PARTITION BY ( a.tenantdomain, HOUR )) amount 
		FROM
			(
			SELECT
				tenantDomain,
				substr( timestr, 12, 2 ) HOUR,
				uid 
			FROM
				dwd_page_log 
			WHERE
				last_page_id = 'login' 
				AND page_id = 'home_service_list' 
				AND to_date ( CURRENT_DATE )<= date_add( to_date ( timestr ), 6 ) 
			) a
			LEFT JOIN ods_user ON a.uid = user_id 
			AND account_type = 1;

tenantDomain 各租户的域名

timestr 各用户的创建时间

hour 各用户的创建的时间段

page_id 当前浏览页面

last_page_id 上个浏览页面

account_type 各账号的种类

amount 各域名下每个小时的用户创建数

7.统计各租户近30天的用户日活量

SELECT DISTINCT
			tenantDomain,
			to_date ( timestr ) DAY,
			count() over (
			PARTITION BY ( tenantDomain, to_date(timestr) )) num 
		FROM
			dwd_page_log 
		WHERE
			last_page_id = 'login' 
			AND page_id = 'home_service-list' 
		AND to_date ( CURRENT_DATE )<= date_add( to_date ( timestr ), 30 )

tenantDomain 各租户的域名

day 各用户账号的创建日期

num 各租户下每天的用户创建数

8.统计近30天各租户的热门浏览页面top5(浏览次数最多的界面)

SELECT
			* 
		FROM
			(
			SELECT
				a.tenantDomain,
				a.page_id,
				a.amount,
				row_number() over ( PARTITION BY a.tenantDomain ORDER BY a.tenantDomain, a.amount DESC ) rank 
			FROM
				(
				SELECT DISTINCT
					tenantDomain,
					page_id,
					count() over ( PARTITION BY tenantDomain, page_id ) amount 
				FROM
					dwd_page_log 
				WHERE
					to_date ( CURRENT_DATE )<= date_add( to_date ( created_time ), 30 ) 
				) a 
			) b 
		WHERE
		b.rank <= 5;

tenantDomain 各租户的域名

page_id 当前浏览页面

amount 各租户下当前页面的浏览数

created_time 当前页面的访问时间

rank 各租户的浏览页面次数排序

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

本项目旨在为开发者数据分析平台搭建提供技术方案参考,通过前端埋点产生的日志行为数据以及后端产生的业务数据为基准,在hive数仓中进行离线分析,按天分区存储,将结果存储在obs中,最后通过dlv进行可视化展示。 展开 收起
Shell 等 3 种语言
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/HuaweiCloudDeveloper/huaweicloud-analytics-reference-architecture.git
git@gitee.com:HuaweiCloudDeveloper/huaweicloud-analytics-reference-architecture.git
HuaweiCloudDeveloper
huaweicloud-analytics-reference-architecture
huaweicloud-analytics-reference-architecture
master-dev

搜索帮助

344bd9b3 5694891 D2dac590 5694891