diff --git a/Application.cfc b/Application.cfc index 6307c8c..5175cab 100644 --- a/Application.cfc +++ b/Application.cfc @@ -76,7 +76,7 @@ - + diff --git a/cloud_capacity.cfm b/cloud_capacity.cfm new file mode 100644 index 0000000..3f35ff5 --- /dev/null +++ b/cloud_capacity.cfm @@ -0,0 +1,184 @@ + + + + + + + + + + +with +capacity as ( +select "Cluster" as cluster, count(*) as hosts, sum(cores) as cores, round(sum(ghz)) as ghz, round(sum(ram)) as ram +from ( + select "Cluster", "Host" + , avg("Host_CPU_Cores") as cores, avg("Host_CPU_Cores"*"Host_CPU_Speed") as ghz, avg("Host_RAM"*.85) as ram + from vmreports.compute + where ts=(select max(ts) from vmreports.compute) + group by "Cluster","Host" + order by "Cluster","Host" +) host +group by "Cluster"), + +usage as ( +select "Cluster" as cluster +, sum("VM_vCPU_count") as vm_cores +, round(sum("VM_vCPU_count"*"VDC_CPU_Speed")) as vm_ghz +, round(sum("VM_CPU_Reserv_GHz")) as vm_ghz_reserved +, round(sum("VM_vCPU_count"*"VDC_CPU_Speed"*"VM_CPU_Reserv_perc"/100)) as vm_ghz_reserved_c +, round(sum("VM_vCPU_count"*"VDC_CPU_Speed"*(case when "VM_CPU_Reserv_perc" IS null then 20 when "VM_CPU_Reserv_perc"<=20 then 20 else "VM_CPU_Reserv_perc" end)/100)) as vm_ghz_promised +-- promised - зарезервированные ГГц, если включить минимальное согласованное резервирование +, round(sum("VM_RAM_Allocated")) as vm_ram_alloc +, round(sum("VM_RAM_Used")) as vm_ram_used +from vmreports.compute +where ts=(select max(ts) from vmreports.compute) +group by "Cluster"), + +cluster_stat as ( +SELECT + h."Cluster" as cluster +,h."Cluster_v2" as cluster_v2 +,m.models +,COUNT(*) as hosts_total +,sum(CASE WHEN "Maintenance"='inMaintenance' THEN 1 ELSE 0 END) as hosts_in_maintenance +,sum(CASE WHEN "Maintenance"='notInMaintenance' THEN 1 ELSE 0 END) as hosts_in_service +,sum("CPU_Cores"*"CPU_Sockets") as cores +,sum(CASE WHEN "Maintenance"='notInMaintenance' THEN "CPU_Cores"*"CPU_Sockets" ELSE 0 END) as cores_in_service +,round(sum(CASE WHEN "Maintenance"='notInMaintenance' THEN "CPU_Cores"*"CPU_Sockets"*"CPU_Speed" ELSE 0 END)::numeric,1) as ghz_in_service +,round(avg(CASE WHEN "Maintenance"='notInMaintenance' THEN "CPU_Speed" ELSE 0 END)::numeric,1) as ghz +,CASE WHEN sum("CPU_Cores"*"CPU_Sockets") > 0 THEN round((sum("CPU_Used_AVG"*"CPU_Cores"*"CPU_Sockets")/sum("CPU_Cores"*"CPU_Sockets"))::numeric,0) ELSE NULL END as cpu_usage_perc +FROM vmreports.host h +LEFT OUTER JOIN ( + SELECT hi."Cluster", STRING_AGG(DISTINCT hi."Model" || ' [' || (hi.cnt::text) || '] ',', ') as models + FROM ( + SELECT hii."Cluster", hii."Model", count(hii."Model") as cnt + FROM vmreports.host hii + WHERE hii.ts=(SELECT max(ts) FROM vmreports.host) + GROUP BY hii."Cluster", hii."Model" + ) hi GROUP BY hi."Cluster" +) m ON (h."Cluster"=m."Cluster") +WHERE ts=(SELECT max(ts) FROM vmreports.host) +GROUP BY h."Cluster", h."Cluster_v2", m.models +ORDER BY h."Cluster" +) + + +select + + h.cluster as cluster_v1 + h.cluster_v2 + h.models + h.hosts_total + h.hosts_in_maintenance + h.hosts_in_service + h.cores + h.cores_in_service + h.ghz_in_service + h.ghz + h.cpu_usage_perc + c.hosts + c.cores as Cores_Capacity + c.ghz as GHz_Capacity + u.vm_ghz_reserved + u.vm_ghz_promised + round((u.vm_ghz_promised/c.ghz)::numeric,2) as GHz_provision_rate + c.ram as RAM_Capacity + u.vm_ram_alloc + u.vm_ram_used + round((u.vm_ram_alloc/c.ram)::numeric,2) as GB_provision_rate + +from cluster_stat h +left outer join usage u on (h.cluster=u.cluster) +left outer join capacity c on (h.cluster=c.cluster) + +order by + + + + + + + + + + + + + + + + Сверка CRM - Cloud + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#cluster_v1##cluster_v2##models##hosts_total##hosts_in_maintenance##hosts_in_service##cores_in_service##ghz_in_service##ghz##cpu_usage_perc##hosts##Cores_Capacity##GHz_Capacity##vm_ghz_reserved##vm_ghz_promised##GHz_provision_rate##RAM_Capacity##vm_ram_alloc##vm_ram_used##GB_provision_rate#
+ + + + + diff --git a/crm2cloud.cfm b/crm2cloud.cfm index 373fc32..9ab8378 100644 --- a/crm2cloud.cfm +++ b/crm2cloud.cfm @@ -8,7 +8,7 @@ - + WITH status(status, status_id, probability_pc) as (VALUES ('Закрыта неуспешно',7,0),('Закрыта успешно',6,100),('Договор подписан',5,100),('Договор на подписании',15,90),('Договор на согласовании',12,70), @@ -81,7 +81,7 @@ z.id_klienta as WZ, z.__name as client, z.__id as company_uid, round(sum(c.cnt*o FROM stair o JOIN elma.companies z on (o._companies=z.__id) LEFT OUTER JOIN component c on (c.__id = ANY (o.params)) -WHERE c.code LIKE 'iaas.ngc.%.ram-_' AND c.cnt <> 0 AND o.cnt <> 0 +WHERE c.code SIMILAR TO 'iaas.(ngc|dcp).%.ram-_' AND c.cnt <> 0 AND o.cnt <> 0 GROUP BY z.id_klienta, z.__id, z.__name ), sold_cpu as (SELECT @@ -91,7 +91,7 @@ z.id_klienta as WZ, z.__name as client, z.__id as company_uid, round(sum(c.cnt*o FROM stair o JOIN elma.companies z on (o._companies=z.__id) LEFT OUTER JOIN component c on (c.__id = ANY (o.params)) -WHERE c.code LIKE 'iaas.ngc.%.vcpu%-_' AND c.cnt <> 0 AND o.cnt <> 0 +WHERE c.code SIMILAR TO 'iaas.(ngc|dcp).%.vcpu%-_' AND c.cnt <> 0 AND o.cnt <> 0 GROUP BY z.id_klienta, z.__id, z.__name ), sold_disk as (SELECT @@ -101,7 +101,7 @@ z.id_klienta as WZ, z.__name as client, z.__id as company_uid, round(sum(c.cnt*o FROM stair o JOIN elma.companies z on (o._companies=z.__id) LEFT OUTER JOIN component c on (c.__id = ANY (o.params)) -WHERE c.code SIMILAR TO 'iaas.ngc.%.(ssd|fstssd|sata)-_' AND c.cnt <> 0 AND o.cnt <> 0 +WHERE c.code SIMILAR TO 'iaas.(ngc|dcp).%.(ssd|fstssd|sata)-_' AND c.cnt <> 0 AND o.cnt <> 0 GROUP BY z.id_klienta, z.__id, z.__name ), deal_stat as ( diff --git a/etc/db/cloud_capacity.sql b/etc/db/cloud_capacity.sql new file mode 100644 index 0000000..5105692 --- /dev/null +++ b/etc/db/cloud_capacity.sql @@ -0,0 +1,64 @@ +with +capacity as ( +select "Cluster" as cluster, count(*) as hosts, sum(cores) as cores, round(sum(ghz)) as ghz, round(sum(ram)) as ram +from ( + select "Cluster", "Host" + , avg("Host_CPU_Cores") as cores, avg("Host_CPU_Cores"*"Host_CPU_Speed") as ghz, avg("Host_RAM"*.85) as ram + from vmreports.compute + where ts=(select max(ts) from vmreports.compute) + group by "Cluster","Host" + order by "Cluster","Host" +) host +group by "Cluster"), + +usage as ( +select "Cluster" as cluster +, sum("VM_vCPU_count") as vm_cores +, round(sum("VM_vCPU_count"*"VDC_CPU_Speed")) as vm_ghz +, round(sum("VM_CPU_Reserv_GHz")) as vm_ghz_reserved +, round(sum("VM_vCPU_count"*"VDC_CPU_Speed"*"VM_CPU_Reserv_perc"/100)) as vm_ghz_reserved_c +, round(sum("VM_vCPU_count"*"VDC_CPU_Speed"*(case when "VM_CPU_Reserv_perc" IS null then 20 when "VM_CPU_Reserv_perc"<=20 then 20 else "VM_CPU_Reserv_perc" end)/100)) as vm_ghz_promised +-- promised - зарезервированные ГГц, если включить минимальное согласованное резервирование +, round(sum("VM_RAM_Allocated")) as vm_ram_alloc +, round(sum("VM_RAM_Used")) as vm_ram_used +from vmreports.compute +where ts=(select max(ts) from vmreports.compute) +group by "Cluster"), + +cluster_stat as ( +SELECT + h."Cluster" as cluster +,h."Cluster_v2" as cluster_v2 +,m.models +,COUNT(*) as hosts_total +,sum(CASE WHEN "Maintenance"='inMaintenance' THEN 1 ELSE 0 END) as hosts_in_maintenance +,sum(CASE WHEN "Maintenance"='notInMaintenance' THEN 1 ELSE 0 END) as hosts_in_service +,sum("CPU_Cores"*"CPU_Sockets") as cores +,sum(CASE WHEN "Maintenance"='notInMaintenance' THEN "CPU_Cores"*"CPU_Sockets" ELSE 0 END) as cores_in_service +,round(sum(CASE WHEN "Maintenance"='notInMaintenance' THEN "CPU_Cores"*"CPU_Sockets"*"CPU_Speed" ELSE 0 END)::numeric,1) as ghz_in_service +,round(avg(CASE WHEN "Maintenance"='notInMaintenance' THEN "CPU_Speed" ELSE 0 END)::numeric,1) as ghz +,CASE WHEN sum("CPU_Cores"*"CPU_Sockets") > 0 THEN round((sum("CPU_Used_AVG"*"CPU_Cores"*"CPU_Sockets")/sum("CPU_Cores"*"CPU_Sockets"))::numeric,0) ELSE NULL END as cpu_usage_perc +FROM vmreports.host h +LEFT OUTER JOIN ( + SELECT hi."Cluster", STRING_AGG(DISTINCT hi."Model" || ' [' || (hi.cnt::text) || '] ',', ') as models + FROM ( + SELECT hii."Cluster", hii."Model", count(hii."Model") as cnt + FROM vmreports.host hii + WHERE hii.ts=(SELECT max(ts) FROM vmreports.host) + GROUP BY hii."Cluster", hii."Model" + ) hi GROUP BY hi."Cluster" +) m ON (h."Cluster"=m."Cluster") +WHERE ts=(SELECT max(ts) FROM vmreports.host) +GROUP BY h."Cluster", h."Cluster_v2", m.models +ORDER BY h."Cluster" +) + +select h.cluster +,h.cluster_v2 +,h.models +,c.hosts, c.cores as Cores_Capacity +, c.ghz as GHz_Capacity, u.vm_ghz_reserved, u.vm_ghz_promised, round((u.vm_ghz_promised/c.ghz)::numeric,2) as GHz_provision_rate +, c.ram as RAM_Capacity, u.vm_ram_alloc, u.vm_ram_used, round((u.vm_ram_alloc/c.ram)::numeric,2) as GB_provision_rate +from cluster_stat h +left outer join usage u on (h.cluster=u.cluster) +left outer join capacity c on (h.cluster=c.cluster) \ No newline at end of file diff --git a/etc/db/host-02.sql b/etc/db/host-02.sql new file mode 100644 index 0000000..c63107c --- /dev/null +++ b/etc/db/host-02.sql @@ -0,0 +1,68 @@ +drop table if exists vmreports.host; +create table vmreports.host( +"Name" varchar(255) NULL, +"Model" varchar(255) NULL, +"Cluster" varchar(255) NULL, +"Cluster_v2" varchar(255) NULL, +"Maintenance" varchar(255) NULL, + +"CPU_Cores" float NULL, +"CPU_Sockets" float NULL, +"CPU_Speed" float NULL, +"RAM_Total" float NULL, +"RAM_Used" float NULL, +"CPU_Used" float NULL, +"CPU_Used_AVG" float NULL, +"CPU_Contention_95" float NULL, +"Object_UUID" uuid NOT NULL, +ts timestamptz NOT NULL +,CONSTRAINT PK_host PRIMARY KEY (ts, "Object_UUID") +); +grant all on vmreports.host to nifi; +--alter table vmreports.host ADD "Cluster_v2" varchar(255) NULL; +/* +{ +"type": "record", +"name": "vmreports.host", +"namespace": "org.apache.nifi", +"fields": [ + {"name":"Object_UUID", "type":{"type": "string", "logicalType": "uuid"}}, + {"name":"ts","type":{"type": "long", "logicalType": "local-timestamp-millis"}}, + {"name":"Name", "type":["string" ,"null"]}, + {"name":"Model", "type":["string" ,"null"]}, + {"name":"Cluster", "type":["string" ,"null"]}, + {"name":"Cluster_v2", "type":["string" ,"null"]}, + {"name":"Maintenance", "type":["string" ,"null"]}, + + {"name":"CPU_Cores", "type":["float" ,"null"]}, + {"name":"CPU_Sockets", "type":["float" ,"null"]}, + {"name":"CPU_Speed", "type":["float" ,"null"]}, + {"name":"RAM_Total", "type":["float" ,"null"]}, + {"name":"RAM_Used", "type":["float" ,"null"]}, + {"name":"CPU_Used", "type":["float" ,"null"]}, + {"name":"CPU_Used_AVG", "type":["float" ,"null"]}, + {"name":"CPU_Contention_95", "type":["float" ,"null"]} +] +} +*/ + +/* +{ + "*": { + "objId":"[&1].Name", + "1":"[&1].Model", + "2":"[&1].Cluster", + "3":"[&1].Cluster_v2", + "4":"[&1].Maintenance", + "5":"[&1].CPU_Cores", + "6":"[&1].CPU_Sockets", + "7":"[&1].CPU_Speed", + "8":"[&1].RAM_Total", + "9":"[&1].RAM_Used", + "10":"[&1].CPU_Used", + "11":"[&1].CPU_Used_AVG", + "12":"[&1].CPU_Contention_95", + "objUUID":"[&1].Object_UUID" + } + } +*/ diff --git a/inc/menu.cfm b/inc/menu.cfm index c3c25fe..e24c4a5 100644 --- a/inc/menu.cfm +++ b/inc/menu.cfm @@ -25,6 +25,7 @@ ---> +