I wrote a service stability tool class for computing systems:
/** * * @ClassName StabilityCalculator * @author kanpiaoxue * @version 1.0 * @CreateTime 2018/01/15 21:20:06 * @Description Stability Calculator * * <pre> * System stability calculation formula (annual): * (100 - (failure minutes / total minutes of the year * 100)) % * (100 - (Failure minutes / (60 * 24 * 365) * 100)) % * (100 - (40 / 525600 * 100)) % = 99.992389649923896% * </pre> */ public class StabilityCalculator { private enum TimeUnit { YEAR(365), QUARTER(120), MONTH(31); private static final int MINUTES_OF_DAY = 60 * 24; private int days; private TimeUnit(int num) { this.days = num; } public int getMinutes() { return MINUTES_OF_DAY * days; } } public static void main(String[] args) { StabilityCalculator sc = new StabilityCalculator(); // The expected system stability that can be achieved in one year is: 99.99%, and the maximum time allowed for problems is: 52.56 minutes sc.calculateErrorTime(99.99D, TimeUnit.YEAR); // Expected system stability that can be achieved in one quarter: 99.99%, the maximum time allowed for problems is: 17.28 minutes sc.calculateErrorTime(99.99D, TimeUnit.QUARTER); System.out.println("=========================================="); // There is 40 minutes of system instability in a year, and the system stability that can be achieved is: 99.99% sc.calculateStabilityPercent(40, TimeUnit.YEAR); // There is 40 minutes of system instability in a quarter, and the system stability that can be achieved is: 99.98% sc.calculateStabilityPercent(40, TimeUnit.QUARTER); } /** * * @param expectedPercent expected stability percentage * @param timeUnit The time unit for statistics: year, quarter * @return the maximum system instability time (minutes) that can occur to achieve the desired stability percentage * @author kanpiaoxue * @CreateTime 2018/01/15 21:45:29 * @Description Calculates the maximum system instability time (minutes) that can occur based on the desired stability percentage */ public double calculateErrorTime(double expectedPercent, TimeUnit timeUnit) { double totalMinutes = timeUnit.getMinutes(); double minutes = (100D - expectedPercent) / 100D * totalMinutes; System.out.println(String.format("[%s] expectedPercent:%s, the least required minutes:%s minutes", timeUnit, expectedPercent, minutes)); return minutes; } /** * * @param errorDuration The duration of system instability (minutes) * @param timeUnit The time unit for statistics: year, quarter * @return desired stability percentage * @author kanpiaoxue * @CreateTime 2018/01/15 21:45:32 * @Description Calculates the current system stability percentage based on the duration (minutes) of system instability */ public double calculateStabilityPercent(int errorDuration, TimeUnit timeUnit) { double totalMinutes = timeUnit.getMinutes(); double expectedPercent = (100D - (errorDuration / totalMinutes * 100D)); System.out.println(String.format("[%s] errorDuration:%s minutes, stability percent:%s", timeUnit, errorDuration, expectedPercent)); return expectedPercent; } }