@oneuptime/common 8.0.5516 → 8.0.5547
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Models/DatabaseModels/AcmeChallenge.ts +3 -0
- package/Models/DatabaseModels/Domain.ts +6 -1
- package/Server/API/AcmeChallengeAPI.ts +64 -0
- package/Server/EnvironmentConfig.ts +54 -0
- package/Server/Infrastructure/Queue.ts +12 -16
- package/Server/Infrastructure/QueueWorker.ts +2 -6
- package/Server/Services/DomainService.ts +48 -40
- package/Server/Utils/AnalyticsDatabase/Statement.ts +8 -4
- package/Server/Utils/Monitor/Criteria/CompareCriteria.ts +47 -15
- package/Server/Utils/Monitor/Criteria/ServerMonitorCriteria.ts +13 -12
- package/Server/Utils/Monitor/MonitorAlert.ts +46 -1
- package/Server/Utils/Monitor/MonitorCriteriaDataExtractor.ts +208 -0
- package/Server/Utils/Monitor/MonitorCriteriaEvaluator.ts +439 -0
- package/Server/Utils/Monitor/MonitorCriteriaExpectationBuilder.ts +141 -0
- package/Server/Utils/Monitor/MonitorCriteriaMessageBuilder.ts +88 -0
- package/Server/Utils/Monitor/MonitorCriteriaMessageFormatter.ts +196 -0
- package/Server/Utils/Monitor/MonitorCriteriaObservationBuilder.ts +1123 -0
- package/Server/Utils/Monitor/MonitorIncident.ts +46 -1
- package/Server/Utils/Monitor/MonitorLogUtil.ts +44 -0
- package/Server/Utils/Monitor/MonitorMetricUtil.ts +482 -0
- package/Server/Utils/Monitor/MonitorResource.ts +185 -914
- package/Server/Utils/StartServer.ts +14 -6
- package/Types/Email.ts +3 -7
- package/Types/Monitor/IncomingMonitor/IncomingMonitorRequest.ts +2 -0
- package/Types/Monitor/LogMonitor/LogMonitorResponse.ts +2 -0
- package/Types/Monitor/MetricMonitor/MetricMonitorResponse.ts +2 -0
- package/Types/Monitor/MonitorEvaluationSummary.ts +48 -0
- package/Types/Monitor/ServerMonitor/ServerMonitorResponse.ts +2 -0
- package/Types/Monitor/TraceMonitor/TraceMonitorResponse.ts +2 -0
- package/Types/Probe/ProbeApiIngestResponse.ts +2 -0
- package/Types/Probe/ProbeMonitorResponse.ts +2 -0
- package/build/dist/Models/DatabaseModels/AcmeChallenge.js +3 -0
- package/build/dist/Models/DatabaseModels/AcmeChallenge.js.map +1 -1
- package/build/dist/Models/DatabaseModels/Domain.js +6 -1
- package/build/dist/Models/DatabaseModels/Domain.js.map +1 -1
- package/build/dist/Server/API/AcmeChallengeAPI.js +39 -0
- package/build/dist/Server/API/AcmeChallengeAPI.js.map +1 -0
- package/build/dist/Server/EnvironmentConfig.js +44 -0
- package/build/dist/Server/EnvironmentConfig.js.map +1 -1
- package/build/dist/Server/Infrastructure/Queue.js +8 -11
- package/build/dist/Server/Infrastructure/Queue.js.map +1 -1
- package/build/dist/Server/Infrastructure/QueueWorker.js +2 -6
- package/build/dist/Server/Infrastructure/QueueWorker.js.map +1 -1
- package/build/dist/Server/Services/DomainService.js +31 -29
- package/build/dist/Server/Services/DomainService.js.map +1 -1
- package/build/dist/Server/Utils/AnalyticsDatabase/Statement.js +2 -1
- package/build/dist/Server/Utils/AnalyticsDatabase/Statement.js.map +1 -1
- package/build/dist/Server/Utils/Monitor/Criteria/CompareCriteria.js +34 -16
- package/build/dist/Server/Utils/Monitor/Criteria/CompareCriteria.js.map +1 -1
- package/build/dist/Server/Utils/Monitor/Criteria/ServerMonitorCriteria.js +12 -12
- package/build/dist/Server/Utils/Monitor/Criteria/ServerMonitorCriteria.js.map +1 -1
- package/build/dist/Server/Utils/Monitor/MonitorAlert.js +42 -4
- package/build/dist/Server/Utils/Monitor/MonitorAlert.js.map +1 -1
- package/build/dist/Server/Utils/Monitor/MonitorCriteriaDataExtractor.js +119 -0
- package/build/dist/Server/Utils/Monitor/MonitorCriteriaDataExtractor.js.map +1 -0
- package/build/dist/Server/Utils/Monitor/MonitorCriteriaEvaluator.js +312 -0
- package/build/dist/Server/Utils/Monitor/MonitorCriteriaEvaluator.js.map +1 -0
- package/build/dist/Server/Utils/Monitor/MonitorCriteriaExpectationBuilder.js +109 -0
- package/build/dist/Server/Utils/Monitor/MonitorCriteriaExpectationBuilder.js.map +1 -0
- package/build/dist/Server/Utils/Monitor/MonitorCriteriaMessageBuilder.js +45 -0
- package/build/dist/Server/Utils/Monitor/MonitorCriteriaMessageBuilder.js.map +1 -0
- package/build/dist/Server/Utils/Monitor/MonitorCriteriaMessageFormatter.js +132 -0
- package/build/dist/Server/Utils/Monitor/MonitorCriteriaMessageFormatter.js.map +1 -0
- package/build/dist/Server/Utils/Monitor/MonitorCriteriaObservationBuilder.js +583 -0
- package/build/dist/Server/Utils/Monitor/MonitorCriteriaObservationBuilder.js.map +1 -0
- package/build/dist/Server/Utils/Monitor/MonitorIncident.js +42 -4
- package/build/dist/Server/Utils/Monitor/MonitorIncident.js.map +1 -1
- package/build/dist/Server/Utils/Monitor/MonitorLogUtil.js +32 -0
- package/build/dist/Server/Utils/Monitor/MonitorLogUtil.js.map +1 -0
- package/build/dist/Server/Utils/Monitor/MonitorMetricUtil.js +361 -0
- package/build/dist/Server/Utils/Monitor/MonitorMetricUtil.js.map +1 -0
- package/build/dist/Server/Utils/Monitor/MonitorResource.js +134 -666
- package/build/dist/Server/Utils/Monitor/MonitorResource.js.map +1 -1
- package/build/dist/Server/Utils/StartServer.js +7 -4
- package/build/dist/Server/Utils/StartServer.js.map +1 -1
- package/build/dist/Types/Email.js +2 -5
- package/build/dist/Types/Email.js.map +1 -1
- package/build/dist/Types/Monitor/MonitorEvaluationSummary.js +2 -0
- package/build/dist/Types/Monitor/MonitorEvaluationSummary.js.map +1 -0
- package/package.json +5 -5
|
@@ -21,6 +21,8 @@ import CaptureSpan from "../Telemetry/CaptureSpan";
|
|
|
21
21
|
import DataToProcess from "./DataToProcess";
|
|
22
22
|
import MonitorTemplateUtil from "./MonitorTemplateUtil";
|
|
23
23
|
import { JSONObject } from "../../../Types/JSON";
|
|
24
|
+
import OneUptimeDate from "../../../Types/Date";
|
|
25
|
+
import MonitorEvaluationSummary from "../../../Types/Monitor/MonitorEvaluationSummary";
|
|
24
26
|
|
|
25
27
|
export default class MonitorIncident {
|
|
26
28
|
@CaptureSpan()
|
|
@@ -32,6 +34,7 @@ export default class MonitorIncident {
|
|
|
32
34
|
rootCause: string;
|
|
33
35
|
criteriaInstance: MonitorCriteriaInstance | null;
|
|
34
36
|
dataToProcess: DataToProcess;
|
|
37
|
+
evaluationSummary?: MonitorEvaluationSummary | undefined;
|
|
35
38
|
}): Promise<Array<Incident>> {
|
|
36
39
|
// check active incidents and if there are open incidents, do not cretae anothr incident.
|
|
37
40
|
const openIncidents: Array<Incident> = await IncidentService.findBy({
|
|
@@ -48,6 +51,7 @@ export default class MonitorIncident {
|
|
|
48
51
|
createdCriteriaId: true,
|
|
49
52
|
createdIncidentTemplateId: true,
|
|
50
53
|
projectId: true,
|
|
54
|
+
incidentNumber: true,
|
|
51
55
|
},
|
|
52
56
|
props: {
|
|
53
57
|
isRoot: true,
|
|
@@ -71,6 +75,17 @@ export default class MonitorIncident {
|
|
|
71
75
|
rootCause: input.rootCause,
|
|
72
76
|
dataToProcess: input.dataToProcess,
|
|
73
77
|
});
|
|
78
|
+
|
|
79
|
+
input.evaluationSummary?.events.push({
|
|
80
|
+
type: "incident-resolved",
|
|
81
|
+
title: `Incident resolved: ${openIncident.id?.toString()}`,
|
|
82
|
+
message:
|
|
83
|
+
"Incident auto-resolved because autoresolve is enabled for this criteria.",
|
|
84
|
+
relatedIncidentId: openIncident.id?.toString(),
|
|
85
|
+
relatedIncidentNumber: openIncident.incidentNumber,
|
|
86
|
+
relatedCriteriaId: input.criteriaInstance?.data?.id,
|
|
87
|
+
at: OneUptimeDate.getCurrentDate(),
|
|
88
|
+
});
|
|
74
89
|
}
|
|
75
90
|
}
|
|
76
91
|
|
|
@@ -86,6 +101,7 @@ export default class MonitorIncident {
|
|
|
86
101
|
autoResolveCriteriaInstanceIdIncidentIdsDictionary: Dictionary<
|
|
87
102
|
Array<string>
|
|
88
103
|
>;
|
|
104
|
+
evaluationSummary?: MonitorEvaluationSummary | undefined;
|
|
89
105
|
props: {
|
|
90
106
|
telemetryQuery?: TelemetryQuery | undefined;
|
|
91
107
|
};
|
|
@@ -101,6 +117,7 @@ export default class MonitorIncident {
|
|
|
101
117
|
rootCause: input.rootCause,
|
|
102
118
|
criteriaInstance: input.criteriaInstance,
|
|
103
119
|
dataToProcess: input.dataToProcess,
|
|
120
|
+
evaluationSummary: input.evaluationSummary,
|
|
104
121
|
});
|
|
105
122
|
|
|
106
123
|
if (input.criteriaInstance.data?.createIncidents) {
|
|
@@ -132,6 +149,16 @@ export default class MonitorIncident {
|
|
|
132
149
|
);
|
|
133
150
|
|
|
134
151
|
if (hasAlreadyOpenIncident) {
|
|
152
|
+
input.evaluationSummary?.events.push({
|
|
153
|
+
type: "incident-skipped",
|
|
154
|
+
title: `Incident already active: ${criteriaIncident.title}`,
|
|
155
|
+
message:
|
|
156
|
+
"Skipped creating a new incident because an active incident exists for this criteria.",
|
|
157
|
+
relatedCriteriaId: input.criteriaInstance.data?.id,
|
|
158
|
+
relatedIncidentId: alreadyOpenIncident?.id?.toString(),
|
|
159
|
+
relatedIncidentNumber: alreadyOpenIncident?.incidentNumber,
|
|
160
|
+
at: OneUptimeDate.getCurrentDate(),
|
|
161
|
+
});
|
|
135
162
|
continue;
|
|
136
163
|
}
|
|
137
164
|
|
|
@@ -226,15 +253,33 @@ export default class MonitorIncident {
|
|
|
226
253
|
}
|
|
227
254
|
|
|
228
255
|
if (DisableAutomaticIncidentCreation) {
|
|
256
|
+
input.evaluationSummary?.events.push({
|
|
257
|
+
type: "incident-skipped",
|
|
258
|
+
title: "Incident creation skipped",
|
|
259
|
+
message:
|
|
260
|
+
"Automatic incident creation is disabled by environment configuration.",
|
|
261
|
+
relatedCriteriaId: input.criteriaInstance.data?.id,
|
|
262
|
+
at: OneUptimeDate.getCurrentDate(),
|
|
263
|
+
});
|
|
229
264
|
return;
|
|
230
265
|
}
|
|
231
266
|
|
|
232
|
-
await IncidentService.create({
|
|
267
|
+
const createdIncident: Incident = await IncidentService.create({
|
|
233
268
|
data: incident,
|
|
234
269
|
props: {
|
|
235
270
|
isRoot: true,
|
|
236
271
|
},
|
|
237
272
|
});
|
|
273
|
+
|
|
274
|
+
input.evaluationSummary?.events.push({
|
|
275
|
+
type: "incident-created",
|
|
276
|
+
title: `Incident created: ${createdIncident.title || criteriaIncident.title}`,
|
|
277
|
+
message: `Incident triggered from criteria "${input.criteriaInstance.data?.name || "Unnamed criteria"}".`,
|
|
278
|
+
relatedCriteriaId: input.criteriaInstance.data?.id,
|
|
279
|
+
relatedIncidentId: createdIncident.id?.toString(),
|
|
280
|
+
relatedIncidentNumber: createdIncident.incidentNumber,
|
|
281
|
+
at: OneUptimeDate.getCurrentDate(),
|
|
282
|
+
});
|
|
238
283
|
}
|
|
239
284
|
}
|
|
240
285
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import MonitorLogService from "../../Services/MonitorLogService";
|
|
2
|
+
import logger from "../Logger";
|
|
3
|
+
import OneUptimeDate from "../../../Types/Date";
|
|
4
|
+
import ObjectID from "../../../Types/ObjectID";
|
|
5
|
+
import { JSONObject } from "../../../Types/JSON";
|
|
6
|
+
import DataToProcess from "./DataToProcess";
|
|
7
|
+
|
|
8
|
+
export default class MonitorLogUtil {
|
|
9
|
+
public static saveMonitorLog(data: {
|
|
10
|
+
monitorId: ObjectID;
|
|
11
|
+
projectId: ObjectID;
|
|
12
|
+
dataToProcess: DataToProcess;
|
|
13
|
+
}): void {
|
|
14
|
+
if (!data.monitorId) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (!data.projectId) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (!data.dataToProcess) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const logIngestionDate: Date = OneUptimeDate.getCurrentDate();
|
|
27
|
+
const logTimestamp: string =
|
|
28
|
+
OneUptimeDate.toClickhouseDateTime(logIngestionDate);
|
|
29
|
+
|
|
30
|
+
const monitorLogRow: JSONObject = {
|
|
31
|
+
_id: ObjectID.generate().toString(),
|
|
32
|
+
createdAt: logTimestamp,
|
|
33
|
+
updatedAt: logTimestamp,
|
|
34
|
+
projectId: data.projectId.toString(),
|
|
35
|
+
monitorId: data.monitorId.toString(),
|
|
36
|
+
time: logTimestamp,
|
|
37
|
+
logBody: JSON.parse(JSON.stringify(data.dataToProcess)),
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
MonitorLogService.insertJsonRows([monitorLogRow]).catch((err: Error) => {
|
|
41
|
+
logger.error(err);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
import logger from "../Logger";
|
|
2
|
+
import CaptureSpan from "../Telemetry/CaptureSpan";
|
|
3
|
+
import TelemetryUtil from "../Telemetry/Telemetry";
|
|
4
|
+
import MetricService from "../../Services/MetricService";
|
|
5
|
+
import DataToProcess from "./DataToProcess";
|
|
6
|
+
import {
|
|
7
|
+
MetricPointType,
|
|
8
|
+
ServiceType,
|
|
9
|
+
} from "../../../Models/AnalyticsModels/Metric";
|
|
10
|
+
import MetricType from "../../../Models/DatabaseModels/MetricType";
|
|
11
|
+
import BasicInfrastructureMetrics from "../../../Types/Infrastructure/BasicMetrics";
|
|
12
|
+
import Dictionary from "../../../Types/Dictionary";
|
|
13
|
+
import { JSONObject } from "../../../Types/JSON";
|
|
14
|
+
import MonitorMetricType from "../../../Types/Monitor/MonitorMetricType";
|
|
15
|
+
import ProbeMonitorResponse from "../../../Types/Probe/ProbeMonitorResponse";
|
|
16
|
+
import ServerMonitorResponse from "../../../Types/Monitor/ServerMonitor/ServerMonitorResponse";
|
|
17
|
+
import SyntheticMonitorResponse from "../../../Types/Monitor/SyntheticMonitors/SyntheticMonitorResponse";
|
|
18
|
+
import { CheckOn } from "../../../Types/Monitor/CriteriaFilter";
|
|
19
|
+
import ObjectID from "../../../Types/ObjectID";
|
|
20
|
+
import OneUptimeDate from "../../../Types/Date";
|
|
21
|
+
|
|
22
|
+
export default class MonitorMetricUtil {
|
|
23
|
+
private static buildMonitorMetricAttributes(data: {
|
|
24
|
+
monitorId: ObjectID;
|
|
25
|
+
projectId: ObjectID;
|
|
26
|
+
monitorName?: string | undefined;
|
|
27
|
+
probeName?: string | undefined;
|
|
28
|
+
extraAttributes?: JSONObject;
|
|
29
|
+
}): JSONObject {
|
|
30
|
+
const attributes: JSONObject = {
|
|
31
|
+
monitorId: data.monitorId.toString(),
|
|
32
|
+
projectId: data.projectId.toString(),
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
if (data.extraAttributes) {
|
|
36
|
+
Object.assign(attributes, data.extraAttributes);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (data.monitorName) {
|
|
40
|
+
attributes["monitorName"] = data.monitorName;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (data.probeName) {
|
|
44
|
+
attributes["probeName"] = data.probeName;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return attributes;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private static buildMonitorMetricRow(data: {
|
|
51
|
+
projectId: ObjectID;
|
|
52
|
+
monitorId: ObjectID;
|
|
53
|
+
metricName: string;
|
|
54
|
+
value: number | null | undefined;
|
|
55
|
+
attributes: JSONObject;
|
|
56
|
+
metricPointType?: MetricPointType;
|
|
57
|
+
}): JSONObject {
|
|
58
|
+
const ingestionDate: Date = OneUptimeDate.getCurrentDate();
|
|
59
|
+
const ingestionTimestamp: string =
|
|
60
|
+
OneUptimeDate.toClickhouseDateTime(ingestionDate);
|
|
61
|
+
const timeUnixNano: string =
|
|
62
|
+
OneUptimeDate.toUnixNano(ingestionDate).toString();
|
|
63
|
+
|
|
64
|
+
const attributes: JSONObject = { ...data.attributes };
|
|
65
|
+
const attributeKeys: Array<string> =
|
|
66
|
+
TelemetryUtil.getAttributeKeys(attributes);
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
_id: ObjectID.generate().toString(),
|
|
70
|
+
createdAt: ingestionTimestamp,
|
|
71
|
+
updatedAt: ingestionTimestamp,
|
|
72
|
+
projectId: data.projectId.toString(),
|
|
73
|
+
serviceId: data.monitorId.toString(),
|
|
74
|
+
serviceType: ServiceType.Monitor,
|
|
75
|
+
name: data.metricName,
|
|
76
|
+
aggregationTemporality: null,
|
|
77
|
+
metricPointType: data.metricPointType || MetricPointType.Sum,
|
|
78
|
+
time: ingestionTimestamp,
|
|
79
|
+
startTime: null,
|
|
80
|
+
timeUnixNano: timeUnixNano,
|
|
81
|
+
startTimeUnixNano: null,
|
|
82
|
+
attributes: attributes,
|
|
83
|
+
attributeKeys: attributeKeys,
|
|
84
|
+
isMonotonic: null,
|
|
85
|
+
count: null,
|
|
86
|
+
sum: null,
|
|
87
|
+
min: null,
|
|
88
|
+
max: null,
|
|
89
|
+
bucketCounts: [],
|
|
90
|
+
explicitBounds: [],
|
|
91
|
+
value: data.value ?? null,
|
|
92
|
+
} as JSONObject;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
@CaptureSpan()
|
|
96
|
+
public static async saveMonitorMetrics(data: {
|
|
97
|
+
monitorId: ObjectID;
|
|
98
|
+
projectId: ObjectID;
|
|
99
|
+
dataToProcess: DataToProcess;
|
|
100
|
+
probeName: string | undefined;
|
|
101
|
+
monitorName: string | undefined;
|
|
102
|
+
}): Promise<void> {
|
|
103
|
+
if (!data.monitorId) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (!data.projectId) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (!data.dataToProcess) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const metricRows: Array<JSONObject> = [];
|
|
116
|
+
|
|
117
|
+
/*
|
|
118
|
+
* Metric name to serviceId map
|
|
119
|
+
* example: "cpu.usage" -> [serviceId1, serviceId2]
|
|
120
|
+
* since these are monitor metrics. They dont belong to any service so we can keep the array empty.
|
|
121
|
+
*/
|
|
122
|
+
const metricNameServiceNameMap: Dictionary<MetricType> = {};
|
|
123
|
+
|
|
124
|
+
if (
|
|
125
|
+
(data.dataToProcess as ServerMonitorResponse).basicInfrastructureMetrics
|
|
126
|
+
) {
|
|
127
|
+
// store cpu, memory, disk metrics.
|
|
128
|
+
|
|
129
|
+
if ((data.dataToProcess as ServerMonitorResponse).requestReceivedAt) {
|
|
130
|
+
let isOnline: boolean = true;
|
|
131
|
+
|
|
132
|
+
const differenceInMinutes: number =
|
|
133
|
+
OneUptimeDate.getDifferenceInMinutes(
|
|
134
|
+
(data.dataToProcess as ServerMonitorResponse).requestReceivedAt,
|
|
135
|
+
OneUptimeDate.getCurrentDate(),
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
if (differenceInMinutes > 2) {
|
|
139
|
+
isOnline = false;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const attributes: JSONObject = this.buildMonitorMetricAttributes({
|
|
143
|
+
monitorId: data.monitorId,
|
|
144
|
+
projectId: data.projectId,
|
|
145
|
+
monitorName: data.monitorName,
|
|
146
|
+
probeName: data.probeName,
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
const metricRow: JSONObject = this.buildMonitorMetricRow({
|
|
150
|
+
projectId: data.projectId,
|
|
151
|
+
monitorId: data.monitorId,
|
|
152
|
+
metricName: MonitorMetricType.IsOnline,
|
|
153
|
+
value: isOnline ? 1 : 0,
|
|
154
|
+
attributes: attributes,
|
|
155
|
+
metricPointType: MetricPointType.Sum,
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
metricRows.push(metricRow);
|
|
159
|
+
|
|
160
|
+
// add MetricType
|
|
161
|
+
const metricType: MetricType = new MetricType();
|
|
162
|
+
metricType.name = MonitorMetricType.IsOnline;
|
|
163
|
+
metricType.description = CheckOn.IsOnline + " status for monitor";
|
|
164
|
+
metricType.unit = "";
|
|
165
|
+
|
|
166
|
+
// add to map
|
|
167
|
+
metricNameServiceNameMap[MonitorMetricType.IsOnline] = metricType;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const basicMetrics: BasicInfrastructureMetrics | undefined = (
|
|
171
|
+
data.dataToProcess as ServerMonitorResponse
|
|
172
|
+
).basicInfrastructureMetrics;
|
|
173
|
+
|
|
174
|
+
if (!basicMetrics) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (basicMetrics.cpuMetrics) {
|
|
179
|
+
const attributes: JSONObject = this.buildMonitorMetricAttributes({
|
|
180
|
+
monitorId: data.monitorId,
|
|
181
|
+
projectId: data.projectId,
|
|
182
|
+
monitorName: data.monitorName,
|
|
183
|
+
probeName: data.probeName,
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
const metricRow: JSONObject = this.buildMonitorMetricRow({
|
|
187
|
+
projectId: data.projectId,
|
|
188
|
+
monitorId: data.monitorId,
|
|
189
|
+
metricName: MonitorMetricType.CPUUsagePercent,
|
|
190
|
+
value: basicMetrics.cpuMetrics.percentUsed ?? null,
|
|
191
|
+
attributes: attributes,
|
|
192
|
+
metricPointType: MetricPointType.Sum,
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
metricRows.push(metricRow);
|
|
196
|
+
|
|
197
|
+
const metricType: MetricType = new MetricType();
|
|
198
|
+
metricType.name = MonitorMetricType.CPUUsagePercent;
|
|
199
|
+
metricType.description = CheckOn.CPUUsagePercent + " of Server/VM";
|
|
200
|
+
metricType.unit = "%";
|
|
201
|
+
|
|
202
|
+
metricNameServiceNameMap[MonitorMetricType.CPUUsagePercent] =
|
|
203
|
+
metricType;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (basicMetrics.memoryMetrics) {
|
|
207
|
+
const attributes: JSONObject = this.buildMonitorMetricAttributes({
|
|
208
|
+
monitorId: data.monitorId,
|
|
209
|
+
projectId: data.projectId,
|
|
210
|
+
monitorName: data.monitorName,
|
|
211
|
+
probeName: data.probeName,
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
const metricRow: JSONObject = this.buildMonitorMetricRow({
|
|
215
|
+
projectId: data.projectId,
|
|
216
|
+
monitorId: data.monitorId,
|
|
217
|
+
metricName: MonitorMetricType.MemoryUsagePercent,
|
|
218
|
+
value: basicMetrics.memoryMetrics.percentUsed ?? null,
|
|
219
|
+
attributes: attributes,
|
|
220
|
+
metricPointType: MetricPointType.Sum,
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
metricRows.push(metricRow);
|
|
224
|
+
|
|
225
|
+
const metricType: MetricType = new MetricType();
|
|
226
|
+
metricType.name = MonitorMetricType.MemoryUsagePercent;
|
|
227
|
+
metricType.description = CheckOn.MemoryUsagePercent + " of Server/VM";
|
|
228
|
+
metricType.unit = "%";
|
|
229
|
+
|
|
230
|
+
metricNameServiceNameMap[MonitorMetricType.MemoryUsagePercent] =
|
|
231
|
+
metricType;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (basicMetrics.diskMetrics && basicMetrics.diskMetrics.length > 0) {
|
|
235
|
+
for (const diskMetric of basicMetrics.diskMetrics) {
|
|
236
|
+
const extraAttributes: JSONObject = {};
|
|
237
|
+
|
|
238
|
+
if (diskMetric.diskPath) {
|
|
239
|
+
extraAttributes["diskPath"] = diskMetric.diskPath;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const attributes: JSONObject = this.buildMonitorMetricAttributes({
|
|
243
|
+
monitorId: data.monitorId,
|
|
244
|
+
projectId: data.projectId,
|
|
245
|
+
monitorName: data.monitorName,
|
|
246
|
+
probeName: data.probeName,
|
|
247
|
+
extraAttributes: extraAttributes,
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
const metricRow: JSONObject = this.buildMonitorMetricRow({
|
|
251
|
+
projectId: data.projectId,
|
|
252
|
+
monitorId: data.monitorId,
|
|
253
|
+
metricName: MonitorMetricType.DiskUsagePercent,
|
|
254
|
+
value: diskMetric.percentUsed ?? null,
|
|
255
|
+
attributes: attributes,
|
|
256
|
+
metricPointType: MetricPointType.Sum,
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
metricRows.push(metricRow);
|
|
260
|
+
|
|
261
|
+
const metricType: MetricType = new MetricType();
|
|
262
|
+
metricType.name = MonitorMetricType.DiskUsagePercent;
|
|
263
|
+
metricType.description = CheckOn.DiskUsagePercent + " of Server/VM";
|
|
264
|
+
metricType.unit = "%";
|
|
265
|
+
|
|
266
|
+
metricNameServiceNameMap[MonitorMetricType.DiskUsagePercent] =
|
|
267
|
+
metricType;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if (
|
|
273
|
+
(data.dataToProcess as ProbeMonitorResponse).customCodeMonitorResponse
|
|
274
|
+
?.executionTimeInMS
|
|
275
|
+
) {
|
|
276
|
+
const extraAttributes: JSONObject = {
|
|
277
|
+
probeId: (
|
|
278
|
+
data.dataToProcess as ProbeMonitorResponse
|
|
279
|
+
).probeId.toString(),
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
const attributes: JSONObject = this.buildMonitorMetricAttributes({
|
|
283
|
+
monitorId: data.monitorId,
|
|
284
|
+
projectId: data.projectId,
|
|
285
|
+
extraAttributes: extraAttributes,
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
const metricRow: JSONObject = this.buildMonitorMetricRow({
|
|
289
|
+
projectId: data.projectId,
|
|
290
|
+
monitorId: data.monitorId,
|
|
291
|
+
metricName: MonitorMetricType.ExecutionTime,
|
|
292
|
+
value:
|
|
293
|
+
(data.dataToProcess as ProbeMonitorResponse).customCodeMonitorResponse
|
|
294
|
+
?.executionTimeInMS ?? null,
|
|
295
|
+
attributes: attributes,
|
|
296
|
+
metricPointType: MetricPointType.Sum,
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
metricRows.push(metricRow);
|
|
300
|
+
|
|
301
|
+
const metricType: MetricType = new MetricType();
|
|
302
|
+
metricType.name = MonitorMetricType.ExecutionTime;
|
|
303
|
+
metricType.description = CheckOn.ExecutionTime + " of this monitor";
|
|
304
|
+
metricType.unit = "ms";
|
|
305
|
+
|
|
306
|
+
metricNameServiceNameMap[MonitorMetricType.ExecutionTime] = metricType;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
if (
|
|
310
|
+
(data.dataToProcess as ProbeMonitorResponse) &&
|
|
311
|
+
(data.dataToProcess as ProbeMonitorResponse).syntheticMonitorResponse &&
|
|
312
|
+
(
|
|
313
|
+
(data.dataToProcess as ProbeMonitorResponse).syntheticMonitorResponse ||
|
|
314
|
+
[]
|
|
315
|
+
).length > 0
|
|
316
|
+
) {
|
|
317
|
+
const syntheticResponses: Array<SyntheticMonitorResponse> =
|
|
318
|
+
(data.dataToProcess as ProbeMonitorResponse).syntheticMonitorResponse ||
|
|
319
|
+
[];
|
|
320
|
+
|
|
321
|
+
for (const syntheticMonitorResponse of syntheticResponses) {
|
|
322
|
+
const extraAttributes: JSONObject = {
|
|
323
|
+
probeId: (
|
|
324
|
+
data.dataToProcess as ProbeMonitorResponse
|
|
325
|
+
).probeId.toString(),
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
if (syntheticMonitorResponse.browserType) {
|
|
329
|
+
extraAttributes["browserType"] = syntheticMonitorResponse.browserType;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (syntheticMonitorResponse.screenSizeType) {
|
|
333
|
+
extraAttributes["screenSizeType"] =
|
|
334
|
+
syntheticMonitorResponse.screenSizeType;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const attributes: JSONObject = this.buildMonitorMetricAttributes({
|
|
338
|
+
monitorId: data.monitorId,
|
|
339
|
+
projectId: data.projectId,
|
|
340
|
+
monitorName: data.monitorName,
|
|
341
|
+
probeName: data.probeName,
|
|
342
|
+
extraAttributes: extraAttributes,
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
const metricRow: JSONObject = this.buildMonitorMetricRow({
|
|
346
|
+
projectId: data.projectId,
|
|
347
|
+
monitorId: data.monitorId,
|
|
348
|
+
metricName: MonitorMetricType.ExecutionTime,
|
|
349
|
+
value: syntheticMonitorResponse.executionTimeInMS ?? null,
|
|
350
|
+
attributes: attributes,
|
|
351
|
+
metricPointType: MetricPointType.Sum,
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
metricRows.push(metricRow);
|
|
355
|
+
|
|
356
|
+
const metricType: MetricType = new MetricType();
|
|
357
|
+
metricType.name = MonitorMetricType.ExecutionTime;
|
|
358
|
+
metricType.description = CheckOn.ExecutionTime + " of this monitor";
|
|
359
|
+
metricType.unit = "ms";
|
|
360
|
+
|
|
361
|
+
metricNameServiceNameMap[MonitorMetricType.ExecutionTime] = metricType;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
if ((data.dataToProcess as ProbeMonitorResponse).responseTimeInMs) {
|
|
366
|
+
const extraAttributes: JSONObject = {
|
|
367
|
+
probeId: (
|
|
368
|
+
data.dataToProcess as ProbeMonitorResponse
|
|
369
|
+
).probeId.toString(),
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
const attributes: JSONObject = this.buildMonitorMetricAttributes({
|
|
373
|
+
monitorId: data.monitorId,
|
|
374
|
+
projectId: data.projectId,
|
|
375
|
+
monitorName: data.monitorName,
|
|
376
|
+
probeName: data.probeName,
|
|
377
|
+
extraAttributes: extraAttributes,
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
const metricRow: JSONObject = this.buildMonitorMetricRow({
|
|
381
|
+
projectId: data.projectId,
|
|
382
|
+
monitorId: data.monitorId,
|
|
383
|
+
metricName: MonitorMetricType.ResponseTime,
|
|
384
|
+
value:
|
|
385
|
+
(data.dataToProcess as ProbeMonitorResponse).responseTimeInMs ?? null,
|
|
386
|
+
attributes: attributes,
|
|
387
|
+
metricPointType: MetricPointType.Sum,
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
metricRows.push(metricRow);
|
|
391
|
+
|
|
392
|
+
const metricType: MetricType = new MetricType();
|
|
393
|
+
metricType.name = MonitorMetricType.ResponseTime;
|
|
394
|
+
metricType.description = CheckOn.ResponseTime + " of this monitor";
|
|
395
|
+
metricType.unit = "ms";
|
|
396
|
+
|
|
397
|
+
metricNameServiceNameMap[MonitorMetricType.ResponseTime] = metricType;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
if ((data.dataToProcess as ProbeMonitorResponse).isOnline !== undefined) {
|
|
401
|
+
const extraAttributes: JSONObject = {
|
|
402
|
+
probeId: (
|
|
403
|
+
data.dataToProcess as ProbeMonitorResponse
|
|
404
|
+
).probeId.toString(),
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
const attributes: JSONObject = this.buildMonitorMetricAttributes({
|
|
408
|
+
monitorId: data.monitorId,
|
|
409
|
+
projectId: data.projectId,
|
|
410
|
+
monitorName: data.monitorName,
|
|
411
|
+
probeName: data.probeName,
|
|
412
|
+
extraAttributes: extraAttributes,
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
const metricRow: JSONObject = this.buildMonitorMetricRow({
|
|
416
|
+
projectId: data.projectId,
|
|
417
|
+
monitorId: data.monitorId,
|
|
418
|
+
metricName: MonitorMetricType.IsOnline,
|
|
419
|
+
value: (data.dataToProcess as ProbeMonitorResponse).isOnline ? 1 : 0,
|
|
420
|
+
attributes: attributes,
|
|
421
|
+
metricPointType: MetricPointType.Sum,
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
metricRows.push(metricRow);
|
|
425
|
+
|
|
426
|
+
const metricType: MetricType = new MetricType();
|
|
427
|
+
metricType.name = MonitorMetricType.IsOnline;
|
|
428
|
+
metricType.description = CheckOn.IsOnline + " status for monitor";
|
|
429
|
+
metricType.unit = "";
|
|
430
|
+
|
|
431
|
+
metricNameServiceNameMap[MonitorMetricType.IsOnline] = metricType;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
if ((data.dataToProcess as ProbeMonitorResponse).responseCode) {
|
|
435
|
+
const extraAttributes: JSONObject = {
|
|
436
|
+
probeId: (
|
|
437
|
+
data.dataToProcess as ProbeMonitorResponse
|
|
438
|
+
).probeId.toString(),
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
const attributes: JSONObject = this.buildMonitorMetricAttributes({
|
|
442
|
+
monitorId: data.monitorId,
|
|
443
|
+
projectId: data.projectId,
|
|
444
|
+
monitorName: data.monitorName,
|
|
445
|
+
probeName: data.probeName,
|
|
446
|
+
extraAttributes: extraAttributes,
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
const metricRow: JSONObject = this.buildMonitorMetricRow({
|
|
450
|
+
projectId: data.projectId,
|
|
451
|
+
monitorId: data.monitorId,
|
|
452
|
+
metricName: MonitorMetricType.ResponseStatusCode,
|
|
453
|
+
value:
|
|
454
|
+
(data.dataToProcess as ProbeMonitorResponse).responseCode ?? null,
|
|
455
|
+
attributes: attributes,
|
|
456
|
+
metricPointType: MetricPointType.Sum,
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
metricRows.push(metricRow);
|
|
460
|
+
|
|
461
|
+
const metricType: MetricType = new MetricType();
|
|
462
|
+
metricType.name = MonitorMetricType.ResponseStatusCode;
|
|
463
|
+
metricType.description = CheckOn.ResponseStatusCode + " for this monitor";
|
|
464
|
+
metricType.unit = "Status Code";
|
|
465
|
+
|
|
466
|
+
metricNameServiceNameMap[MonitorMetricType.ResponseStatusCode] =
|
|
467
|
+
metricType;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
if (metricRows.length > 0) {
|
|
471
|
+
await MetricService.insertJsonRows(metricRows);
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// index metrics
|
|
475
|
+
TelemetryUtil.indexMetricNameServiceNameMap({
|
|
476
|
+
projectId: data.projectId,
|
|
477
|
+
metricNameServiceNameMap: metricNameServiceNameMap,
|
|
478
|
+
}).catch((err: Error) => {
|
|
479
|
+
logger.error(err);
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
}
|