forked from KaylieB/paycalculator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
285 lines (247 loc) · 11.1 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Check Frequency Calculator</title>
<link href="StyleSheet.css" rel="stylesheet">
</head>
<body>
<center><img src="checkly-logo-dark.svg" alt="Checkly logo"></center>
<h1>Check Frequency Calculator</h1>
<div class="container">
<div class="form-content">
<!-- Input Panel -->
<div class="formstyle">
<form onsubmit="return false;" name="form1">
<!-- Metric input section -->
<div class="input-section">
<!-- SLA Level -->
<div class="entry">
<label class="entry-label">SLA Level</label>
<small class="description">Target service uptime percentage</small>
<div class="input-group">
<input type="text" id="sla-level" name="sla-level" value="">
<span class="unit">%</span>
</div>
</div>
<!-- Incidents -->
<div class="entry">
<label class="entry-label">Incidents</label>
<small class="description">Estimated amount of incidents - default: 1</small>
<div class="input-group">
<input type="text" id="incidents" name="incidents">
<span class="unit">per month</span>
</div>
</div>
<!-- Time to Recovery -->
<div class="entry">
<label class="entry-label">Time to Recovery</label>
<small class="description">Estimated time to resolve an incident</small>
<div class="input-group">
<input type="text" id="ttr" name="ttr" value="">
<span class="unit">minute(s)</span>
</div>
</div>
<!-- Time to Detect -->
<div class="entry">
<label class="entry-label">Time to Detect</label>
<small class="description">Maximum TTD equaling check frequency</small>
<div class="input-group">
<input type="text" id="ttd" name="ttd" value="">
<span class="unit">minute(s)</span>
</div>
</div>
</div>
</form>
</div>
<!-- Result Panel -->
<div class="highlight-section">
<!-- Error Budget -->
<h2>Error Budget</h2>
<small class="description">Remaining downtime allowance per month</small>
<div class="frequency-result">
<span id="error-budget">0 min</span>
</div>
<!-- Check Frequency -->
<h2>Check Frequency</h2>
<small class="description">Based on provided TTD</small>
<div class="frequency-result">
<span id="check-frequency">0 min</span>
</div>
<!-- Available Check Frequencies -->
<div class="available-frequencies">
<div class="frequency-item" id="frequency-recommendation">
</div>
</div>
</div>
</div>
</div>
<!-- JavaScript Code -->
<script>
const apiFrequencies = [
10, 20, 30, 60, 120, 300, 600, 900,
1800, 3600, 7200, 10800, 21600, 43200, 86400
];
const browserFrequencies = [
60, 120, 300, 600, 900, 1800,
3600, 7200, 10800, 21600, 43200, 86400
];
function formatDuration(totalMinutes) {
if (isNaN(totalMinutes)) return "0 min";
let isNegative = totalMinutes < 0;
totalMinutes = Math.abs(totalMinutes);
let totalSeconds = Math.round(totalMinutes * 60);
const days = Math.floor(totalSeconds / (24 * 3600));
totalSeconds %= 24 * 3600;
const hours = Math.floor(totalSeconds / 3600);
totalSeconds %= 3600;
const minutes = Math.floor(totalSeconds / 60);
const seconds = totalSeconds % 60;
let parts = [];
if (days > 0) parts.push(`${days}d`);
if (hours > 0) parts.push(`${hours}h`);
if (minutes > 0) parts.push(`${minutes}m`);
if (seconds > 0) parts.push(`${seconds}s`);
if (parts.length === 0) {
parts.push("0 min");
}
let formattedDuration = parts.join(' ');
if (isNegative) {
formattedDuration = `-${formattedDuration}`;
}
return formattedDuration;
}
function formatFrequency(seconds) {
if (seconds < 60) {
return `${seconds} sec`;
} else if (seconds < 3600) {
const minutes = seconds / 60;
return `${minutes % 1 === 0 ? minutes : minutes.toFixed(1)} min`;
} else {
const hours = seconds / 3600;
return `${hours % 1 === 0 ? hours : hours.toFixed(1)} hr`;
}
}
function getNextAvailableFrequency(calculatedFrequencyInSeconds, frequenciesArray) {
let availableFrequencies = frequenciesArray.filter(freq => freq <= calculatedFrequencyInSeconds);
if (availableFrequencies.length === 0) {
return null;
}
return Math.max(...availableFrequencies);
}
function calculate() {
let slaLevel = parseFloat(document.getElementById('sla-level').value);
let incidentsInput = document.getElementById('incidents').value;
let ttr = parseFloat(document.getElementById('ttr').value);
let ttd = parseFloat(document.getElementById('ttd').value);
const totalMinutesPerMonth = 30 * 24 * 60;
let errorBudget = 0;
let checkFrequency = ttd;
let formattedApiFrequency = 'N/A';
let formattedBrowserFrequency = 'N/A';
let formattedCheckFrequency = 'N/A';
if (!isNaN(slaLevel) && slaLevel > 0 && slaLevel < 100) {
const initialErrorBudget = ((100 - slaLevel) / 100) * totalMinutesPerMonth;
let incidents = parseInt(incidentsInput);
if (incidentsInput.trim() === '') {
incidents = 1;
} else if (isNaN(incidents) || incidents <= 0) {
incidents = 1;
}
if (isNaN(ttr) || ttr < 0) ttr = 0;
if (isNaN(ttd) || ttd < 0) ttd = 0;
// Calculate the error budget
errorBudget = initialErrorBudget - incidents * (ttr + ttd);
// Handle NaN for checkFrequency
if (isNaN(checkFrequency) || checkFrequency <= 0) {
formattedCheckFrequency = 'N/A';
} else {
formattedCheckFrequency = `${checkFrequency % 1 === 0 ? checkFrequency : checkFrequency.toFixed(2)} min`;
}
if (errorBudget < 0) {
// Calculate minimum TTD required to bring error budget to zero
let minTTD = (initialErrorBudget / incidents) - ttr;
if (minTTD <= 0) {
// Impossible to achieve non-negative error budget
formattedApiFrequency = 'N/A';
formattedBrowserFrequency = 'N/A';
document.getElementById('frequency-recommendation').innerHTML = `
<strong>Error Budget Exceeded</strong><br>
`;
} else {
let minTTDInSeconds = minTTD * 60;
// For API checks
let apiFrequencyInSeconds = getNextAvailableFrequency(minTTDInSeconds, apiFrequencies);
if (apiFrequencyInSeconds !== null) {
formattedApiFrequency = formatFrequency(apiFrequencyInSeconds);
} else {
formattedApiFrequency = 'N/A';
}
// For Browser checks
let browserFrequencyInSeconds = getNextAvailableFrequency(minTTDInSeconds, browserFrequencies);
if (browserFrequencyInSeconds !== null) {
formattedBrowserFrequency = formatFrequency(browserFrequencyInSeconds);
} else {
formattedBrowserFrequency = 'N/A';
}
// Provide recommendations without changing the checkFrequency
document.getElementById('frequency-recommendation').innerHTML = `
<strong>Recommended Check Frequencies</strong><br>
Checkly API check: ${formattedApiFrequency}<br>
Checkly Browser check: ${formattedBrowserFrequency}
`;
}
} else {
// Error budget is positive
let checkFrequencyInSeconds = checkFrequency * 60;
let apiFrequencyInSeconds = getNextAvailableFrequency(checkFrequencyInSeconds, apiFrequencies);
if (apiFrequencyInSeconds !== null) {
formattedApiFrequency = formatFrequency(apiFrequencyInSeconds);
} else {
formattedApiFrequency = 'N/A';
}
let browserFrequencyInSeconds = getNextAvailableFrequency(checkFrequencyInSeconds, browserFrequencies);
if (browserFrequencyInSeconds !== null) {
formattedBrowserFrequency = formatFrequency(browserFrequencyInSeconds);
} else {
formattedBrowserFrequency = 'N/A';
}
// Display the frequencies
document.getElementById('frequency-recommendation').innerHTML = `
<strong>Recommended Check Frequencies</strong><br>
Checkly API check: ${formattedApiFrequency}<br>
Checkly browser check: ${formattedBrowserFrequency}
`;
}
} else {
// Invalid SLA level
errorBudget = 0;
formattedCheckFrequency = 'N/A';
formattedApiFrequency = 'N/A';
formattedBrowserFrequency = 'N/A';
document.getElementById('frequency-recommendation').innerHTML = `
Please enter a valid SLA level
`;
}
const formattedErrorBudget = formatDuration(errorBudget);
// Display the results
const errorBudgetElement = document.getElementById('error-budget');
errorBudgetElement.innerText = formattedErrorBudget;
if (errorBudget < 0) {
errorBudgetElement.classList.add('negative-budget');
} else {
errorBudgetElement.classList.remove('negative-budget');
}
document.getElementById('check-frequency').innerText = formattedCheckFrequency;
}
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('sla-level').addEventListener('input', calculate);
document.getElementById('incidents').addEventListener('input', calculate);
document.getElementById('ttr').addEventListener('input', calculate);
document.getElementById('ttd').addEventListener('input', calculate);
calculate();
});
</script>
</body>
</html>