mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-07-21 14:08:53 -04:00
add ping and fix uptime
This commit is contained in:
parent
9c653c3d05
commit
a6b5986dd6
9 changed files with 285 additions and 97 deletions
|
@ -1,4 +1,5 @@
|
|||
const tcpp = require('tcp-ping');
|
||||
const Ping = require("./ping-lite");
|
||||
|
||||
exports.tcping = function (hostname, port) {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
@ -20,3 +21,19 @@ exports.tcping = function (hostname, port) {
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
exports.ping = function (hostname) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const ping = new Ping(hostname);
|
||||
|
||||
ping.send(function(err, ms) {
|
||||
if (err) {
|
||||
reject(err)
|
||||
} else if (ms === null) {
|
||||
reject(new Error("timeout"))
|
||||
} else {
|
||||
resolve(Math.round(ms))
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue