@ -3,7 +3,7 @@ const dayjs = require("dayjs");
const axios = require ( "axios" ) ;
const axios = require ( "axios" ) ;
const { Prometheus } = require ( "../prometheus" ) ;
const { Prometheus } = require ( "../prometheus" ) ;
const { log , UP , DOWN , PENDING , MAINTENANCE , flipStatus , MAX _INTERVAL _SECOND , MIN _INTERVAL _SECOND ,
const { log , UP , DOWN , PENDING , MAINTENANCE , flipStatus , MAX _INTERVAL _SECOND , MIN _INTERVAL _SECOND ,
SQL _DATETIME _FORMAT , isDev , sleep , getRandomInt
SQL _DATETIME _FORMAT
} = require ( "../../src/util" ) ;
} = require ( "../../src/util" ) ;
const { tcping , ping , checkCertificate , checkStatusCode , getTotalClientInRoom , setting , mssqlQuery , postgresQuery , mysqlQuery , mqttAsync , setSetting , httpNtlm , radius , grpcQuery ,
const { tcping , ping , checkCertificate , checkStatusCode , getTotalClientInRoom , setting , mssqlQuery , postgresQuery , mysqlQuery , mqttAsync , setSetting , httpNtlm , radius , grpcQuery ,
redisPingAsync , mongodbPing , kafkaProducerAsync , getOidcTokenClientCredentials , rootCertificatesFingerprints , axiosAbortSignal
redisPingAsync , mongodbPing , kafkaProducerAsync , getOidcTokenClientCredentials , rootCertificatesFingerprints , axiosAbortSignal
@ -343,16 +343,6 @@ class Monitor extends BeanModel {
}
}
}
}
// Evil
if ( isDev ) {
if ( process . env . EVIL _RANDOM _MONITOR _SLEEP === "SURE" ) {
if ( getRandomInt ( 0 , 100 ) === 0 ) {
log . debug ( "evil" , ` [ ${ this . name } ] Evil mode: Random sleep: ` + beatInterval * 10000 ) ;
await sleep ( beatInterval * 10000 ) ;
}
}
}
// Expose here for prometheus update
// Expose here for prometheus update
// undefined if not https
// undefined if not https
let tlsInfo = undefined ;
let tlsInfo = undefined ;
@ -495,7 +485,7 @@ class Monitor extends BeanModel {
validateStatus : ( status ) => {
validateStatus : ( status ) => {
return checkStatusCode ( status , this . getAcceptedStatuscodes ( ) ) ;
return checkStatusCode ( status , this . getAcceptedStatuscodes ( ) ) ;
} ,
} ,
signal : axiosAbortSignal ( this . timeout * 1000 ) ,
signal : axiosAbortSignal ( ( this . timeout + 10 ) * 1000 ) ,
} ;
} ;
if ( bodyValue ) {
if ( bodyValue ) {
@ -910,7 +900,11 @@ class Monitor extends BeanModel {
} catch ( error ) {
} catch ( error ) {
bean . msg = error . message ;
if ( error ? . name === "CanceledError" ) {
bean . msg = ` timeout by AbortSignal ( ${ this . timeout } s) ` ;
} else {
bean . msg = error . message ;
}
// If UP come in here, it must be upside down mode
// If UP come in here, it must be upside down mode
// Just reset the retries
// Just reset the retries
@ -1011,7 +1005,6 @@ class Monitor extends BeanModel {
log . debug ( "monitor" , ` [ ${ this . name } ] Next heartbeat in: ${ intervalRemainingMs } ms ` ) ;
log . debug ( "monitor" , ` [ ${ this . name } ] Next heartbeat in: ${ intervalRemainingMs } ms ` ) ;
this . heartbeatInterval = setTimeout ( safeBeat , intervalRemainingMs ) ;
this . heartbeatInterval = setTimeout ( safeBeat , intervalRemainingMs ) ;
this . lastScheduleBeatTime = dayjs ( ) ;
} else {
} else {
log . info ( "monitor" , ` [ ${ this . name } ] isStop = true, no next check. ` ) ;
log . info ( "monitor" , ` [ ${ this . name } ] isStop = true, no next check. ` ) ;
}
}
@ -1024,9 +1017,7 @@ class Monitor extends BeanModel {
* /
* /
const safeBeat = async ( ) => {
const safeBeat = async ( ) => {
try {
try {
this . lastStartBeatTime = dayjs ( ) ;
await beat ( ) ;
await beat ( ) ;
this . lastEndBeatTime = dayjs ( ) ;
} catch ( e ) {
} catch ( e ) {
console . trace ( e ) ;
console . trace ( e ) ;
UptimeKumaServer . errorLog ( e , false ) ;
UptimeKumaServer . errorLog ( e , false ) ;
@ -1035,9 +1026,6 @@ class Monitor extends BeanModel {
if ( ! this . isStop ) {
if ( ! this . isStop ) {
log . info ( "monitor" , "Try to restart the monitor" ) ;
log . info ( "monitor" , "Try to restart the monitor" ) ;
this . heartbeatInterval = setTimeout ( safeBeat , this . interval * 1000 ) ;
this . heartbeatInterval = setTimeout ( safeBeat , this . interval * 1000 ) ;
this . lastScheduleBeatTime = dayjs ( ) ;
} else {
log . info ( "monitor" , "isStop = true, no next check." ) ;
}
}
}
}
} ;
} ;