經歷一番推理演算,每個欄位逐字分析,接著https://blog.csdn.net/hu_lichao/article/details/110358607 前面的理論,本篇對前面的監控做了更進一步的設計產出,看完絕對不會浪費您的時間,
設計摘要:
任務執行、監控和報警從設計上是可以完全分開的,分開可以讓任務執行盡可能只做任務執行的事情,監控可以根據多種監控規則來進行資料統計,資料分布,而報警則專注于如何根據監控的結果進行自定義靈活地報警,其中在設計上可以以監控為主體,任務執行和報警可以依據需求來定制,從而更好滿足各方需求, 監控規則的設計,暫時從以下幾個方面入手,資料磁區的生成、資料磁區的資料量、資料磁區的資料量波動、表資料欄位的碼值分布波動,監控的主要職責是跑數,跑出報警需要的資料,而報警,可以根據監控的輸出資料以及監控配置進行生成done檔案或者undone 和 報警,
done目錄和原表目錄類似 表/版本/磁區或日期/done/a.done or b.done or c.done (根據配置的根目錄 + 表路徑的后半部分來生成)
1.表資料監控
監控什么?要達到什么目的?
監控主要有兩個目的,一個是報警,另外一個是攔截,攔截為了發生問題時不繼續往下走,所以一般配置有攔截必有報警,有報警不一定有攔截,比如延時報警,
1.1 輸入什么
一個調度平臺的調度時間,以天為單位,最后體現在跑批日志的磁區欄位上,可以支持回溯,其他監控需要的配置資訊都在表資料監控的主表里面,一些特別的配置資訊,會用到附屬表,比如分布子表,
1.2 計算模型
1.2.1磁區有沒有生成 show partitions | grep xx
1.2.2磁區數量大于某個閾值,默認0:select count(*) from db_table where {db_table_date_column} = f($input_date) and version=20201205
1.2.3 磁區數量波動:(磁區數量的count - 前幾天的count平均值) / 前幾天的count平均值
1.2.4 資料碼值分布波動監控
如何衡量資料分布波動
假設某指標碼值和資料分布如下:
| 2020-12-05 | 2020-12-06 | 2020-12-07 |
|---|---|---|
| a 10% | a 9% | a 1% |
| b 50% | b 51% | b 90% |
| c 40% | c 40% | c 9% |
可以看到在12.07日,波動較大,需要做預警,問如何衡量這個波動,以及設定預警
把a,b,c看成一個向量,求比如最近一周(不包括當天)的向量平均值
\[a1,b1,c1 \],然后計算當前向量
\[a0,b0,b1 - a1,b1,c1 / (a1,b1,c1) = a3,b3,c3 \]資料分布波動計算模型
key 當天向量
\[a=(x,y,z...) \]\[b=(x1,y1,z1....) \]那么波動向量
\[c=(a-b)/a \],最終結果
\[c=(x2,y2,z2...) \]2.報警設計
報警任務的每次啟動可以依賴當天磁區資料監控的日志跑批磁區,即至少有跑批日志,才開始進行報警任務,報警的輸入是監控主表和監控跑批表,輸出done,undone && 報警,于報警日志中,
3. 整體設計

使用平臺例行任務來調度監控任務,使用mysql開發環境來讀配置,使用gp來存盤結果資料,使用平臺同步功能將同結構的hive結果表同步到gp來做報表展示,整個程序支持回溯,
表資料監控配置表:
-- 總表
create table table_monitor_conf (
db_table string,
table_charge_people string comment '表負責人',
done_path string comment 'done 檔案輸出位置前綴',
where_condition string comment 'where 子句內容 eg:version=20201201 and dt=#YYYYMMdd#',
if_done string comment '總開關:是否生成done檔案'
if_check_partition string comment '規則1:是否監控產出磁區',
if_check_partition_count string comment '規則2:是否監控產出磁區資料量',
if_check_partition_count_fluctuates string comment '規則3:是否監控產出磁區資料量波動',
if_check_distribute string comment '規則4:是否監控產出表資料分布波動'
)
-- 分布子表if_check_distribute 為1時候使用
create table table_monitor_distribute_conf (
db_table string comment '表名',
with_code_value_keys string comment '有碼值的keys:k1,k2,k3',
no_code_value_keys string comment '無碼值的keys:k1,k2,k3'
)
其中當table_monitor_conf 的 db_table = 'default.default' 時候表示是所有配置記錄的默認值,
表資料量監控跑批記錄:
create table table_monitor_records (
run_db_table string comment '跑批表,來源table_monitor_conf 的db_table',
check_date_time string comment '任務實際跑批時間-程式生成',
run_check_partition string comment '規則1產出:根據where_condition 是否產出磁區'
run_check_partition_count bigint comment '規則2產出:根據where_condition 跑出來的表數量',
run_check_partition_count_fluctuates string comment '規則3產出:表資料量相對一周前平均值的資料波動',
run_check_distribute_json comment '規則4產出:資料分布的大json',
run_check_distribute_fluctuates comment '規則4產出:資料分布的大json相對一周平均值的波動大json'
) partition by (dt string comment '資料跑批磁區,平臺傳入')
comment '監控跑批記錄表'
報警配置表
create table table_monitor_notify_conf(
db_table string comment '庫表',
notify_enable string comment '是否開啟此報警',
normal_produce_datetime string comment '表資料正常產生時間',
check_count_threshold bigint comment '監控產出磁區資料量的閾值',
check_count_fluctuates_threshold double comment '監控產出磁區資料量波動的閾值' ,
check_distribute__json_threshold double comment '表資料分布閾值'
)
報警日志表
create table table_monitor_notify_records(
db_table string comment '哪個表有問題',
view_url string comment '頁面展示地址',
table_charge_people string comment '表負責人',
trouble_description string comment '有什么問題',
check_date_time string comment '報警時間-程式生成',
) patition by (dt string comment '資料跑批磁區,平臺傳入')
寫出資料,done 檔案 ,undone檔案 每個表,每個磁區只有一個
資料分布,在分布波動的第一次跑資料時候,就會寫一份
總共有幾個任務:監控任務,報警任務各1個,每天1點->晚上8點,10分鐘一次
其他:
hi_email_message_phone string comment '報警方式,保留欄位'
zhiban_people string comment '值班負責人,保留欄位',
TODO:
-
[ ] 增加值班人,報警方式升級、
-
[ ] 根據依賴來報警
-
[ ] 通過群內機器人,來操作報警日志表,達到報警暫停一段時間的作用
吳邪,小三爺,混跡于后臺,大資料,人工智能領域的小菜鳥,
更多請關注

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/231844.html
標籤:其他
