Files
payg/cloud_capacity.cfm
T
2026-04-07 19:55:22 +03:00

389 lines
18 KiB
Plaintext

<cfsilent>
<cfimport prefix="m" taglib="lib"/>
<cfimport prefix="c" taglib="lib/controls"/>
<cfimport prefix="d" taglib="lib/data"/>
<cfimport prefix="layout" taglib="layout"/>
</cfsilent>
<m:prepare_ls entity="crm2cloud" settingsKey="crm2cloud" accessObject="" pageInfoOut="pageInfo" trackOut="tr"/>
<cfquery name="qTS">
select
(select max(ts) from vmreports.compute) as ts_compute
,(select max(ts) from vmreports.host) as ts_host
</cfquery>
<cfquery name="qRead">
with
capacity as (
select "Cluster" as cluster, count(*) as hosts, sum(cores) as cores, round(sum(ghz)::numeric,1) 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
,count("UUID_VM") as vms
,sum("VM_vCPU_count") as vm_cores
,sum("VM_vCPU_count"*"VDC_CPU_Speed") as vm_ghz
,sum("VM_CPU_Reserv_GHz") as vm_ghz_reserved
,sum("VM_vCPU_count"*"VDC_CPU_Speed"*"VM_CPU_Reserv_perc"/100) as vm_ghz_reserved_c
,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 - зарезервированные ГГц, если включить минимальное согласованное резервирование
,sum("VM_RAM_Allocated") as vm_ram_alloc
,sum("VM_RAM_Used") as vm_ram_used
,sum("VM_CPU_Used_AVG") as vm_ghz_usage
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
,COUNT(*)-1 as hosts_ha /*не вполне корректно, хосты разного размера, отказ по-разному влияет*/
,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") as cores
,sum(CASE WHEN "Maintenance"='notInMaintenance' THEN "CPU_Cores" ELSE 0 END) as cores_in_service
,sum(CASE WHEN "Maintenance"='notInMaintenance' THEN "CPU_Cores"*"CPU_Speed" ELSE 0 END) as ghz_in_service
,sum("CPU_Used_AVG") as host_ghz_usage
,(sum(CASE WHEN "Maintenance"='notInMaintenance' THEN "RAM_Total" ELSE 0 END)) as ram_in_service
,(avg(CASE WHEN "Maintenance"='notInMaintenance' THEN "CPU_Speed" ELSE 0 END)) as ghz
,CASE WHEN sum("CPU_Cores"*"CPU_Speed") > 0 THEN sum("CPU_Used_AVG")/sum("CPU_Cores"*"CPU_Speed")*100 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"
),
cluster_naming (cluster,commercial_name) AS (VALUES
('cl01-vsan','msk1, Intel Cascade Lake 2,9 ГГц')
,('cl02','msk1, Intel Cascade Lake 3,1 ГГц')
,('cl04-vsan','msk1, AMD Milan 2,8 ГГц')
,('cl05-1c','msk1, AMD Raphael 4,5 ГГц')
,('cl06-vsan','msk1, Intel Ice Lake 2,8 ГГц')
,('cl07-vsan','msk1, AMD Genoa 4,0 ГГц')
)
select
<d:field_set titleMapOut="titleMap" lengthOut="fieldCount">
<d:field title="cluster v1">h.cluster as cluster_v1</d:field>
<d:field title="cluster v2">h.cluster_v2</d:field>
<d:field title="Коммерческое название">n.commercial_name</d:field>
<d:field title="Models">h.models</d:field>
<d:field title="Hosts total">h.hosts_total</d:field>
<d:field title="Hosts HA">h.hosts_ha</d:field>
<d:field title="Hosts in mainte nance">h.hosts_in_maintenance</d:field>
<d:field title="Hosts in service">h.hosts_in_service</d:field>
<d:field title="Cores Total">h.cores</d:field>
<d:field title="Cores in service">h.cores_in_service</d:field>
<d:field title="GHz in service">h.ghz_in_service</d:field>
<d:field title="Host GHz usage">h.host_ghz_usage</d:field>
<d:field title="VM GHz usage">u.vm_ghz_usage</d:field>
<d:field title="CPU GHz">h.ghz</d:field>
<d:field title="RAM GB in service">h.ram_in_service</d:field>
<d:field title="Host CPU usage %">h.cpu_usage_perc</d:field>
<d:field title="Hosts in use">c.hosts</d:field>
<d:field title="Cores Capacity">c.cores as Cores_Capacity</d:field>
<d:field title="GHz Capacity">c.ghz as GHz_Capacity</d:field>
<d:field title="VM GHz reserved">u.vm_ghz_reserved</d:field>
<d:field title="VM GHz обещанные">u.vm_ghz_promised</d:field>
<d:field title="CPU GHz provision rate %">round((u.vm_ghz_promised/c.ghz)::numeric,2)*100 as GHz_provision_rate</d:field>
<d:field title="RAM GB Capacity">c.ram as RAM_Capacity</d:field>
<d:field title="VM RAM GB alloc">u.vm_ram_alloc</d:field>
<d:field title="VM RAM GB used">u.vm_ram_used</d:field>
<d:field title="RAM alloc %">round((u.vm_ram_alloc/c.ram)::numeric,2)*100 as GB_alloc_perc</d:field>
<d:field title="RAM usage %">round((u.vm_ram_used/c.ram)::numeric,2)*100 as GB_usage_perc</d:field>
<d:field title="Пере подписка vCPU">round((u.vm_cores/c.cores)::numeric,1) as oversubscription</d:field>
<d:field title="VM cores">u.vm_cores</d:field>
<d:field title="VM">u.vms</d:field>
<d:field title="VM CPU Usage %">u.vm_ghz_usage/h.ghz_in_service*100 as vm_cpu_usage_perc</d:field>
</d:field_set>
from cluster_stat h
left outer join usage u on (h.cluster=u.cluster)
left outer join capacity c on (h.cluster=c.cluster)
left outer join cluster_naming n on (h.cluster=n.cluster)
where 1=1 <!--- <m:filter_build filter=#pageInfo.settings.filter#/> --->
order by <m:order_build sortArray=#pageInfo.settings.sort.sortArray# fieldCount=#fieldCount#/>
</cfquery>
<cfquery name="qTotal" dbtype="query">
select
sum(hosts_total) as hosts_total
,sum(hosts_ha) as hosts_ha
,sum(hosts_in_maintenance) as hosts_in_maintenance
,sum(hosts) as hosts
,sum(host_ghz_usage) as host_ghz_usage
,sum(cores_in_service) as cores_in_service
,sum(ghz_in_service) as ghz_in_service
,sum(GHz_Capacity) as GHz_Capacity
,sum(ram_in_service) as ram_in_service
,sum(RAM_Capacity) as RAM_Capacity
,sum(cores_in_service) as cores_in_service
,sum(vm_cores) as vm_cores
,sum(vm_ghz_usage) as vm_ghz_usage
,sum(vm_ghz_reserved) as vm_ghz_reserved
,sum(vm_ghz_promised) as vm_ghz_promised
,sum(vm_ram_alloc) as vm_ram_alloc
,sum(vm_ram_used) as vm_ram_used
,sum(vms) as vms
,sum(cores*ghz)/sum(cores) as ghz
from qRead
</cfquery>
<cfif isDefined("output_xls")>
<layout:xml qRead=#qRead# titleMap=#titleMap# filename="#pageInfo.entity#.xml"/>
<cfabort/>
</cfif><cfif isDefined("output_json")>
<layout:json qRead=#qRead# titleMap=#titleMap# filename="#pageInfo.entity#.json"/>
<cfabort/>
</cfif>
<layout:page section="header" pageInfo=#pageInfo#>
<layout:attribute name="title">
<cfoutput><b>Cloud Capacity</b></cfoutput>
</layout:attribute>
<layout:attribute name="controls"><!--- empty to remove controls (filter link) ---></layout:attribute>
</layout:page>
<cfoutput query="qTS">
<h3 style="display:inline-block; margin-right:2em;">Актуальность данных</h3>
<b>VM:</b> #dateFormat(ts_compute,"YYYY-MM-DD")# #timeFormat(ts_compute,"HH:MM")#
<b>Хосты:</b> #dateFormat(ts_host,"YYYY-MM-DD")# #timeFormat(ts_host,"HH:MM")#
</cfoutput>
<h3>Свободно</h3>
<table class="worktable">
<thead>
<layout:grid_head titleMap=#titleMap# sortArray=#pageInfo.settings.sort.sortArray#>
<th width="5%"><layout:column_head name="cluster_v1"/></th>
<th width="5%"><layout:column_head name="cluster_v2"/></th>
<th width="7%"><layout:column_head name="commercial_name"/></th>
<th width="3%"><layout:column_head name="ghz"/></th>
<th width="3%"><layout:column_head name="hosts_total"/></th>
<th width="3%">RAM GB</th>
<th width="3%">CPU GHz (текущий резерв)</th>
<th width="3%">Ядра (текущий резерв | 20%)</th>
<th width="3%">Ядра (текущий резерв | 50%)</th>
<th width="3%">Ядра (текущий резерв | 80%)</th>
<th width="3%">CPU GHz (жесткий резерв)</th>
<th width="3%">Ядра (жесткий резерв | 20%)</th>
<th width="3%">Ядра (жесткий резерв | 50%)</th>
<th width="3%">Ядра (жесткий резерв | 80%)</th>
<th width="3%">ВМ размещено</th>
</layout:grid_head>
</thead>
<cfoutput query="qRead">
<tr>
<td>#cluster_v1#</td>
<td>#cluster_v2#</td>
<td>#commercial_name#</td>
<td class="r">#numberFormat(ghz,".0")#</td>
<td class="r">#hosts_total#</td>
<td class="r<cfif RAM_Capacity-vm_ram_alloc LE 0> err</cfif>">#numberFormat(RAM_Capacity-vm_ram_alloc,"0")#</td>
<td class="r<cfif GHz_Capacity-vm_ghz_reserved LE 0> err</cfif>">#numberFormat(GHz_Capacity-vm_ghz_reserved,".0")#</td>
<td class="r<cfif GHz_Capacity-vm_ghz_reserved LE 0> err</cfif>">#numberFormat((GHz_Capacity-vm_ghz_reserved)/ghz/0.2,"0")#</td>
<td class="r<cfif GHz_Capacity-vm_ghz_reserved LE 0> err</cfif>">#numberFormat((GHz_Capacity-vm_ghz_reserved)/ghz/0.5,"0")#</td>
<td class="r<cfif GHz_Capacity-vm_ghz_reserved LE 0> err</cfif>">#numberFormat((GHz_Capacity-vm_ghz_reserved)/ghz/0.8,"0")#</td>
<td class="r<cfif GHz_Capacity-vm_ghz_promised LE 0> err</cfif>">#numberFormat(GHz_Capacity-vm_ghz_promised,".0")#</td>
<td class="r<cfif GHz_Capacity-vm_ghz_promised LE 0> err</cfif>">#numberFormat((GHz_Capacity-vm_ghz_promised)/ghz/0.2,"0")#</td>
<td class="r<cfif GHz_Capacity-vm_ghz_promised LE 0> err</cfif>">#numberFormat((GHz_Capacity-vm_ghz_promised)/ghz/0.5,"0")#</td>
<td class="r<cfif GHz_Capacity-vm_ghz_promised LE 0> err</cfif>">#numberFormat((GHz_Capacity-vm_ghz_promised)/ghz/0.8,"0")#</td>
<td class="r">#vms#</td>
</tr>
</cfoutput>
</table>
<i>Жесткий резерв - если включим минимальное резервирование 20%</i>
<h3>Использование</h3>
<layout:grid_summary
recordCount=#qRead.recordCount#
footerOut="gridFooter"
excelLink="Yes"
jsonLink="Yes"
/>
<table class="worktable">
<thead>
<layout:grid_head titleMap=#titleMap# sortArray=#pageInfo.settings.sort.sortArray#>
<th width="5%"><layout:column_head name="cluster_v1"/></th>
<th width="5%"><layout:column_head name="cluster_v2"/></th>
<th width="7%"><layout:column_head name="commercial_name"/></th>
<th width="15%"><layout:column_head name="models"/></th>
<th width="3%"><layout:column_head name="ghz"/></th>
<th width="3%"><layout:column_head name="hosts_total"/></th>
<th width="3%"><layout:column_head name="hosts_ha"/></th>
<th width="3%"><layout:column_head name="hosts_in_maintenance"/></th>
<th width="3%"><layout:column_head name="hosts"/></th>
<!--- <th width="3%"><layout:column_head name="hosts_in_service"/></th>
<th width="3%"><layout:column_head name="ram_in_service"/></th>
<th width="3%"><layout:column_head name="cores_in_service"/></th>
<th width="3%"><layout:column_head name="ghz_in_service"/></th> --->
<th width="3%"><layout:column_head name="host_ghz_usage"/></th>
<th width="3%"><layout:column_head name="vm_ghz_usage"/></th>
<th width="3%"><layout:column_head name="cpu_usage_perc"/></th>
<th width="3%"><layout:column_head name="vm_cpu_usage_perc"/></th>
<th width="3%"><layout:column_head name="oversubscription"/></th>
<th width="3%"><layout:column_head name="Cores_Capacity"/></th>
<th width="3%"><layout:column_head name="GHz_Capacity"/></th>
<th width="3%"><layout:column_head name="vm_ghz_reserved"/></th>
<th width="3%"><layout:column_head name="vm_ghz_promised"/></th>
<th width="3%"><layout:column_head name="vm_cores"/></th>
<th width="3%"><layout:column_head name="GHz_provision_rate"/></th>
<th width="3%"><layout:column_head name="RAM_Capacity"/></th>
<th width="3%"><layout:column_head name="vm_ram_alloc"/></th>
<th width="3%"><layout:column_head name="vm_ram_used"/></th>
<th width="3%"><layout:column_head name="GB_alloc_perc"/></th>
<th width="3%"><layout:column_head name="GB_usage_perc"/></th>
<th width="3%">ВМ шт.</th>
<th width="10%">Средняя ВМ</th>
</layout:grid_head>
</thead>
<cfoutput query="qRead">
<tr>
<td>#cluster_v1#</td>
<td>#cluster_v2#</td>
<td>#commercial_name#</td>
<td>#models#</td>
<td class="r">#numberFormat(ghz,".0")#</td>
<td class="r">#hosts_total#</td>
<td class="r">#hosts_ha#</td>
<td class="r"><cfif hosts_in_maintenance NEQ 0>#hosts_in_maintenance#</cfif></td> <!--- style="background:lightcoral" --->
<td class="r">#hosts#</td>
<!--- <td class="r">#hosts_in_service#</td>
<td class="r">#numberFormat(ram_in_service,"0")#</td>
<td class="r">#cores_in_service#</td>
<td class="r">#numberFormat(ghz_in_service,".0")#</td> --->
<td class="r">#numberFormat(host_ghz_usage,".0")#</td>
<td class="r">#numberFormat(vm_ghz_usage,".0")#</td>
<td class="c" style="font-size:130%;">#numberFormat(cpu_usage_perc,"0")#</td>
<td class="c" style="font-size:130%;">#numberFormat(vm_cpu_usage_perc,"0")#</td>
<td class="r">#oversubscription#</td>
<td class="r">#Cores_Capacity#</td>
<td class="r">#numberFormat(GHz_Capacity,".0")#</td>
<td class="r">#numberFormat(vm_ghz_reserved,".0")#</td>
<td class="r">#numberFormat(vm_ghz_promised,".0")#</td>
<td class="r">#vm_cores#</td>
<td class="r">#numberFormat(GHz_provision_rate,"0")#</td>
<td class="r">#numberFormat(RAM_Capacity,"0")#</td>
<td class="r">#numberFormat(vm_ram_alloc,"0")#</td>
<td class="r">#numberFormat(vm_ram_used,"0")#</td>
<td class="r">#numberFormat(GB_alloc_perc,"0")#</td>
<td class="r">#numberFormat(GB_usage_perc,"0")#</td>
<td class="r">#vms#</td>
<td class="r"><cftry>#numberFormat(vm_cores/vms,".0")#&nbsp;core #numberFormat(vm_ghz_usage/vms,".0")#&nbsp;GHz #numberFormat(vm_ghz_usage/vm_cores/ghz*100,"0")#% #numberFormat(vm_ram_alloc/vms,".0")#&nbsp;GB <cfcatch></cfcatch></cftry></td>
</tr>
</cfoutput>
<cfoutput query="qTotal">
<tr class="b">
<td colspan="4" class="r b"> Итого</td>
<td class="r">#numberFormat(ghz,".0")#</td>
<td class="r">#hosts_total#</td>
<td class="r">#hosts_ha#</td>
<td class="r">#hosts_in_maintenance#</td>
<td class="r">#hosts#</td>
<!--- <td class="r"></td>
<td class="r">#numberFormat(ram_in_service,"0")#</td>
<td class="r">#cores_in_service#</td>
<td class="r">#numberFormat(ghz_in_service,".0")#</td> --->
<td class="r">#numberFormat(host_ghz_usage,".0")#</td>
<td class="r">#numberFormat(vm_ghz_usage,".0")#</td>
<td class="r"></td>
<td class="r"><!--- #cpu_usage_perc# ---></td>
<td class="r" style="font-size:130%;">#numberFormat(vm_cores/cores_in_service,".0")#</td>
<td class="r"></td>
<td class="r">#numberFormat(GHz_Capacity,".0")#</td>
<td class="r">#numberFormat(vm_ghz_reserved,".0")#</td>
<td class="r">#numberFormat(vm_ghz_promised,".0")#</td>
<td class="r">#vm_cores#</td>
<td class="r"></td>
<td class="r">#numberFormat(RAM_Capacity,"0")#</td>
<td class="r">#numberFormat(vm_ram_alloc,"0")#</td>
<td class="r">#numberFormat(vm_ram_used,"0")#</td>
<td class="r" style="font-size:130%;">#numberFormat(vm_ram_alloc/ram_in_service*100,"0")#</td>
<td class="r" style="font-size:130%;">#numberFormat(vm_ram_used/ram_in_service*100,"0")#</td>
<td class="r">#vms#</td>
<td class="r">
<cftry>
#numberFormat(vm_cores/vms,".0")#&nbsp;core
#numberFormat(vm_ghz_usage/vms,".0")#&nbsp;GHz
#numberFormat(vm_ghz_usage/vm_cores/ghz*100,"0")#% <!--- *** тут не уверен --->
#numberFormat(vm_ram_alloc/vms,".0")#&nbsp;GB
<cfcatch></cfcatch></cftry>
</td>
</tr>
</cfoutput>
</table>
<!--- <cfdump var=#qCharge#/> --->
<i>Пока выводим избыточный набор колонок для контроля. Кроме того, еще не выбрали, какие колонки удобнее и релевантнее</i>
<br/>
<i>* CPU GHz provision rate % - отношение зарезервированной частоты (с учетом 20% резерва по умолчанию) к наличной частоте процессоров</i>
<br/>
<i>* Расхождения в оценке объема RAM частично связаны с разной оценкой затрат памяти на собственные нужды гипервизора</i>
<br/>
<!--- <cfchart
format="png"
chartWidth="500"
chartHeight="300"
seriesplacement="stacked"
title="Population Distribution: Males vs Females"
scalefrom="-100"
scaleto="100"
labelformat="number">
<!--- Left Side: Males (Negative Values) --->
<cfchartseries type="bar" seriesLabel="Males" seriesColor="##3366CC">
<cfchartdata item="Age 0-10" value="-85">
<cfchartdata item="Age 11-20" value="-70">
<cfchartdata item="Age 21-30" value="-55">
</cfchartseries>
<!--- Right Side: Females (Positive Values) --->
<cfchartseries type="bar" seriesLabel="Females" seriesColor="##FF99CC">
<cfchartdata item="Age 0-10" value="82">
<cfchartdata item="Age 11-20" value="75">
<cfchartdata item="Age 21-30" value="60">
</cfchartseries>
</cfchart> --->
<layout:page section="footer"/>