This post is more than 5 years old
23 Posts
0
145713
November 1st, 2012 16:00
VM Growth Over Past N Days Derived Metric
Looking for some assistance in creating a derived metric that would take a point in time metric from say 6 months ago, "poweredOnVMCount", subtract it from the current "poweredOnVMCount" and divided it by the number of days between the two metrics effectively providing the daily growth. Any assistance would be appreciated.
Thanks,
Joshua


DELL-Brian W
59 Posts
1
November 27th, 2012 20:00
You can use a replace a variable in the String using '$', e.g. $numdays.
Try something like this (scope is a VMWCluster):
then = null
numdays = 180
while (then == null) {
try {
String query = "virtualMachinesPoweredOnCount from VMWCluster:name = '$scope.name' for 1 day $numdays days ago"
then = max(server.QueryService.queryObservations(query))
}
catch (Exception e) {}
numdays--
}
'' + numdays++ + ' days ago there were ' + then + ' VMs powered on'
My result:
56 days ago there were 3.0 VMs powered on
Regards,
Brian Wheeldon
DELL-Thomas B
171 Posts
0
November 2nd, 2012 03:00
Of course now that I think about it,being late and all, I should finish it off...
ds = server.get("DataService") // Data Service
qs = server.get("QueryService") // Query Service
String query = "virtualMachinesPoweredOnCount from VMWCluster : name like '$scope.name' for 1 day 180 days ago" // Get all values from 1 day from 180 days ago
then = max(qs.queryObservations(query)) // Retrieves the max value over the time range above
now = ds.retrieveLatestValue(scope, "virtualMachinesPoweredOnCount").getValue().avg // Retrieves the current value
growthRate = ( (now - then) / 180 ) // Calculate current growth rate
return growthRate // Returns the growth rate
DELL-Thomas B
171 Posts
0
November 2nd, 2012 03:00
Here is an example for one at the cluster level that would look for the max value over a day from 6 months ago. You could change it to look at say a 4 hour chunk, you need at least that for the default retention period, so you get data returned, or change to avg or min vs. I have max in there right now.
qs = server.get("QueryService") // Query Service
String query = "virtualMachinesPoweredOnCount from VMWCluster : name like '$scope.name' for 1 day 6 months ago"
max(qs.queryObservations(query))
jingo5star
23 Posts
0
November 27th, 2012 14:00
Nice script Thomas, I am able to quickly find a 30 day growth rate and manipulate the data where needed. The only issue that I am running into is if for some reason that particular day does not have any data for the cluster. Such as adding a new cluster into the environment with it being only days old versus a cluster that is months/years old and would have data.
I thought about doing a while loop a counting down the number of days but it appears I am not able to use a variable in the query where it say "for 1 day 180 days ago"
Sample while loop I was trying to get working:
numdays = 180
then = null
while (then == null) {
String query = "virtualMachinesPoweredOnCount from VMWCluster : name like '$scope.name' for 1 day numdays days ago" // Get all values from 1 day from 180 days ago
then = max(qs.queryObservations(query)) // Retrieves the max value over the time range above
numdays--
}
Thoughts on how to get around this?
Thanks,
Joshua
jingo5star
23 Posts
0
November 28th, 2012 17:00
That would be a tremendous benefit to the community to not have to recreate the same scripts or even to drive customers to utilize the product in ways they may not have envinsioned out of the box.
DELL-Thomas B
171 Posts
0
November 28th, 2012 17:00
Not one that I know of on the community site. I keep a copy of all of the ones I can find on the forums for ths most part, so I have things to reference in the future. We could make a little code house of sorts for these things.
jingo5star
23 Posts
0
November 28th, 2012 17:00
This is great, thank you for following up and the script. I did have to add if (then >= 0){break} numdays-- to prevent the number of days from reporting as 1 day less than what it really was. Is there a script repository that patrons of the community can share and review?
ckitchens1
1 Message
0
January 8th, 2013 16:00
I wouldl ike to use this script for some custom reporting. Where/How do I put this script into Vfoglight 6.7?
Thanks.
jingo5star
23 Posts
0
January 8th, 2013 18:00
Chris,
The way I did it was add it as a Derived Metric. You would take the entire script and paste it into the derived metric calculation with the Scope being a VMWCluster. Once successfully added you can start producing reports with the newly created derived metric.