How to create a Performance Analytics breakdown by CI Class

mitzaka
Mega Guru

Hey SNC, I came upon the case the other day where I needed a breakdown by the CI Class on Configuration Items in PA. Therefore I decided to share how I solved this case:

1. create a new manual breakdown, in my case called 'CI.Class'. Leave 'display' unchecked. Once you save it, copy the sys_id of that manual breakdown and write it down somewhere (you are going to need it a bit later)

2. create a Scheduled Job, which in my case I set up to run daily and is called 'CI Classes Collection'. Enter the following script in the scheduled job script section:

//get the Configuration Item table and the Class column from it:

var table = 'cmdb_ci';

var col = 'sys_class_name';

var breakdown = '<sysid of the manual breakdown you were supposed to remember in step 1>';

gs.log('Collection of CI Classes started');

//do not modify:

(function(table, col, breakdown) {

  var ga = new GlideAggregate(table);

  ga.addAggregate('COUNT', col);

  ga.query();

  while(ga.next()) {

  var value = ga.getDisplayValue(col);

  var gr = new GlideRecord('pa_manual_breakdowns');

  gr.addQuery('breakdown', breakdown);

  gr.addQuery('value', value);

  gr.query();

  if(!gr.next()) {

  gr = new GlideRecord('pa_manual_breakdowns');

  gr.initialize();

  gr.setValue('breakdown', breakdown);

  gr.setValue('value', value);

  gr.insert();

  gr.close();

  }

  }

  ga.close();

  gs.log('Collection of CI Classes finished');

}) (table, col, breakdown);

3. make sure you choose a time for the scheduled job to run before the scores collection of performance analytics (in my case two PA Jobs to fetch information from cmdb_ci table - daily and historically. Then hit Execute on the Scheduled Job 'CI Classes Collection' to fill the breakdown the first time. Check your manual breakdown if all elements have been added - by going to PA>Breakdowns>Manual Breakdowns and checking the 'CI.Class' breakdown. You should see a list of collected CI Classes (below is what I see in my setup)

Screen Shot 2017-07-04 at 10.20.45 AM.png

4. create a breakdown source that uses the manual breakdown as a source.   Go to PA > Breakdown Sources and click 'New'. As source use the facts table pa_manual_breakdown and set the field to sys_id. Create a condition: breakdown is 'CI.Class' (in my case below - 47 classes collected)

Screen Shot 2017-07-04 at 10.24.35 AM.png

5. create a PA script to associate every record with the breakdown elements. Go to PA>Automation>Scripts and click 'New'. Enter the name (in my case 'CI.Class'), then for the 'Facts Table' choose 'cmdb_ci', and for the 'Fields' choose 'Class (sys_class_name)'. In the script section enter the following script:

var breakdown = '<sysid of the manual breakdown you were supposed to remember in step 1>';

var value = current.sys_class_name.getDisplayValue();

//do not modify:

var sysID = '';

if (value && value!= '') {

  var gr = new GlideRecord('pa_manual_breakdowns');

  gr.addQuery('breakdown', breakdown);

  gr.addQuery('value', value);

  gr.query();

  if(gr.next()) {

  sysID = gr.getValue('sys_id');

  }

}

sysID || '';

6. create an automated breakdown which will use the script you created. Go to PA>Breakdowns>Automated Breakdowns and click 'New'. Give it a name (in my case 'CI Class' and give it a breakdown source that you created in step 4: 'CI Classes'. Save and then create the breakdown mappings - for the 'Facts Table' choose 'Configuration Item' and select the option 'scripted', then select the script you created in step 5 'CI.Class'.

Screen Shot 2017-07-04 at 10.34.02 AM.png

Mission accomplished. You now have an automated breakdown which will feed daily from the manual breakdown and the scheduled job you created.

Enjoy!

3 REPLIES 3

Arnoud Kooi
ServiceNow Employee
ServiceNow Employee

Thanks, this seems a use-case without the risk of ending up with unstructured data!



To structure things a bit, you could move the logic of step two to a script include and call it from the condition field of the PA job.


This integrates it in one Job and removes the timing dependency between the Scheduled Job and the PA Job.



Something like:


find_real_file.png


Kumar38
Kilo Sage

can i add breakdown scores of 2 different indicators using formula indicators ?

Serkan Yilmaz
Tera Expert

Hi all,

 

There is a trigger to create automatically a Breakdown Source when you create a Manual Breakdown. That means step 4 is not applicable anymore.

 

Secondly the Breakdown source selection for an Automated Breakdown is restricted, so it's not possible to select a Breakdown Source connected to a Manual Breakdown (see ref. qualifier) of the Breakdown Source field.

Use therefore the following background script to create the Automated Breakdown with a link to your Breakdown source:

var tbl = 'pa_breakdowns';
var name = 'NAME OF THE AUTOMATED BREAKDOWN'; //
var breakdownSource = 'SYS ID OF THE BREAKDOWN SOURCE'; //Sys id of the Breakdown source linked to the Manual breakdown

var grBS = new GlideRecord(tbl);
    grBS.initialize();
    grBS.setValue('type',1); //1 is Automated
    grBS.setValue('name', name);
    grBS.setValue('dimension'breakdownSource);
    gs.print(grBS.insert()); //Print the sys_id of the created Automated Breakdown
 
Cheers,
 
Serkan