performance analytics

Ragavi
Tera Contributor

Hi,

Indicator source - cmdb_ci_outage table 

indicator with breakdown on cmdb_ci_business_app

job with relative start 10 days ago and relative end 0 days ago .

Aim is to find out downtime of an application for a day . Consider an application A had an outage with begin date oct 4th 2024 1pm and end date oct 6th 2024 5pm .I need output as below 

oct 4th -11 hrs

oct 5th -24 hrs

oct 6th - 17 hrs 

So in indicator source I have used PA scripts as below 

var diff = function(x, y)

        {
           return y.dateNumericValue() - x.dateNumericValue();
        };
var minutes = function(x, y) {
return diff(x, y) / (60 * 1000);
};
var allDay = function() {
  return 60 * 24;
};
var isToday = function(x) {
    var gdt = new GlideDateTime(x);
    var today = new GlideDateTime();
    return gdt.getLocalDate().getValue() == today.getLocalDate().getValue();
    //     today.setNumericValue(score_start.dateNumericValue());  
    //return gdt.getDate().getValue() == today.getDate().getValue();
};

if (isToday(current.begin) && isToday(current.end)) {
    minutes(current.begin, current.end);
} else if (isToday(current.begin)) {
    minutes(current.begin, score_end);
} else if (isToday(current.end)) {
    minutes(score_start, current.end);
} else {
    allDay();
}
Here whenever I run historic job my current date is calculated as the date when I run that job manually and only else condition got executed .GlideDateTime is not considering the relative date from pa job . Please advise .

 

Thanks,

Ragavi

1 ACCEPTED SOLUTION

Aniket Chavan
Tera Sage
Tera Sage

Hello @Ragavi ,

It sounds like you're aiming to calculate the daily downtime for an application based on the outage period. To do this, you’ll need to adjust your script to account for the dates within the PA job’s relative date range, instead of relying on the system date. This will help you get accurate calculations for each specific day in your range.|

So please try with the updated script below and see how it works for you.

var diff = function(x, y) {
    return y.dateNumericValue() - x.dateNumericValue();
};
var minutes = function(x, y) {
    return diff(x, y) / (60 * 1000); // Convert difference to minutes
};
var allDay = function() {
    return 60 * 24; // Minutes in a full day
};

// Get the relative current date from the PA job
var currentDate = new GlideDateTime(score_start);
currentDate.setDisplayValue(score_start.getDisplayValue());

// Define the start and end times for the event
var begin = new GlideDateTime(current.begin);
var end = new GlideDateTime(current.end);

if (currentDate.getLocalDate().getValue() == begin.getLocalDate().getValue()) {
    // If the event starts on the current date
    return minutes(begin, GlideDateTime(score_end));
} else if (currentDate.getLocalDate().getValue() == end.getLocalDate().getValue()) {
    // If the event ends on the current date
    return minutes(score_start, end);
} else if (currentDate.getLocalDate().getValue() > begin.getLocalDate().getValue() &&
           currentDate.getLocalDate().getValue() < end.getLocalDate().getValue()) {
    // Full downtime if the current date is between the begin and end dates
    return allDay();
} else {
    // No downtime for dates outside the range
    return 0;
}

 

This script:

  • Calculates the minutes of downtime based on the start and end of each day within the relative date range of your PA job.
  • Accounts for whether the event falls at the beginning, end, or completely covers the date in question.

This should provide the output you’re looking for with the downtime hours per day as specified. Give this a try and let me know how it works out, or if you need any further help!

Please Mark āœ…Correct if this solves your query and also mark šŸ‘Helpful if you find my response worthy based on the impact.


Regards,
Aniket

View solution in original post

1 REPLY 1

Aniket Chavan
Tera Sage
Tera Sage

Hello @Ragavi ,

It sounds like you're aiming to calculate the daily downtime for an application based on the outage period. To do this, you’ll need to adjust your script to account for the dates within the PA job’s relative date range, instead of relying on the system date. This will help you get accurate calculations for each specific day in your range.|

So please try with the updated script below and see how it works for you.

var diff = function(x, y) {
    return y.dateNumericValue() - x.dateNumericValue();
};
var minutes = function(x, y) {
    return diff(x, y) / (60 * 1000); // Convert difference to minutes
};
var allDay = function() {
    return 60 * 24; // Minutes in a full day
};

// Get the relative current date from the PA job
var currentDate = new GlideDateTime(score_start);
currentDate.setDisplayValue(score_start.getDisplayValue());

// Define the start and end times for the event
var begin = new GlideDateTime(current.begin);
var end = new GlideDateTime(current.end);

if (currentDate.getLocalDate().getValue() == begin.getLocalDate().getValue()) {
    // If the event starts on the current date
    return minutes(begin, GlideDateTime(score_end));
} else if (currentDate.getLocalDate().getValue() == end.getLocalDate().getValue()) {
    // If the event ends on the current date
    return minutes(score_start, end);
} else if (currentDate.getLocalDate().getValue() > begin.getLocalDate().getValue() &&
           currentDate.getLocalDate().getValue() < end.getLocalDate().getValue()) {
    // Full downtime if the current date is between the begin and end dates
    return allDay();
} else {
    // No downtime for dates outside the range
    return 0;
}

 

This script:

  • Calculates the minutes of downtime based on the start and end of each day within the relative date range of your PA job.
  • Accounts for whether the event falls at the beginning, end, or completely covers the date in question.

This should provide the output you’re looking for with the downtime hours per day as specified. Give this a try and let me know how it works out, or if you need any further help!

Please Mark āœ…Correct if this solves your query and also mark šŸ‘Helpful if you find my response worthy based on the impact.


Regards,
Aniket