/
index.ts
38 lines (33 loc) · 1001 Bytes
/
index.ts
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
#!/usr/bin/env node
import * as isoly from "isoly"
import { default as fetch } from "node-fetch"
import { performance } from "perf_hooks"
const argument = process.argv.slice(2)
let interval = Number.parseInt(argument[0])
if (interval == Number.NaN)
interval = 3600
else
argument.shift()
const endpoints = argument
if (endpoints.length == 0)
console.error("usage: uply <intervall in ms> <url 1> <url 2>\nexample: uply 1000 https://google.com https://dn.se")
else {
console.error("starting")
console.log(["started", ...endpoints].join(","))
const timer = setInterval(async () => {
const started = isoly.DateTime.now()
const start = performance.now()
const responses = await Promise.all(
endpoints.map(async url => {
const response = await fetch(url)
await response.text()
return performance.now() - start
})
)
console.log([started, ...responses].join(","))
}, interval)
process.once("SIGINT", _ => {
clearInterval(timer)
console.error("shutting down")
})
}