Hello!
I've a problem with calculate uptime and chargeback
We use rate allocated per hour. I think it will be calculated by this formula:
Memory allocation per hour (in MB) * Hourly Allocation cost per megabyte * Number of Memory Allocation metrics available for the day
But where i can find allocation metrics ?
In MetricRollup i see only used metric
So, and the last question: how i can calculate vm uptime? (if it possible)
Allocation is based on what is defined for the object during that hour. So, if a VM has 4 vcpus and 16GB memory, those are the allocation amounts. They would be derived from the values in vim_performance_states, which are snapshots of the state of the VM every hour. Additionally, there are columns in the metrics table, such as derived_memory_available, which is used for allocation calculations.
@gtanzillo @lpichler Can you keep me honest here ^?
how i can calculate vm uptime? (if it possible)
That one I'm not sure. I don't believe we store uptime from the provider, so collecting that would be an enhancement. We do have boot_time, but that's not exactly the same thing. We do also have when the power state changed (state_changed_on), so you could technically derive it from VMs that are powered on and seeing when the power on state last changed. @agrare do you know?
We are able to get boot_time from some providers (amazon, rhev, and vsphere) which will be more accurate than state_changed_on (state_changed_on is when we saved it, not when it actually started) but that will only give you the most recent uptime.
If you're trying to calculate e.g. how long has a vm been up over a period of time like a day, week, etc... you're best is probably to look at power state ems_events and sum the time between start and stop events within that time period.
So, I found a way. A fetch from consumption info about cpu_usage_average. If usage more than 0, I think that vm was powered on during 1 hour.
And use this info I can collect uptime per consumption period.
Also, I saw that consumption_rollup have a field power_status, but it always nil...
Also i wrote a method which calculate costs for dynamic allocated resources by uptime
If it make sense i can create pr
def dynamic_allocated_value(metric, sub_metric = nil)
uptime_index = ChargeableField.col_index('cpu_usage_rate_average')
case metric
when 'derived_vm_numvcpus', 'derived_memory_available'
@rollup_array.map do |rollup|
rollup[uptime_index].nil? ? 0.0 : rollup[ChargeableField.col_index(metric)]
end.compact.sum / consumed_hours_in_interval
else
avg(metric, sub_metric)
end
end
Depending on how accurate you need the uptime calculation to be that should work. A VM could have been on for 1 minute of that 1 hour rollup and it will be counted as on for that whole hour.
Not sure if you have access to the realtime metric datapoints from there, but those are a 20s resolution and thus cut this error down dramatically.
A VM could have been on for 1 minute of that 1 hour rollup and it will be counted as on for that whole hour.
I think it's an acceptable accuracy (other cloud providers have the same way for calculating)
@agrare @Fryguy guys, it make sense to pr or no?
https://github.com/ManageIQ/manageiq/issues/21144#issuecomment-817131787
@ahrechushkin definitely create a PR, we can discuss there.
I'd still like to investigate other approaches for more accurate uptime calculations but if +/- 1hr is close enough that's better than not having as long as we document that.
Most helpful comment
I think it's an acceptable accuracy (other cloud providers have the same way for calculating)