dowwntime 1.3.0 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.mjs +30 -26
- package/dist/cli.mjs.map +1 -1
- package/dist/index.mjs +30 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -14888,14 +14888,16 @@ const measureRequest = async (url$2, options) => {
|
|
|
14888
14888
|
const startAt = Date.now();
|
|
14889
14889
|
return await new Promise((resolve$1) => {
|
|
14890
14890
|
let tlsHandshakeAt;
|
|
14891
|
+
let firstByteAt;
|
|
14891
14892
|
const req = ((typeof url$2 === "string" ? new URL(url$2) : url$2).protocol === "https:" ? https : http).request(url$2, options, (res) => {
|
|
14892
|
-
res.on("data", () => {
|
|
14893
|
+
res.on("data", () => {
|
|
14894
|
+
if (!firstByteAt) firstByteAt = Date.now();
|
|
14895
|
+
});
|
|
14893
14896
|
res.on("end", () => {
|
|
14894
|
-
const
|
|
14895
|
-
const tlsMs = tlsHandshakeAt ? tlsHandshakeAt - startAt : 0;
|
|
14897
|
+
const durationMs = (firstByteAt ? firstByteAt - startAt : 0) - (tlsHandshakeAt ? tlsHandshakeAt - startAt : 0);
|
|
14896
14898
|
resolve$1({
|
|
14897
14899
|
statusCode: res.statusCode || 0,
|
|
14898
|
-
durationMs:
|
|
14900
|
+
durationMs: Math.max(0, durationMs)
|
|
14899
14901
|
});
|
|
14900
14902
|
});
|
|
14901
14903
|
});
|
|
@@ -28346,29 +28348,26 @@ const run = async (options) => {
|
|
|
28346
28348
|
const measure = async (path$4) => {
|
|
28347
28349
|
const url$2 = fetchConfigurations.get(path$4);
|
|
28348
28350
|
if (!url$2) return;
|
|
28349
|
-
let status = "down";
|
|
28350
|
-
let durationMs;
|
|
28351
28351
|
const start = Date.now();
|
|
28352
28352
|
try {
|
|
28353
28353
|
const metrics = await measureRequest(url$2, {
|
|
28354
28354
|
method: "GET",
|
|
28355
28355
|
timeout: options.timeoutMs ?? 5e3
|
|
28356
28356
|
});
|
|
28357
|
-
|
|
28358
|
-
|
|
28359
|
-
|
|
28357
|
+
debug$1(`Measured ${path$4}:`, metrics);
|
|
28358
|
+
return {
|
|
28359
|
+
...metrics,
|
|
28360
|
+
url: url$2.toString(),
|
|
28361
|
+
timestamp: start
|
|
28362
|
+
};
|
|
28360
28363
|
} catch (_error) {
|
|
28361
|
-
|
|
28362
|
-
|
|
28364
|
+
return {
|
|
28365
|
+
statusCode: 0,
|
|
28366
|
+
durationMs: Date.now() - start,
|
|
28367
|
+
url: url$2.toString(),
|
|
28368
|
+
timestamp: start
|
|
28369
|
+
};
|
|
28363
28370
|
}
|
|
28364
|
-
const measurement = {
|
|
28365
|
-
status,
|
|
28366
|
-
durationMs,
|
|
28367
|
-
timestamp: start,
|
|
28368
|
-
url: url$2.toString()
|
|
28369
|
-
};
|
|
28370
|
-
debug$1(`Measured ${path$4}:`, measurement);
|
|
28371
|
-
return measurement;
|
|
28372
28371
|
};
|
|
28373
28372
|
const throttledMeasure = pThrottle({
|
|
28374
28373
|
limit: options.concurrency ?? 5,
|
|
@@ -28382,13 +28381,18 @@ const run = async (options) => {
|
|
|
28382
28381
|
const iqr = q3 - q1;
|
|
28383
28382
|
const lowerBound = q1 - 1.5 * iqr;
|
|
28384
28383
|
const upperBound = q3 + 1.5 * iqr;
|
|
28385
|
-
const
|
|
28386
|
-
|
|
28387
|
-
|
|
28388
|
-
|
|
28389
|
-
|
|
28390
|
-
|
|
28391
|
-
|
|
28384
|
+
const filteredResults = results.filter((r) => r && r.durationMs >= lowerBound && r.durationMs <= upperBound);
|
|
28385
|
+
const durationMs = Math.round(filteredResults.reduce((acc, curr) => acc + (curr?.durationMs ?? 0), 0) / filteredResults.length);
|
|
28386
|
+
let status = "down";
|
|
28387
|
+
const statusCode = Math.max(...filteredResults.map((r) => r?.statusCode ?? 0));
|
|
28388
|
+
if (options.getStatus) status = options.getStatus(statusCode, path$4, durationMs);
|
|
28389
|
+
else status = statusCode >= 200 ? "up" : "down";
|
|
28390
|
+
const measurement = {
|
|
28391
|
+
status,
|
|
28392
|
+
durationMs,
|
|
28393
|
+
timestamp: Date.now(),
|
|
28394
|
+
url: fetchConfigurations.get(path$4)?.toString() ?? ""
|
|
28395
|
+
};
|
|
28392
28396
|
debug$1(`Measured ${path$4} (avg):`, measurement);
|
|
28393
28397
|
if (!measurement) return;
|
|
28394
28398
|
await measurements.add(path$4, measurement);
|