mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-12-01 02:34:03 +00:00
feat: Add timeoutMs field
This commit is contained in:
parent
c3eef28443
commit
76ef46740a
5 changed files with 28 additions and 2 deletions
7
db/patch-add-timeout-ms-monitor.sql
Normal file
7
db/patch-add-timeout-ms-monitor.sql
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
-- You should not modify if this have pushed to Github, unless it does serious wrong with the db.
|
||||||
|
BEGIN TRANSACTION;
|
||||||
|
|
||||||
|
ALTER TABLE monitor
|
||||||
|
ADD timeout_ms INTEGER default 0 not null;
|
||||||
|
|
||||||
|
COMMIT;
|
|
@ -64,6 +64,7 @@ class Database {
|
||||||
"patch-add-other-auth.sql": { parents: [ "patch-monitor-basic-auth.sql" ] },
|
"patch-add-other-auth.sql": { parents: [ "patch-monitor-basic-auth.sql" ] },
|
||||||
"patch-add-radius-monitor.sql": true,
|
"patch-add-radius-monitor.sql": true,
|
||||||
"patch-monitor-add-resend-interval.sql": true,
|
"patch-monitor-add-resend-interval.sql": true,
|
||||||
|
"patch-add-timeout-ms-monitor.sql": true,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -77,6 +77,7 @@ class Monitor extends BeanModel {
|
||||||
weight: this.weight,
|
weight: this.weight,
|
||||||
active: this.active,
|
active: this.active,
|
||||||
type: this.type,
|
type: this.type,
|
||||||
|
timeoutMs: this.timeoutMs,
|
||||||
interval: this.interval,
|
interval: this.interval,
|
||||||
retryInterval: this.retryInterval,
|
retryInterval: this.retryInterval,
|
||||||
resendInterval: this.resendInterval,
|
resendInterval: this.resendInterval,
|
||||||
|
@ -252,7 +253,7 @@ class Monitor extends BeanModel {
|
||||||
url: this.url,
|
url: this.url,
|
||||||
method: (this.method || "get").toLowerCase(),
|
method: (this.method || "get").toLowerCase(),
|
||||||
...(this.body ? { data: JSON.parse(this.body) } : {}),
|
...(this.body ? { data: JSON.parse(this.body) } : {}),
|
||||||
timeout: this.interval * 1000 * 0.8,
|
timeout: this.timeoutMs,
|
||||||
headers: {
|
headers: {
|
||||||
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
|
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
|
||||||
"User-Agent": "Uptime-Kuma/" + version,
|
"User-Agent": "Uptime-Kuma/" + version,
|
||||||
|
@ -446,7 +447,7 @@ class Monitor extends BeanModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
let res = await axios.get(steamApiUrl, {
|
let res = await axios.get(steamApiUrl, {
|
||||||
timeout: this.interval * 1000 * 0.8,
|
timeout: this.timeoutMs,
|
||||||
headers: {
|
headers: {
|
||||||
"Accept": "*/*",
|
"Accept": "*/*",
|
||||||
"User-Agent": "Uptime-Kuma/" + version,
|
"User-Agent": "Uptime-Kuma/" + version,
|
||||||
|
|
|
@ -668,6 +668,7 @@ let needSetup = false;
|
||||||
bean.headers = monitor.headers;
|
bean.headers = monitor.headers;
|
||||||
bean.basic_auth_user = monitor.basic_auth_user;
|
bean.basic_auth_user = monitor.basic_auth_user;
|
||||||
bean.basic_auth_pass = monitor.basic_auth_pass;
|
bean.basic_auth_pass = monitor.basic_auth_pass;
|
||||||
|
bean.timeoutMs = monitor.timeoutMs;
|
||||||
bean.interval = monitor.interval;
|
bean.interval = monitor.interval;
|
||||||
bean.retryInterval = monitor.retryInterval;
|
bean.retryInterval = monitor.retryInterval;
|
||||||
bean.resendInterval = monitor.resendInterval;
|
bean.resendInterval = monitor.resendInterval;
|
||||||
|
@ -1254,6 +1255,7 @@ let needSetup = false;
|
||||||
|
|
||||||
// Define default values
|
// Define default values
|
||||||
let retryInterval = 0;
|
let retryInterval = 0;
|
||||||
|
let timeoutMs = monitorListData[i].interval * 1000 * 0.8; // previously hardcoded in monitor.js
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Only replace the default value with the backup file data for the specific version, where it appears the first time
|
Only replace the default value with the backup file data for the specific version, where it appears the first time
|
||||||
|
@ -1278,6 +1280,7 @@ let needSetup = false;
|
||||||
basic_auth_pass: monitorListData[i].basic_auth_pass,
|
basic_auth_pass: monitorListData[i].basic_auth_pass,
|
||||||
authWorkstation: monitorListData[i].authWorkstation,
|
authWorkstation: monitorListData[i].authWorkstation,
|
||||||
authDomain: monitorListData[i].authDomain,
|
authDomain: monitorListData[i].authDomain,
|
||||||
|
timeoutMs: timeoutMs,
|
||||||
interval: monitorListData[i].interval,
|
interval: monitorListData[i].interval,
|
||||||
retryInterval: retryInterval,
|
retryInterval: retryInterval,
|
||||||
resendInterval: monitorListData[i].resendInterval || 0,
|
resendInterval: monitorListData[i].resendInterval || 0,
|
||||||
|
|
|
@ -254,6 +254,11 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<!-- Interval -->
|
<!-- Interval -->
|
||||||
|
<div class="my-3">
|
||||||
|
<label for="timeoutMs" class="form-label">{{ $t("Heartbeat Timeout") }} ({{ $t("timeoutAfterMs", [ monitor.timeoutMs ]) }})</label>
|
||||||
|
<input id="timeoutMs" v-model="monitor.timeoutMs" type="number" class="form-control" required min="50" step="50">
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="my-3">
|
<div class="my-3">
|
||||||
<label for="interval" class="form-label">{{ $t("Heartbeat Interval") }} ({{ $t("checkEverySecond", [ monitor.interval ]) }})</label>
|
<label for="interval" class="form-label">{{ $t("Heartbeat Interval") }} ({{ $t("checkEverySecond", [ monitor.interval ]) }})</label>
|
||||||
<input id="interval" v-model="monitor.interval" type="number" class="form-control" required min="20" step="1">
|
<input id="interval" v-model="monitor.interval" type="number" class="form-control" required min="20" step="1">
|
||||||
|
@ -606,6 +611,10 @@ export default {
|
||||||
if (this.monitor.retryInterval === oldValue) {
|
if (this.monitor.retryInterval === oldValue) {
|
||||||
this.monitor.retryInterval = value;
|
this.monitor.retryInterval = value;
|
||||||
}
|
}
|
||||||
|
// keep timeoutMs below interval, minding the unit conversion
|
||||||
|
if (!this.monitor.timeoutMs || this.monitor.timeoutMs >= value * 1000) {
|
||||||
|
this.monitor.timeoutMs = value * 1000 * 0.8;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
"monitor.type"() {
|
"monitor.type"() {
|
||||||
|
@ -668,6 +677,7 @@ export default {
|
||||||
url: "https://",
|
url: "https://",
|
||||||
method: "GET",
|
method: "GET",
|
||||||
interval: 60,
|
interval: 60,
|
||||||
|
timeoutMs: this.interval * 1000 * 0.8, // previous default value
|
||||||
retryInterval: this.interval,
|
retryInterval: this.interval,
|
||||||
resendInterval: 0,
|
resendInterval: 0,
|
||||||
maxretries: 0,
|
maxretries: 0,
|
||||||
|
@ -711,6 +721,10 @@ export default {
|
||||||
if (this.monitor.retryInterval === 0) {
|
if (this.monitor.retryInterval === 0) {
|
||||||
this.monitor.retryInterval = this.monitor.interval;
|
this.monitor.retryInterval = this.monitor.interval;
|
||||||
}
|
}
|
||||||
|
// Handling for monitors that are missing timeoutMs
|
||||||
|
if (!this.monitor.timeoutMs) {
|
||||||
|
this.monitor.timeoutMs = this.monitor.interval * 1000 * 0.8;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
toast.error(res.msg);
|
toast.error(res.msg);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue