javapingdom

Pingdom uptime calculation formula


I am trying to generate uptime report using pingdom apis.

I am using the following formula. But somehow the percentage is not exact as shown in their UI.

( ( number_of_days_in_the_months * 86400 ) / 100 ) * uptime_percentage = uptime_in_seconds

Am I doing anything wrong ?


Solution

  • Here is the correct way of doing this.

    Use summary.outage api to get the results and then do the following

     SummaryOutage summaryOutage = new ObjectMapper().readValue(response, SummaryOutage.class);
    
            double uptime = 0d;
            double downtime = 0d;
            double unknown = 0d;
    
            for(SummaryOutage.Summary.State state :summaryOutage.summary.states){
                if(state.status.equals("up")){
                    uptime =  uptime + (state.timeto - state.timefrom);
                }else if (state.status.equals("down")){
                    downtime  =  downtime + (state.timeto - state.timefrom);
                }else if (state.status.equals("unknown")){
                    unknown  =  unknown + (state.timeto - state.timefrom);
                }
    
            }
    
            double totalTime = uptime + downtime + unknown;
            if(totalTime > 0) {
    
                DecimalFormat decimalFormat = new DecimalFormat("#.00");
                String numberAsString = decimalFormat.format(100 *( (uptime + unknown) / totalTime));
    
                return numberAsString;
    
            }
    

    This works perfect for me. You can enhance the java code as per your expertise.

    Hope this is of help to someone.