084 airplane

This commit is contained in:
2026-09-14 11:56:11 +03:00
parent 26451cbd1d
commit 96a283dd08
5 changed files with 57 additions and 376 deletions
+2 -80
View File
@@ -44,91 +44,13 @@
select
count(distinct obj_id) as unique_vm_cnt,
sum(p.value)/12. as vm_h, -- 5 minute sampling
sum(p.value)/12.*32.18 as cost,
sum(p.value)/12./744 as avg_month_vm -- в августе 744 часа
count(distinct obj)
sum(p.value)/12. as vm_h -- 5 minute sampling
from gpu.vm
JOIN gpu.vm_power_state p on (vm.obj_uuid=p.obj_uuid)
where 1=1
AND p.ts >= '2026-08-01'
AND p.ts < '2026-08-31'
AND vm.client_id='WZ01516'
-- упражнение: посчитать, сколько средних ВМ, включенных круглые сутки, создаст такой же движ за время оказания сервиса
select
p.ts::date,
count(distinct obj_id) as unique_vm_cnt,
round((sum(p.value)/12.)::numeric,1) as vm_h, -- 5 minute sampling
round((sum(p.value)/12.*32.18)::numeric,2) as cost,
round((sum(p.value)/12./24)::numeric, 1) as avg_roundclock_vm
from gpu.vm
JOIN gpu.vm_power_state p on (vm.obj_uuid=p.obj_uuid)
where 1=1
AND p.ts >= '2026-08-01'
AND p.ts < '2026-08-31'
AND vm.client_id='WZ01516'
GROUP BY p.ts::date
ORDER BY 1
select
p.ts::date,
count(distinct obj_id) as unique_vm_cnt,
round((sum(p.value)/12.)::numeric,1) as vm_h, -- 5 minute sampling
round((sum(p.value)/12.*32.18)::numeric,2) as cost,
round((sum(p.value)/12.*32.18*(1-0.02*400/32.18))::numeric,2) as cost_wo_disk,
round((count(distinct obj_id)*0.02*400*24)::numeric,2) as disk_cost_simplified, -- считаем все ВМ, включавшиеся за данные сутки
round((sum(p.value)/12./24)::numeric, 1) as avg_roundclock_vm
from gpu.vm
JOIN gpu.vm_power_state p on (vm.obj_uuid=p.obj_uuid)
where 1=1
AND p.ts >= '2026-08-01'
AND p.ts < '2026-08-31'
AND vm.client_id='WZ01516'
GROUP BY p.ts::date
ORDER BY 1
select
p.ts::date,
count(distinct obj_id) as unique_vm_cnt,
(select count(distinct obj_id) from gpu.vm vm1
JOIN gpu.vm_power_state p1 on (vm1.obj_uuid=p1.obj_uuid)
WHERE vm1.client_id='WZ01516' AND p1.ts <= p.ts::date) as unique_vm_acc,
round((sum(p.value)/12.)::numeric,1) as vm_h, -- 5 minute sampling
round((sum(p.value)/12.*32.18)::numeric,2) as cost,
round((sum(p.value)/12.*32.18*(1-0.02*400/32.18))::numeric,2) as cost_wo_disk,
round((count(distinct obj_id)*0.02*400*24)::numeric,2) as disk_cost_simplified, -- считаем все ВМ, включавшиеся за данные сутки
round((sum(p.value)/12./24)::numeric, 1) as avg_roundclock_vm
from gpu.vm
JOIN gpu.vm_power_state p on (vm.obj_uuid=p.obj_uuid)
where 1=1
AND p.ts >= '2026-08-01'
AND p.ts < '2026-08-31'
AND vm.client_id='WZ01516'
GROUP BY p.ts::date
ORDER BY 1
with daily as (
select
p.ts::date as dt,
count(distinct obj_id) as unique_vm_cnt,
round((sum(p.value)/12.)::numeric,1) as vm_h, -- 5 minute sampling
round((sum(p.value)/12.*32.18)::numeric,2) as cost,
round((sum(p.value)/12.*32.18*(1-0.02*400/32.18))::numeric,2) as cost_wo_disk,
round((count(distinct obj_id)*0.02*400*24)::numeric,2) as disk_cost_simplified, -- считаем все ВМ, включавшиеся за данные сутки
round((sum(p.value)/12./24)::numeric, 1) as avg_roundclock_vm
from gpu.vm
JOIN gpu.vm_power_state p on (vm.obj_uuid=p.obj_uuid)
where 1=1
AND p.ts >= '2026-08-01'
AND p.ts < '2026-08-31'
AND vm.client_id='WZ01516'
GROUP BY p.ts::date
ORDER BY 1
),
acc as (select p.ts::date as dt, count(distinct obj_id) as unique_vm_accum from gpu.vm
JOIN gpu.vm_power_state p on (vm.obj_uuid=p.obj_uuid)
WHERE vm.client_id='WZ01516'
group by p.ts::date)
select * from daily join acc on daily.dt<=acc.dt