Skip to content

Commit

Permalink
Add debug logging to server monitor criteria and comparison functions
Browse files Browse the repository at this point in the history
  • Loading branch information
simlarsen committed Dec 20, 2024
1 parent 8fc3fe4 commit 946f82f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
6 changes: 6 additions & 0 deletions Common/Server/Utils/Monitor/Criteria/CompareCriteria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export default class CompareCriteria {
value: boolean | Array<boolean>;
evaluationType?: EvaluateOverTimeType | undefined;
}): boolean {
logger.debug(`isTrue: ${JSON.stringify(data)}`);

if (Array.isArray(data.value)) {
if (data.evaluationType === EvaluateOverTimeType.AnyValue) {
return data.value.some((value: boolean) => {
Expand All @@ -49,6 +51,8 @@ export default class CompareCriteria {
value: boolean | Array<boolean>;
evaluationType?: EvaluateOverTimeType | undefined;
}): boolean {
logger.debug(`isFalse: ${JSON.stringify(data)}`);

if (Array.isArray(data.value)) {
if (data.evaluationType === EvaluateOverTimeType.AnyValue) {
return data.value.some((value: boolean) => {
Expand Down Expand Up @@ -304,6 +308,8 @@ export default class CompareCriteria {
value: Array<boolean> | boolean;
criteriaFilter: CriteriaFilter;
}): string | null {
logger.debug(`compareCriteriaBoolean: ${JSON.stringify(data)}`);

if (data.value === null || data.value === undefined) {
return null;
}
Expand Down
26 changes: 23 additions & 3 deletions Common/Server/Utils/Monitor/Criteria/ServerMonitorCriteria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import ServerMonitorResponse, {
ServerProcess,
} from "Common/Types/Monitor/ServerMonitor/ServerMonitorResponse";
import logger from "../../Logger";

export default class ServerMonitorCriteria {
public static async isMonitorInstanceCriteriaFilterMet(input: {
Expand Down Expand Up @@ -64,18 +65,31 @@ export default class ServerMonitorCriteria {
input.criteriaFilter.evaluateOverTimeOptions.timeValueInMinutes || 3;
}

logger.debug("Server Monitor Criteria Filter");
logger.debug(`Monitor ID: ${input.dataToProcess.monitorId}`);
logger.debug(`Check On: ${input.criteriaFilter.checkOn}`);
logger.debug(`Difference in Minutes: ${differenceInMinutes}`);
logger.debug(
`Offline if not checked in minutes: ${offlineIfNotCheckedInMinutes}`,
);

if (
input.criteriaFilter.checkOn === CheckOn.IsOnline &&
differenceInMinutes >= offlineIfNotCheckedInMinutes
) {

const currentIsOnline: boolean | Array<boolean> =
(overTimeValue as Array<boolean>) || false; // false because no request receieved in the last 2 minutes

return CompareCriteria.compareCriteriaBoolean({
logger.debug(`Current Is Online: ${currentIsOnline}`);

const criteria: string | null = CompareCriteria.compareCriteriaBoolean({
value: currentIsOnline,
criteriaFilter: input.criteriaFilter,
});

logger.debug(`Criteria: ${criteria}`);

return criteria;
}

if (
Expand All @@ -85,10 +99,16 @@ export default class ServerMonitorCriteria {
const currentIsOnline: boolean | Array<boolean> =
(overTimeValue as Array<boolean>) || true; // true because request receieved in the last 2 minutes

return CompareCriteria.compareCriteriaBoolean({
logger.debug(`Current Is Online: ${currentIsOnline}`);

const criteria: string | null = CompareCriteria.compareCriteriaBoolean({
value: currentIsOnline,
criteriaFilter: input.criteriaFilter,
});

logger.debug(`Criteria: ${criteria}`);

return criteria;
}

if (
Expand Down
2 changes: 1 addition & 1 deletion Common/Server/Utils/Monitor/MonitorResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ export default class MonitorResourceUtil {
logger.debug(
`${dataToProcess.monitorId.toString()} - Processing monitor step...`,
);

response = await MonitorResourceUtil.processMonitorStep({
dataToProcess: dataToProcess,
monitorStep: monitorStep,
Expand Down
4 changes: 3 additions & 1 deletion Worker/Jobs/ServerMonitor/CheckOnlineStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ RunCron(
monitorId: monitor.id!,
onlyCheckRequestReceivedAt: true,
requestReceivedAt:
monitor.serverMonitorRequestReceivedAt || monitor.serverMonitorResponse?.requestReceivedAt || monitor.createdAt!,
monitor.serverMonitorRequestReceivedAt ||
monitor.serverMonitorResponse?.requestReceivedAt ||
monitor.createdAt!,
hostname: monitor.serverMonitorResponse?.hostname || "",
};

Expand Down

0 comments on commit 946f82f

Please sign in to comment.