Pārlūkot izejas kodu

day, hour视图增加告警时长

Ping 1 gadu atpakaļ
vecāks
revīzija
271069c5f0
2 mainītis faili ar 36 papildinājumiem un 6 dzēšanām
  1. 21 3
      views/v_bi_alm_all_alarm_day.sql
  2. 15 3
      views/v_bi_alm_all_alarm_hour.sql

+ 21 - 3
views/v_bi_alm_all_alarm_day.sql

@@ -34,7 +34,17 @@ select
     floor((`m`.`alarm_count` / `m`.`days`)) AS `avg_alarm_count`,
     if((`m`.`alarm_source` = '性能告警'),
     ((60 / 5) * 24),
-    ((60 * 2) * 24)) AS `collection_frequency`
+    ((60 * 2) * 24)) AS `collection_frequency`,
+    (case
+        when ((`m`.`occur_time` <= `m`.`thedvalue_b`)
+        and (`m`.`update_time` >= `m`.`thedvalue_e`)) then (60 * 24)
+        when ((`m`.`occur_time` > `m`.`thedvalue_b`)
+        and (`m`.`update_time` >= `m`.`thedvalue_e`)) then ((60 * 24) - (`m`.`occur_time` % 100))
+        when ((`m`.`occur_time` <= `m`.`thedvalue_b`)
+        and (`m`.`update_time` < `m`.`thedvalue_e`)) then (`m`.`update_time` % 100)
+        when ((`m`.`occur_time` > `m`.`thedvalue_b`)
+        and (`m`.`update_time` < `m`.`thedvalue_e`)) then ((`m`.`update_time` % 100) - (`m`.`occur_time` % 100))
+    end) AS `alarm_duration`
 from
     (
     select
@@ -53,7 +63,11 @@ from
         'DAY' AS `dtype`,
         `dates`.`YYYYMMDD` AS `thedvalue`,
         1 AS `is_active_alarm`,
-        `aa`.`alarm_source` AS `alarm_source`
+        `aa`.`alarm_source` AS `alarm_source`,
+        date_format(str_to_date(`dates`.`YYYYMMDD`, '%Y%m%d%H%m'), '%Y%m%d%H00') AS `thedvalue_b`,
+        date_format((str_to_date(`dates`.`YYYYMMDD`, '%Y%m%d%H%m') + interval 1 day), '%Y%m%d%H00') AS `thedvalue_e`,
+        date_format(`aa`.`occur_time`, '%Y%m%d%H%m') AS `occur_time`,
+        date_format(`aa`.`update_time`, '%Y%m%d%H%m') AS `update_time`
     from
         (`t_alm_active_alarm` `aa`
     join (
@@ -80,7 +94,11 @@ union all
         'DAY' AS `dtype`,
         `dates`.`YYYYMMDD` AS `thedvalue`,
         0 AS `is_active_alarm`,
-        `ha`.`alarm_source` AS `alarm_source`
+        `ha`.`alarm_source` AS `alarm_source`,
+        date_format(str_to_date(`dates`.`YYYYMMDD`, '%Y%m%d%H%m'), '%Y%m%d%H00') AS `thedvalue_b`,
+        date_format((str_to_date(`dates`.`YYYYMMDD`, '%Y%m%d%H%m') + interval 1 day), '%Y%m%d%H00') AS `thedvalue_e`,
+        date_format(`ha`.`occur_time`, '%Y%m%d%H%m') AS `occur_time`,
+        date_format(`ha`.`update_time`, '%Y%m%d%H%m') AS `update_time`
     from
         (`t_alm_history_alarm` `ha`
     join (

+ 15 - 3
views/v_bi_alm_all_alarm_hour.sql

@@ -21,7 +21,13 @@ select
     floor((`m`.`alarm_count` / `m`.`hours`)) AS `avg_alarm_count`,
     if((`m`.`alarm_source` = '性能告警'),
     (60 / 5),
-    (60 * 2)) AS `collection_frequency`
+    (60 * 2)) AS `collection_frequency`,
+    CASE 
+	    WHEN occur_time<=thedvalue_b and update_time>=thedvalue_e THEN 60
+	    WHEN occur_time>thedvalue_b and update_time>=thedvalue_e THEN 60-MOD(occur_time,100)
+	    WHEN occur_time<=thedvalue_b and update_time<thedvalue_e THEN MOD(update_time,100)
+	    WHEN occur_time>thedvalue_b and update_time<thedvalue_e THEN MOD(update_time,100)-MOD(occur_time,100)
+    END 'alarm_duration'
 from
     (
     select
@@ -40,7 +46,10 @@ from
         'HOUR' AS `dtype`,
         `dates`.`thevalue` AS `thedvalue`,
         1 AS `is_active_alarm`,
-        `aa`.`alarm_source` AS `alarm_source`
+        `aa`.`alarm_source` AS `alarm_source`,
+        date_format(STR_TO_DATE(`dates`.`thevalue`, '%Y%m%d%H%m'),'%Y%m%d%H00') 'thedvalue_b',
+        date_format(DATE_ADD(STR_TO_DATE(`dates`.`thevalue`, '%Y%m%d%H%m'), INTERVAL 1 HOUR),'%Y%m%d%H00') 'thedvalue_e',
+        date_format(`aa`.`occur_time`, '%Y%m%d%H%m') occur_time, date_format(`aa`.`update_time`, '%Y%m%d%H%m') update_time
     from
         (`t_alm_active_alarm` `aa`
     join (
@@ -67,7 +76,10 @@ union all
         'HOUR' AS `dtype`,
         `dates`.`thevalue` AS `thedvalue`,
         0 AS `is_active_alarm`,
-        `ha`.`alarm_source` AS `alarm_source`
+        `ha`.`alarm_source` AS `alarm_source`,
+        date_format(STR_TO_DATE(`dates`.`thevalue`, '%Y%m%d%H%m'),'%Y%m%d%H00') 'thedvalue_b',
+        date_format(DATE_ADD(STR_TO_DATE(`dates`.`thevalue`, '%Y%m%d%H%m'), INTERVAL 1 HOUR),'%Y%m%d%H00') 'thedvalue_e',
+        date_format(`ha`.`occur_time`, '%Y%m%d%H%m') occur_time, date_format(`ha`.`update_time`, '%Y%m%d%H%m') update_time
     from
         (`t_alm_history_alarm` `ha`
     join (