v_bi_alm_all_alarm_hour.sql 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. -- lawe.v_bi_alm_all_alarm_hour source
  2. CREATE OR REPLACE
  3. ALGORITHM = UNDEFINED VIEW `v_bi_alm_all_alarm_hour` AS
  4. select
  5. `m`.`alarm_object_ip` AS `alarm_object_ip`,
  6. `m`.`alarm_object_id` AS `alarm_object_id`,
  7. `m`.`alarm_object_type` AS `alarm_object_type`,
  8. `m`.`alarm_object_name` AS `alarm_object_name`,
  9. `m`.`severity_id` AS `severity_id`,
  10. `m`.`title` AS `title`,
  11. `m`.`alarm_text` AS `alarm_text`,
  12. `m`.`clr_status` AS `clr_status`,
  13. `m`.`alarm_count` AS `alarm_count`,
  14. `m`.`bg_time` AS `bg_time`,
  15. `m`.`ed_time` AS `ed_time`,
  16. `m`.`hours` AS `hours`,
  17. `m`.`dtype` AS `dtype`,
  18. `m`.`thedvalue` AS `thedvalue`,
  19. `m`.`is_active_alarm` AS `is_active_alarm`,
  20. floor((`m`.`alarm_count` / `m`.`hours`)) AS `avg_alarm_count`,
  21. if((`m`.`alarm_source` = '性能告警'),
  22. (60 / 5),
  23. (60 * 2)) AS `collection_frequency`,
  24. CASE
  25. WHEN occur_time<=thedvalue_b and update_time>=thedvalue_e THEN 60
  26. WHEN occur_time>thedvalue_b and update_time>=thedvalue_e THEN 60-MOD(occur_time,100)
  27. WHEN occur_time<=thedvalue_b and update_time<thedvalue_e THEN MOD(update_time,100)
  28. WHEN occur_time>thedvalue_b and update_time<thedvalue_e THEN MOD(update_time,100)-MOD(occur_time,100)
  29. END 'alarm_duration'
  30. from
  31. (
  32. select
  33. `aa`.`alarm_object_ip` AS `alarm_object_ip`,
  34. `aa`.`alarm_object_id` AS `alarm_object_id`,
  35. `aa`.`alarm_object_type` AS `alarm_object_type`,
  36. `aa`.`alarm_object_name` AS `alarm_object_name`,
  37. `aa`.`severity_id` AS `severity_id`,
  38. `aa`.`title` AS `title`,
  39. `aa`.`alarm_text` AS `alarm_text`,
  40. `aa`.`clr_status` AS `clr_status`,
  41. `aa`.`alarm_count` AS `alarm_count`,
  42. cast(date_format(`aa`.`occur_time`, '%Y%m%d%H') as unsigned) AS `bg_time`,
  43. cast(date_format(`aa`.`update_time`, '%Y%m%d%H') as unsigned) AS `ed_time`,
  44. (abs(timestampdiff(HOUR, `aa`.`update_time`, `aa`.`occur_time`)) + 1) AS `hours`,
  45. 'HOUR' AS `dtype`,
  46. `dates`.`thevalue` AS `thedvalue`,
  47. 1 AS `is_active_alarm`,
  48. `aa`.`alarm_source` AS `alarm_source`,
  49. date_format(STR_TO_DATE(`dates`.`thevalue`, '%Y%m%d%H%m'),'%Y%m%d%H00') 'thedvalue_b',
  50. date_format(DATE_ADD(STR_TO_DATE(`dates`.`thevalue`, '%Y%m%d%H%m'), INTERVAL 1 HOUR),'%Y%m%d%H00') 'thedvalue_e',
  51. date_format(`aa`.`occur_time`, '%Y%m%d%H%m') occur_time, date_format(`aa`.`update_time`, '%Y%m%d%H%m') update_time
  52. from
  53. (`t_alm_active_alarm` `aa`
  54. join (
  55. select
  56. concat(`dh`.`yyyyMMdd`, lpad(`dh`.`hour`, 2, 0)) AS `thevalue`
  57. from
  58. `dim_hour` `dh`
  59. where
  60. (`dh`.`yyyyMMdd` between 20230101 and 20241231)) `dates`)
  61. union all
  62. select
  63. `ha`.`alarm_object_ip` AS `alarm_object_ip`,
  64. `ha`.`alarm_object_id` AS `alarm_object_id`,
  65. `ha`.`alarm_object_type` AS `alarm_object_type`,
  66. `ha`.`alarm_object_name` AS `alarm_object_name`,
  67. `ha`.`severity_id` AS `severity_id`,
  68. `ha`.`title` AS `title`,
  69. `ha`.`alarm_text` AS `alarm_text`,
  70. `ha`.`clr_status` AS `clr_status`,
  71. `ha`.`alarm_count` AS `alarm_count`,
  72. cast(date_format(`ha`.`occur_time`, '%Y%m%d%H') as unsigned) AS `bg_time`,
  73. cast(date_format(`ha`.`update_time`, '%Y%m%d%H') as unsigned) AS `ed_time`,
  74. (abs(timestampdiff(HOUR, `ha`.`update_time`, `ha`.`occur_time`)) + 1) AS `hours`,
  75. 'HOUR' AS `dtype`,
  76. `dates`.`thevalue` AS `thedvalue`,
  77. 0 AS `is_active_alarm`,
  78. `ha`.`alarm_source` AS `alarm_source`,
  79. date_format(STR_TO_DATE(`dates`.`thevalue`, '%Y%m%d%H%m'),'%Y%m%d%H00') 'thedvalue_b',
  80. date_format(DATE_ADD(STR_TO_DATE(`dates`.`thevalue`, '%Y%m%d%H%m'), INTERVAL 1 HOUR),'%Y%m%d%H00') 'thedvalue_e',
  81. date_format(`ha`.`occur_time`, '%Y%m%d%H%m') occur_time, date_format(`ha`.`update_time`, '%Y%m%d%H%m') update_time
  82. from
  83. (`t_alm_history_alarm` `ha`
  84. join (
  85. select
  86. concat(`dh`.`yyyyMMdd`, lpad(`dh`.`hour`, 2, 0)) AS `thevalue`
  87. from
  88. `dim_hour` `dh`
  89. where
  90. (`dh`.`yyyyMMdd` between 20230101 and 20241231)) `dates`)) `m`
  91. where
  92. (`m`.`thedvalue` between `m`.`bg_time` and `m`.`ed_time`);