2 Commits 46c81869c4 ... 1094a4a065

Author SHA1 Message Date
  zhangpeng 1094a4a065 在bi_host_stat新增两列 一个为 单位(GB/%)一个为cloud 1 year ago
  Ping 152d499a05 修改bi_alm_group_by_time中应用的取数逻辑 1 year ago
1 changed files with 88 additions and 61 deletions
  1. 88 61
      all.sql

+ 88 - 61
all.sql

@@ -325,16 +325,14 @@ from
 		case b.PRIORITY WHEN 'low' then '一般应用' when 'important' then '重要应用' when 'high' then '核心应用' else '未知' end as PRIORITY,
 		case b.PRIORITY WHEN 'low' then '一般应用' when 'important' then '重要应用' when 'high' then '核心应用' else '未知' end as PRIORITY,
 		d.name as app_type_name, 
 		d.name as app_type_name, 
 		e.name as net_name,
 		e.name as net_name,
-		c.mantancevendor as mantancevendor,
-		c.yunweirenyuan as yunweirenyuan,
+		'' as mantancevendor,
+		b.mantance_duty as yunweirenyuan,
 		wf.process_type_name,wrr.app_id
 		wf.process_type_name,wrr.app_id
 	from (select * from v_bi_alm_all_alarm where alarm_object_type ='应用') a
 	from (select * from v_bi_alm_all_alarm where alarm_object_type ='应用') a
 	left join itm_app b
 	left join itm_app b
 	on a.alarm_object_id = b.ITM_APP_ID 
 	on a.alarm_object_id = b.ITM_APP_ID 
 	LEFT JOIN icm_bpm.t_work_resource_real wrr on wrr.object_id = a.alarm_object_id
 	LEFT JOIN icm_bpm.t_work_resource_real wrr on wrr.object_id = a.alarm_object_id
 	left join icm_bpm.t_work_flow wf on wf.id=wrr.work_id
 	left join icm_bpm.t_work_flow wf on wf.id=wrr.work_id
-	inner join bi_itm_hardware_resources c
-	on b.ITM_APP_NAME = c.servicename
 	LEFT JOIN m_com_dict d on b.app_type=d.value
 	LEFT JOIN m_com_dict d on b.app_type=d.value
 	LEFT JOIN m_com_dict e on e.value = b.ITM_NETGROUP_ID 
 	LEFT JOIN m_com_dict e on e.value = b.ITM_NETGROUP_ID 
 	WHERE d.dict_index='app_type' and e.dict_index='itm_resources_netcode'
 	WHERE d.dict_index='app_type' and e.dict_index='itm_resources_netcode'
@@ -532,7 +530,7 @@ CREATE TABLE `bi_app_stat_group_by_time` (
   `itm_monitor_flag` varchar(64) DEFAULT NULL COMMENT '是否进行监控 0未纳入监控 1纳入监控',
   `itm_monitor_flag` varchar(64) DEFAULT NULL COMMENT '是否进行监控 0未纳入监控 1纳入监控',
   `create_time` datetime DEFAULT NULL COMMENT '设备创建时间',
   `create_time` datetime DEFAULT NULL COMMENT '设备创建时间',
   `NAME` varchar(512) DEFAULT NULL COMMENT '所属组织',
   `NAME` varchar(512) DEFAULT NULL COMMENT '所属组织',
-  `resclasscnname` varchar(255) DEFAULT NULL COMMENT '所属类型(网系)',
+  `resclasscnname` varchar(255) DEFAULT NULL COMMENT '所属类型(网系)',bi_host_stat
   `UID` varchar(100) DEFAULT NULL COMMENT 'UID 同告警设备ID',
   `UID` varchar(100) DEFAULT NULL COMMENT 'UID 同告警设备ID',
   `pinpai` varchar(255) DEFAULT NULL COMMENT '设备品牌',
   `pinpai` varchar(255) DEFAULT NULL COMMENT '设备品牌',
   `xinghao` varchar(255) DEFAULT NULL COMMENT '设备型号',
   `xinghao` varchar(255) DEFAULT NULL COMMENT '设备型号',
@@ -1056,83 +1054,112 @@ truncate table bi_sijifayuan_alm_group_by_time;
 
 
 DROP TABLE IF EXISTS `bi_host_stat`;
 DROP TABLE IF EXISTS `bi_host_stat`;
 CREATE TABLE `bi_host_stat` (
 CREATE TABLE `bi_host_stat` (
-  `dtype` varchar(10) NOT NULL DEFAULT '',
-  `thedvalue` varchar(10) DEFAULT NULL,
-  `COMPANY` varchar(30) DEFAULT NULL COMMENT '数据来源',
-  `target` varchar(20) NOT NULL DEFAULT '',
-  `dim` varchar(20) NOT NULL DEFAULT '',
-  `dim_value` decimal(20,8) DEFAULT NULL,
-  `group_agg` varchar(3) NOT NULL DEFAULT ''
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+	`dtype` VARCHAR ( 10 ) NOT NULL DEFAULT '',
+	`thedvalue` VARCHAR ( 10 ) DEFAULT NULL,
+	`COMPANY` VARCHAR ( 30 ) DEFAULT NULL COMMENT '数据来源',
+	`target` VARCHAR ( 20 ) NOT NULL DEFAULT '',
+	`dim` VARCHAR ( 20 ) NOT NULL DEFAULT '',
+	`dim_value` DECIMAL ( 50, 20 ) DEFAULT NULL,
+	`group_agg` VARCHAR ( 10 ) NOT NULL DEFAULT '',
+	`unit` VARCHAR ( 10 ) NOT NULL DEFAULT '单位' ,
+	 `cloud` varchar(255) DEFAULT NULL COMMENT '云平台'
 
 
-	
-	TRUNCATE table bi_host_stat;
-	INSERT INTO bi_host_stat 
-	select 
+) ENGINE = InnoDB DEFAULT CHARSET = utf8;
+TRUNCATE table bi_host_stat;	
+INSERT INTO bi_host_stat 
+
+select 
 		'HOUR' as dtype,
 		'HOUR' as dtype,
-		a.thedvalue,a.COMPANY,
-		case b.mm when 1 then 'CPU' when 2 then '内存' when 3 then '硬盘'when 4 then 'CPU' when 5 then '内存' when 6 then '硬盘'when 7 then 'CPU' when 8 then '内存' when 9 then '硬盘' when 10 then 'CPU' when 11 then '内存' when 12 then '硬盘' else '' end as target,
-		case b.mm when 1 then '额定量' when 2 then '额定量' when 3 then '额定量' when 4 then '分配量' 
-		when 5 then '分配量' when 6 then '分配量'when 7 then '剩余可用' when 8 then '剩余可用' when 9 then '剩余可用' when 10 then '分配占比' when 11 then '分配占比' when 12 then '分配占比' else '' end as dim,
-		case b.mm when 1 then dim1 when 2 then dim2 when 3 then dim3 when 4 then dim4 when 5 then dim5 when 6 then dim6 when 7 then dim7 when 8 then dim8 when 9 then dim9 
-			when 10 then IF(dim1<>0,dim4/dim1,0) when 11 then IF(dim2<>0,dim5/dim2,0) when 12 then IF(dim3<>0,dim6/dim3,0) else null end as dim_value,
-		case b.mm when 1 then 'avg' when 2 then 'max' when 3 then 'max'when 4 then 'avg' when 5 then 'max' when 6 then 'max'when 7 then 'avg' when 8 then 'max' when 9 then 'max' else 'avg' end as group_agg
-	from (
-	select 
-		date_format(CREATE_TIME,'%Y%m%d%H')  as thedvalue,
-		case COMPANY when 'huawei' then '太极云资源池' when 'huawei-xc' then '信创云资源池' when 'shouxin' then '首信云资源池' when 'unicom' then '联通云资源池' else '其它' end as COMPANY,
-		avg(IND_VALUE_HOST_CPU_UTILIZATION) as dim1,MAX(IND_VALUE_HOST_MEMORY_TOTAL) as dim2,MAX(IND_VALUE_HOST_DISK_TOTAL) as dim3,
-		avg(IND_VALUE_HOST_CPU_TOP) as dim4,MAX(IND_VALUE_HOST_MEMORY_USED) as dim5,MAX(IND_VALUE_HOST_DISK_USED) as dim6,
-		avg(IND_VALUE_HOST_CPU_UTILIZATION_LOW) as dim7,MAX(IND_VALUE_HOST_MEMORY_UNUSED) as dim8,MAX(IND_VALUE_HOST_DISK_UNUSED) as dim9
-	from app_host_stat where COMPANY is not null
-	group by COMPANY,date_format(CREATE_TIME,'%Y%m%d%H') ) a
-	cross join
-	(select 1 mm 
-	union all select 2 
-	union all select 3
-	union all select 4
-	union all select 5
-	union all select 6
-	union all select 7
-	union all select 8
-	union all select 9
-	union all select 10
-	union all select 11
-	union all select 12) b;
-	
-	INSERT INTO bi_host_stat 
-	select 'DAY' as dtype,substring(thedvalue,1,8) AS thedvalue,COMPANY,target,dim,AVG(dim_value),group_agg  
+		a.thedvalue,
+		a.COMPANY,
+case b.mm when 1 then 'CPU' when 2 then '内存' when 3 then '硬盘'when 4 then 'CPU' when 5 then '内存' 		when  6 then '硬盘'when 7 then 'CPU' when 8 then '内存' when 9 then '硬盘' when 10 then 'CPU' when 11 then 		   		'内存' when 12 then '硬盘' else '' end as target,		
+case b.mm when 1 then '额定量' when 2 then '额定量' when 3 then '额定量' when 4 then '分配量' 
+			when 5 then '分配量' when 6 then '分配量'when 7 then '剩余可用' when 8 then '剩余可用' when 9 then '剩余可用' when 10 then '分配占比' when 11 then '分配占比' when 12 then '分配占比' else '' end as dim,		
+round(case b.mm when 1 then dim1 when 2 then dim2 when 3 then dim3 when 4 then dim4 when 5 then dim5 when 6 		then dim6 when 7 then dim7 when 8 then dim8 when 9 then dim9 when 10 then IF(dim1<>0,dim4/dim1,0) when 11 
+			then IF(dim2<>0,dim5/dim2,0) when 12 then IF(dim3<>0,dim6/dim3,0) else null end ,2) as dim_value,				
+case b.mm when 1 then 'avg' when 2 then 'max' when 3 then 'max'when 4 then 'avg' when 5 then 'max' when 6 then 		'max'when 7 then 'avg' when 8 then 'max' when 9 then 'max' else 'avg' end as group_agg,
+case b.mm when 1 then 'GB' when 2 then 'GB' when 3 then 'GB' when 4 then 'GB' 
+  when 5 then 'GB' when 6 then 'GB'when 7 then 'GB' when 8 then 'GB' when 9 then 'GB' when 10 then '%' when 11 			then '%' when 12 then '%' else '' end as unit,
+	cloud from (
+	SELECT
+		date_format( temp1.CREATE_TIME, '%Y%m%d%H' ) AS thedvalue,
+	CASE
+			temp1.COMPANY 
+			WHEN 'huawei' THEN
+			'太极云资源池' 
+			WHEN 'huawei-xc' THEN
+			'信创云资源池' 
+			WHEN 'shouxin' THEN
+			'首信云资源池' 
+			WHEN 'unicom' THEN
+			'联通云资源池' ELSE '其它' 
+		END AS COMPANY,
+		avg( IND_VALUE_HOST_CPU_UTILIZATION ) AS dim1,
+		MAX( IND_VALUE_HOST_MEMORY_TOTAL ) AS dim2,
+		MAX( IND_VALUE_HOST_DISK_TOTAL ) AS dim3,
+		avg( IND_VALUE_HOST_CPU_TOP ) AS dim4,
+		MAX( IND_VALUE_HOST_MEMORY_USED ) AS dim5,
+		MAX( IND_VALUE_HOST_DISK_USED ) AS dim6,
+		avg( IND_VALUE_HOST_CPU_UTILIZATION_LOW ) AS dim7,
+		MAX( IND_VALUE_HOST_MEMORY_UNUSED ) AS dim8,
+		MAX( IND_VALUE_HOST_DISK_UNUSED ) AS dim9,
+		temp2.cloud 
+	FROM
+		app_host_stat temp1
+		LEFT JOIN itm_hardware_resources AS temp2 ON temp1.int_id = temp2.ITM_HARDWARE_RESOURCES_ID 
+	WHERE
+		temp1.COMPANY IS NOT NULL 
+	GROUP BY
+		temp1.COMPANY,
+		date_format( temp1.CREATE_TIME, '%Y%m%d%H' ),
+		temp2.cloud 
+	) a
+			cross join
+			(select 1 mm 
+			union all select 2 
+			union all select 3
+			union all select 4
+			union all select 5
+			union all select 6
+			union all select 7
+			union all select 8
+			union all select 9
+			union all select 10
+			union all select 11
+			union all select 12) b; 
+
+INSERT INTO bi_host_stat 
+	select 'DAY' as dtype,substring(thedvalue,1,8) AS thedvalue,COMPANY,target,dim,AVG(dim_value),group_agg,unit,cloud  
 	from bi_host_stat 
 	from bi_host_stat 
 	where group_agg = 'avg' AND dtype = 'HOUR'
 	where group_agg = 'avg' AND dtype = 'HOUR'
-	GROUP BY substring(thedvalue,1,8),COMPANY,target,dim,group_agg
+	GROUP BY substring(thedvalue,1,8),COMPANY,target,dim,group_agg,unit,cloud  
 	UNION ALL
 	UNION ALL
-	select 'DAY' as dtype,substring(thedvalue,1,8) AS thedvalue,COMPANY,target,dim,MAX(dim_value),group_agg  
+	select 'DAY' as dtype,substring(thedvalue,1,8) AS thedvalue,COMPANY,target,dim,MAX(dim_value),group_agg,unit,cloud  
 	from bi_host_stat 
 	from bi_host_stat 
 	where group_agg = 'MAX' AND dtype = 'HOUR'
 	where group_agg = 'MAX' AND dtype = 'HOUR'
-	GROUP BY substring(thedvalue,1,8),COMPANY,target,dim,group_agg;
+	GROUP BY substring(thedvalue,1,8),COMPANY,target,dim,group_agg,unit,cloud  ;
 	
 	
 	INSERT INTO bi_host_stat 
 	INSERT INTO bi_host_stat 
-	select 'MONTH' as dtype,substring(thedvalue,1,6) AS thedvalue,COMPANY,target,dim,AVG(dim_value),group_agg  
+	select 'MONTH' as dtype,substring(thedvalue,1,6) AS thedvalue,COMPANY,target,dim,AVG(dim_value),group_agg,unit,cloud    
 	from bi_host_stat 
 	from bi_host_stat 
 	where group_agg = 'avg' AND dtype = 'DAY'
 	where group_agg = 'avg' AND dtype = 'DAY'
-	GROUP BY substring(thedvalue,1,6),COMPANY,target,dim,group_agg
+	GROUP BY substring(thedvalue,1,6),COMPANY,target,dim,group_agg,unit,cloud  
 	UNION ALL
 	UNION ALL
-	select 'MONTH' as dtype,substring(thedvalue,1,6) AS thedvalue,COMPANY,target,dim,MAX(dim_value),group_agg  
+	select 'MONTH' as dtype,substring(thedvalue,1,6) AS thedvalue,COMPANY,target,dim,MAX(dim_value),group_agg,unit,cloud    
 	from bi_host_stat 
 	from bi_host_stat 
 	where group_agg = 'MAX' AND dtype = 'DAY'
 	where group_agg = 'MAX' AND dtype = 'DAY'
-	GROUP BY substring(thedvalue,1,6),COMPANY,target,dim,group_agg;
+	GROUP BY substring(thedvalue,1,6),COMPANY,target,dim,group_agg,unit,cloud;
 	
 	
 	INSERT INTO bi_host_stat
 	INSERT INTO bi_host_stat
-	select 'YEAR' as dtype,substring(thedvalue,1,4) AS thedvalue,COMPANY,target,dim,AVG(dim_value),group_agg  
+	select 'YEAR' as dtype,substring(thedvalue,1,4) AS thedvalue,COMPANY,target,dim,AVG(dim_value),group_agg,unit,cloud    
 	from bi_host_stat 
 	from bi_host_stat 
 	where group_agg = 'avg' AND dtype = 'MONTH'
 	where group_agg = 'avg' AND dtype = 'MONTH'
-	GROUP BY substring(thedvalue,1,4),COMPANY,target,dim,group_agg
+	GROUP BY substring(thedvalue,1,4),COMPANY,target,dim,group_agg,unit,cloud  
 	UNION ALL
 	UNION ALL
-	select 'YEAR' as dtype,substring(thedvalue,1,4) AS thedvalue,COMPANY,target,dim,MAX(dim_value),group_agg  
+	select 'YEAR' as dtype,substring(thedvalue,1,4) AS thedvalue,COMPANY,target,dim,MAX(dim_value),group_agg,unit,cloud    
 	from bi_host_stat 
 	from bi_host_stat 
 	where group_agg = 'MAX' AND dtype = 'MONTH'
 	where group_agg = 'MAX' AND dtype = 'MONTH'
-	GROUP BY substring(thedvalue,1,4),COMPANY,target,dim,group_agg;
-
+	GROUP BY substring(thedvalue,1,4),COMPANY,target,dim,group_agg,unit,cloud;