48 null bug fix

This commit is contained in:
2026-05-06 21:15:12 +03:00
parent fcde490da1
commit df4abb6969
3 changed files with 89 additions and 40 deletions
+87 -38
View File
@@ -5,6 +5,56 @@
<cfimport prefix="layout" taglib="layout"/>
</cfsilent>
<!--- этого можно было не делать, ошибка возникала при вычитании нулла в cfm --->
<cffunction name="safeCompareNum" returntype="boolean">
<cfargument name="n1" type="any"/>
<cfargument name="operator" type="string"/>
<cfargument name="n2" type="any" default=0/>
<cfif NOT isNumeric(arguments.n1) OR NOT isNumeric(arguments.n2)>
<cfreturn false/>
</cfif>
<cfswitch expression=#arguments.operator#>
<cfcase value="GT">
<cfreturn (n1 GT n2)/>
</cfcase>
<cfcase value="LT">
<cfreturn (n1 LT n2)/>
</cfcase>
<cfcase value="EQ,IS">
<cfreturn (n1 EQ n2)/>
</cfcase>
<cfcase value="NEQ">
<cfreturn (n1 NEQ n2)/>
</cfcase>
<cfcase value="GE,GTE">
<cfreturn (n1 GE n2)/>
</cfcase>
<cfcase value="LE,LTE">
<cfreturn (n1 LE n2)/>
</cfcase>
<cfdefaultcase>
<cfreturn false/>
</cfdefaultcase>
</cfswitch>
</cffunction>
<cffunction name="safeNumberFormat" returntype="string">
<cfargument name="num" type="any"/>
<cfargument name="format" type="string"/>
<cfif NOT isNumeric(arguments.num)>
<cfreturn ""/>
</cfif>
<cftry>
<cfreturn numberFormat(arguments.num, arguments.format)/>
<cfcatch type="any">
<cfreturn ""/>
</cfcatch>
</cftry>
</cffunction>
<m:prepare_ls entity="crm2cloud" settingsKey="crm2cloud" accessObject="" pageInfoOut="pageInfo" trackOut="tr"/>
<cfquery name="qTS">
@@ -94,35 +144,34 @@ select
<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 total">coalesce(h.hosts_total,0) as hosts_total</d:field>
<d:field title="Hosts HA">coalesce(h.hosts_ha,0) as hosts_ha</d:field>
<d:field title="Hosts in mainte nance">coalesce(h.hosts_in_maintenance,0) as hosts_in_maintenance</d:field>
<d:field title="Hosts in service">coalesce(h.hosts_in_service,0) as hosts_in_service</d:field>
<d:field title="Cores Total">coalesce(h.cores,0) as cores</d:field>
<d:field title="Cores in service">coalesce(h.cores_in_service,0) as cores_in_service</d:field>
<d:field title="GHz in service">coalesce(h.ghz_in_service,0) as ghz_in_service</d:field>
<d:field title="Host GHz usage">coalesce(h.host_ghz_usage,0) as host_ghz_usage</d:field>
<d:field title="VM GHz usage">coalesce(u.vm_ghz_usage,0) as vm_ghz_usage</d:field>
<d:field title="CPU GHz">coalesce(h.ghz,0) as ghz</d:field>
<d:field title="RAM GB in service">coalesce(h.ram_in_service,0) as ram_in_service</d:field>
<d:field title="Host CPU usage %">coalesce(h.cpu_usage_perc,0) as cpu_usage_perc</d:field>
<!--- <d:field title="Hosts in use">h.hosts</d:field> --->
<d:field title="Cores Capacity">h.cores as Cores_Capacity</d:field>
<d:field title="Cores Capacity">coalesce(h.cores,0) as Cores_Capacity</d:field>
<!--- <d:field title="GHz Capacity">c.ghz as GHz_Capacity</d:field> --->
<d:field title="GHz Provisioned">h.ghz_provisioned - CASE WHEN hosts_in_maintenance > 0 THEN 0 ELSE h.ghz_subtract_ha END as GHz_Provisioned</d:field><!--- за вычетом согласованных резервов на хосте и на HA --->
<d:field title="GB Provisioned">h.gb_provisioned - CASE WHEN hosts_in_maintenance > 0 THEN 0 ELSE h.gb_subtract_ha END as GB_Provisioned</d:field><!--- за вычетом согласованных резервов на хосте и на HA --->
<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/h.ghz_provisioned)::numeric,2)*100 as GHz_provision_rate</d:field>
<!--- <d:field title="RAM GB Capacity">h.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/h.gb_provisioned)::numeric,2)*100 as GB_alloc_perc</d:field>
<d:field title="RAM usage %">round((u.vm_ram_used/h.gb_provisioned)::numeric,2)*100 as GB_usage_perc</d:field>
<d:field title="Пере подписка vCPU">round((u.vm_cores/h.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 title="GHz Provisioned">coalesce(h.ghz_provisioned - CASE WHEN hosts_in_maintenance > 0 THEN 0 ELSE h.ghz_subtract_ha END,0) as GHz_Provisioned</d:field><!--- за вычетом согласованных резервов на хосте и на HA --->
<d:field title="GB Provisioned">coalesce(h.gb_provisioned - CASE WHEN hosts_in_maintenance > 0 THEN 0 ELSE h.gb_subtract_ha END,0) as GB_Provisioned</d:field><!--- за вычетом согласованных резервов на хосте и на HA --->
<d:field title="VM GHz reserved">coalesce(u.vm_ghz_reserved,0) as vm_ghz_reserved</d:field>
<d:field title="VM GHz обещанные">coalesce(u.vm_ghz_promised,0) as vm_ghz_promised</d:field>
<d:field title="CPU GHz provision rate %">coalesce(round((u.vm_ghz_promised/h.ghz_provisioned)::numeric,2)*100,0) as GHz_provision_rate</d:field>
<d:field title="VM RAM GB alloc">coalesce(u.vm_ram_alloc,0) as vm_ram_alloc</d:field>
<d:field title="VM RAM GB used">coalesce(u.vm_ram_used,0) as vm_ram_used</d:field>
<d:field title="RAM alloc %">coalesce(round((u.vm_ram_alloc/h.gb_provisioned)::numeric,2)*100,0) as GB_alloc_perc</d:field>
<d:field title="RAM usage %">coalesce(round((u.vm_ram_used/h.gb_provisioned)::numeric,2)*100,0) as GB_usage_perc</d:field>
<d:field title="Пере подписка vCPU">coalesce(round((u.vm_cores/h.cores)::numeric,1),0) as oversubscription</d:field>
<d:field title="VM cores">coalesce(u.vm_cores,0) as vm_cores</d:field>
<d:field title="VM">coalesce(u.vms,0) as vms</d:field>
<d:field title="VM CPU Usage %">coalesce(u.vm_ghz_usage/h.ghz_in_service*100,0) as vm_cpu_usage_perc</d:field>
</d:field_set>
from cluster_stat h
left outer join usage u on (h.cluster=u.cluster)
@@ -213,19 +262,19 @@ from qRead
<!--- <td class="r" style="font-size:120%">#numberFormat(ghz,".0")#</td> --->
<td class="r">#hosts_total#</td>
<td class="r<cfif gb_provisioned-vm_ram_alloc LE 0> err</cfif>" style="font-size:130%">#numberFormat(gb_provisioned-vm_ram_alloc,"0")#</td>
<td class="r<cfif gb_provisioned-vm_ram_used LE 0> err</cfif>" style="font-size:130%">#numberFormat(gb_provisioned-vm_ram_used,"0")#</td>
<td class="r<cfif safeCompareNum(gb_provisioned - vm_ram_alloc, "LE", 0)> err</cfif>" style="font-size:130%">
#safeNumberFormat(gb_provisioned-vm_ram_alloc,"0")#</td>
<td class="r<cfif safeCompareNum(gb_provisioned - vm_ram_used, "LE", 0)> err</cfif>" style="font-size:130%">#safeNumberFormat(gb_provisioned - vm_ram_used,"0")#</td>
<td class="r<cfif ghz_provisioned-vm_ghz_reserved LE 0> err</cfif>" style="font-size:130%">#numberFormat(ghz_provisioned-vm_ghz_reserved,".0")#</td>
<td class="r<cfif ghz_provisioned-vm_ghz_reserved LE 0> err</cfif>" style="font-size:130%">#numberFormat((ghz_provisioned-vm_ghz_reserved)/ghz/0.2,"0")#</td>
<td class="r<cfif ghz_provisioned-vm_ghz_reserved LE 0> err</cfif>" style="font-size:130%">#numberFormat((ghz_provisioned-vm_ghz_reserved)/ghz/0.5,"0")#</td>
<td class="r<cfif ghz_provisioned-vm_ghz_reserved LE 0> err</cfif>" style="font-size:130%">#numberFormat((ghz_provisioned-vm_ghz_reserved)/ghz/0.8,"0")#</td>
<td class="r<cfif ghz_provisioned-vm_ghz_promised LE 0> err</cfif>" style="font-size:130%">#numberFormat(ghz_provisioned-vm_ghz_promised,".0")#</td>
<td class="r<cfif ghz_provisioned-vm_ghz_promised LE 0> err</cfif>" style="font-size:130%">#numberFormat((ghz_provisioned-vm_ghz_promised)/ghz/0.2,"0")#</td>
<td class="r<cfif ghz_provisioned-vm_ghz_promised LE 0> err</cfif>" style="font-size:130%">#numberFormat((ghz_provisioned-vm_ghz_promised)/ghz/0.5,"0")#</td>
<td class="r<cfif ghz_provisioned-vm_ghz_promised LE 0> err</cfif>" style="font-size:130%">#numberFormat((ghz_provisioned-vm_ghz_promised)/ghz/0.8,"0")#</td>
<td class="r<cfif safeCompareNum(ghz_provisioned - vm_ghz_reserved, "LE", 0)> err</cfif>" style="font-size:130%">#safeNumberFormat(ghz_provisioned-vm_ghz_reserved,".0")#</td>
<td class="r<cfif safeCompareNum(ghz_provisioned - vm_ghz_reserved, "LE", 0)> err</cfif>" style="font-size:130%">#safeNumberFormat((ghz_provisioned-vm_ghz_reserved)/ghz/0.2,"0")#</td>
<td class="r<cfif safeCompareNum(ghz_provisioned - vm_ghz_reserved, "LE", 0)> err</cfif>" style="font-size:130%">#safeNumberFormat((ghz_provisioned-vm_ghz_reserved)/ghz/0.5,"0")#</td>
<td class="r<cfif safeCompareNum(ghz_provisioned - vm_ghz_reserved, "LE", 0)> err</cfif>" style="font-size:130%">#safeNumberFormat((ghz_provisioned-vm_ghz_reserved)/ghz/0.8,"0")#</td>
<td class="r<cfif safeCompareNum(ghz_provisioned - vm_ghz_promised, "LE", 0)> err</cfif>" style="font-size:130%">#safeNumberFormat(ghz_provisioned-vm_ghz_promised,".0")#</td>
<td class="r<cfif safeCompareNum(ghz_provisioned - vm_ghz_promised, "LE", 0)> err</cfif>" style="font-size:130%">#safeNumberFormat((ghz_provisioned-vm_ghz_promised)/ghz/0.2,"0")#</td>
<td class="r<cfif safeCompareNum(ghz_provisioned - vm_ghz_promised, "LE", 0)> err</cfif>" style="font-size:130%">#safeNumberFormat((ghz_provisioned-vm_ghz_promised)/ghz/0.5,"0")#</td>
<td class="r<cfif safeCompareNum(ghz_provisioned - vm_ghz_promised, "LE", 0)> err</cfif>" style="font-size:130%">#safeNumberFormat((ghz_provisioned-vm_ghz_promised)/ghz/0.8,"0")#</td>
<td class="r">#vms#</td>
</tr>