Average processing time for service Catalog Items
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2011 07:42 AM
we have a requirement to find the Average processing time for each Service Catalog Items.
I have created a Metric Definition to calculate the duration on SC_REQ_ITEM table.
Has anyone calculated Avg Processing time based on Requested Items? Thanks for your help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2011 01:52 PM
Could you please elaborate on what you mean with processing time?
Looking at the out of the box list, you can either choose to make a metric based on state, or a metric based on stage. This means that you would probably like to measure the amount of time after approval, until the state is either 3 (closed completed), 4 (closed incomplete) or 7 (closed skipped).
Create a metric with a script calculated value, with the following script in that field:
if(current.approval == 'approved'){
createMetric(current.state);
}
function createMetric(value) {
if(value == 3 || value == 4 || value == 7){
var mi = new MetricInstance(definition, current);
if (mi.metricExists())
return;
var gr = mi.getNewRecord();
gr.field_value = gs.dateDiff(current.approval_set.getDisplayValue(),gs.nowDateTime(),true);
gr.field = null;
gr.calculation_complete = true;
gr.insert();
}
}
NOTE: For stage you should be listing the value differently, according to the stage field. State would probably be better as it is clear what the values are, and is processed simultaneously.
When this is done, every time a request item enters a 'Closed state', a metric_instance is created with a nice field_value indicating the processing time in seconds from the moment the approval was set, to the moment your close conditions are met.
To get the average processing time of all the requests, depending on where you want to show it, you need to process the values of all the metrics again.
You can do this by creating another (meta) metric or by just creating a business rule, that stores the value in a property for instance. The following script calculates the average time in seconds across all requested items:
var tot = 0; // Processing time is stored as seconds.
var avg;
var gt = new GlideRecord('metric_instance');
gt.addQuery('number', 'MTRC0010003'); // this is the number of the metric we just created.
gt.addQuery('calculation_complete',true); // make sure the metric is done calculating
gt.query();
var am = gt.getRowCount(); //To know the divisor.
if(am > 0){
while(gt.next()){
tot += parseInt(gt.field_value, 10); // Add all seconds together
}
avg = tot / am; //Divide total seconds to the divisor, the number of applicable metrics
}
var avgTimeInRoundDownSeconds = Math.floor(avg);
Since the metric updates every time, you might want to consider setting up an interval for calculating and updating the average time, but that completely depends on the requirement. You could perhaps create some widget or monitoring gadget that shows the value and triggers an update every 15 minutes or something. Completely depends on what you want to do with it.
Hope it helped.
Regards,
Wesley
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2015 04:23 AM
Hello Wesley,
we have a requirement to calculate the duration of request items. I created a metric definition for that as you suggested above, it worked fine. we are able to calculate the duration of request items for newly created requests only. It is the actual behavior I know that, but the customer wants duration to be calculated for historic request items also. pls help me out