@oneuptime/common 7.0.3985 → 7.0.3993
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/AnalyticsModels/Metric.ts +0 -62
- package/Models/DatabaseModels/MetricType.ts +63 -0
- package/Models/DatabaseModels/OnCallDutyPolicySchedule.ts +137 -0
- package/Models/DatabaseModels/OnCallDutyPolicyScheduleLayer.ts +79 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1743530326936-MigrationName.ts +59 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1743538648415-MigrationName.ts +19 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +4 -0
- package/Server/Services/AlertService.ts +58 -36
- package/Server/Services/IncidentService.ts +49 -9
- package/Server/Utils/Monitor/MonitorResource.ts +93 -33
- package/Server/Utils/Telemetry/Telemetry.ts +32 -9
- package/UI/Components/ModelTable/BaseModelTable.tsx +4 -1
- package/build/dist/Models/AnalyticsModels/Metric.js +0 -56
- package/build/dist/Models/AnalyticsModels/Metric.js.map +1 -1
- package/build/dist/Models/DatabaseModels/MetricType.js +67 -0
- package/build/dist/Models/DatabaseModels/MetricType.js.map +1 -1
- package/build/dist/Models/DatabaseModels/OnCallDutyPolicySchedule.js +141 -0
- package/build/dist/Models/DatabaseModels/OnCallDutyPolicySchedule.js.map +1 -1
- package/build/dist/Models/DatabaseModels/OnCallDutyPolicyScheduleLayer.js +82 -0
- package/build/dist/Models/DatabaseModels/OnCallDutyPolicyScheduleLayer.js.map +1 -1
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1743530326936-MigrationName.js +26 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1743530326936-MigrationName.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1743538648415-MigrationName.js +14 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1743538648415-MigrationName.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +4 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
- package/build/dist/Server/Services/AlertService.js +52 -32
- package/build/dist/Server/Services/AlertService.js.map +1 -1
- package/build/dist/Server/Services/IncidentService.js +38 -9
- package/build/dist/Server/Services/IncidentService.js.map +1 -1
- package/build/dist/Server/Utils/Monitor/MonitorResource.js +56 -31
- package/build/dist/Server/Utils/Monitor/MonitorResource.js.map +1 -1
- package/build/dist/Server/Utils/Telemetry/Telemetry.js +25 -4
- package/build/dist/Server/Utils/Telemetry/Telemetry.js.map +1 -1
- package/build/dist/UI/Components/ModelTable/BaseModelTable.js +4 -1
- package/build/dist/UI/Components/ModelTable/BaseModelTable.js.map +1 -1
- package/package.json +2 -2
|
@@ -52,6 +52,8 @@ import Monitor from "../../Models/DatabaseModels/Monitor";
|
|
|
52
52
|
import MonitorService from "./MonitorService";
|
|
53
53
|
import { MessageBlocksByWorkspaceType } from "./WorkspaceNotificationRuleService";
|
|
54
54
|
import CaptureSpan from "../Utils/Telemetry/CaptureSpan";
|
|
55
|
+
import MetricType from "../../Models/DatabaseModels/MetricType";
|
|
56
|
+
import Dictionary from "../../Types/Dictionary";
|
|
55
57
|
|
|
56
58
|
export class Service extends DatabaseService<Model> {
|
|
57
59
|
public constructor() {
|
|
@@ -946,8 +948,8 @@ ${alertSeverity.name}
|
|
|
946
948
|
name: true,
|
|
947
949
|
},
|
|
948
950
|
alertSeverity: {
|
|
949
|
-
name: true,
|
|
950
951
|
_id: true,
|
|
952
|
+
name: true,
|
|
951
953
|
},
|
|
952
954
|
},
|
|
953
955
|
props: {
|
|
@@ -960,11 +962,10 @@ ${alertSeverity.name}
|
|
|
960
962
|
}
|
|
961
963
|
|
|
962
964
|
if (!alert.projectId) {
|
|
963
|
-
throw new BadDataException("
|
|
965
|
+
throw new BadDataException("Alert Project ID not found");
|
|
964
966
|
}
|
|
965
967
|
|
|
966
968
|
// get alert state timeline
|
|
967
|
-
|
|
968
969
|
const alertStateTimelines: Array<AlertStateTimeline> =
|
|
969
970
|
await AlertStateTimelineService.findBy({
|
|
970
971
|
query: {
|
|
@@ -993,8 +994,7 @@ ${alertSeverity.name}
|
|
|
993
994
|
const firstAlertStateTimeline: AlertStateTimeline | undefined =
|
|
994
995
|
alertStateTimelines[0];
|
|
995
996
|
|
|
996
|
-
// delete all the alert metrics with this alert id because
|
|
997
|
-
|
|
997
|
+
// delete all the alert metrics with this alert id because it's a refresh
|
|
998
998
|
await MetricService.deleteBy({
|
|
999
999
|
query: {
|
|
1000
1000
|
serviceId: data.alertId,
|
|
@@ -1005,9 +1005,9 @@ ${alertSeverity.name}
|
|
|
1005
1005
|
});
|
|
1006
1006
|
|
|
1007
1007
|
const itemsToSave: Array<Metric> = [];
|
|
1008
|
+
const metricTypesMap: Dictionary<MetricType> = {};
|
|
1008
1009
|
|
|
1009
1010
|
// now we need to create new metrics for this alert - TimeToAcknowledge, TimeToResolve, AlertCount, AlertDuration
|
|
1010
|
-
|
|
1011
1011
|
const alertStartsAt: Date =
|
|
1012
1012
|
firstAlertStateTimeline?.startsAt ||
|
|
1013
1013
|
alert.createdAt ||
|
|
@@ -1019,16 +1019,14 @@ ${alertSeverity.name}
|
|
|
1019
1019
|
alertCountMetric.serviceId = alert.id!;
|
|
1020
1020
|
alertCountMetric.serviceType = ServiceType.Alert;
|
|
1021
1021
|
alertCountMetric.name = AlertMetricType.AlertCount;
|
|
1022
|
-
alertCountMetric.description = "Number of alerts created";
|
|
1023
1022
|
alertCountMetric.value = 1;
|
|
1024
|
-
alertCountMetric.unit = "";
|
|
1025
1023
|
alertCountMetric.attributes = {
|
|
1026
1024
|
alertId: data.alertId.toString(),
|
|
1027
1025
|
projectId: alert.projectId.toString(),
|
|
1028
|
-
monitorId: alert.monitor?.
|
|
1029
|
-
monitorName: alert.monitor?.name
|
|
1030
|
-
alertSeverityId: alert.alertSeverity?.
|
|
1031
|
-
alertSeverityName: alert.alertSeverity?.name
|
|
1026
|
+
monitorId: alert.monitor?._id?.toString(),
|
|
1027
|
+
monitorName: alert.monitor?.name?.toString(),
|
|
1028
|
+
alertSeverityId: alert.alertSeverity?._id?.toString(),
|
|
1029
|
+
alertSeverityName: alert.alertSeverity?.name?.toString(),
|
|
1032
1030
|
};
|
|
1033
1031
|
|
|
1034
1032
|
alertCountMetric.time = alertStartsAt;
|
|
@@ -1039,6 +1037,13 @@ ${alertSeverity.name}
|
|
|
1039
1037
|
|
|
1040
1038
|
itemsToSave.push(alertCountMetric);
|
|
1041
1039
|
|
|
1040
|
+
const metricType: MetricType = new MetricType();
|
|
1041
|
+
metricType.name = alertCountMetric.name;
|
|
1042
|
+
metricType.description = "Number of alerts created";
|
|
1043
|
+
metricType.unit = "";
|
|
1044
|
+
metricType.telemetryServices = [];
|
|
1045
|
+
metricTypesMap[alertCountMetric.name] = metricType;
|
|
1046
|
+
|
|
1042
1047
|
// is the alert acknowledged?
|
|
1043
1048
|
const isAlertAcknowledged: boolean = alertStateTimelines.some(
|
|
1044
1049
|
(timeline: AlertStateTimeline) => {
|
|
@@ -1059,20 +1064,17 @@ ${alertSeverity.name}
|
|
|
1059
1064
|
timeToAcknowledgeMetric.serviceId = alert.id!;
|
|
1060
1065
|
timeToAcknowledgeMetric.serviceType = ServiceType.Alert;
|
|
1061
1066
|
timeToAcknowledgeMetric.name = AlertMetricType.TimeToAcknowledge;
|
|
1062
|
-
timeToAcknowledgeMetric.description =
|
|
1063
|
-
"Time taken to acknowledge the alert";
|
|
1064
1067
|
timeToAcknowledgeMetric.value = OneUptimeDate.getDifferenceInSeconds(
|
|
1065
1068
|
ackAlertStateTimeline?.startsAt || OneUptimeDate.getCurrentDate(),
|
|
1066
1069
|
alertStartsAt,
|
|
1067
1070
|
);
|
|
1068
|
-
timeToAcknowledgeMetric.unit = "seconds";
|
|
1069
1071
|
timeToAcknowledgeMetric.attributes = {
|
|
1070
1072
|
alertId: data.alertId.toString(),
|
|
1071
1073
|
projectId: alert.projectId.toString(),
|
|
1072
|
-
monitorId: alert.monitor?.
|
|
1073
|
-
monitorName: alert.monitor?.name
|
|
1074
|
-
alertSeverityId: alert.alertSeverity?.
|
|
1075
|
-
alertSeverityName: alert.alertSeverity?.name
|
|
1074
|
+
monitorId: alert.monitor?._id?.toString(),
|
|
1075
|
+
monitorName: alert.monitor?.name?.toString(),
|
|
1076
|
+
alertSeverityId: alert.alertSeverity?._id?.toString(),
|
|
1077
|
+
alertSeverityName: alert.alertSeverity?.name?.toString(),
|
|
1076
1078
|
};
|
|
1077
1079
|
|
|
1078
1080
|
timeToAcknowledgeMetric.time =
|
|
@@ -1085,6 +1087,12 @@ ${alertSeverity.name}
|
|
|
1085
1087
|
timeToAcknowledgeMetric.metricPointType = MetricPointType.Sum;
|
|
1086
1088
|
|
|
1087
1089
|
itemsToSave.push(timeToAcknowledgeMetric);
|
|
1090
|
+
|
|
1091
|
+
const metricType: MetricType = new MetricType();
|
|
1092
|
+
metricType.name = timeToAcknowledgeMetric.name;
|
|
1093
|
+
metricType.description = "Time taken to acknowledge the alert";
|
|
1094
|
+
metricType.unit = "seconds";
|
|
1095
|
+
metricTypesMap[timeToAcknowledgeMetric.name] = metricType;
|
|
1088
1096
|
}
|
|
1089
1097
|
}
|
|
1090
1098
|
|
|
@@ -1108,20 +1116,18 @@ ${alertSeverity.name}
|
|
|
1108
1116
|
timeToResolveMetric.serviceId = alert.id!;
|
|
1109
1117
|
timeToResolveMetric.serviceType = ServiceType.Alert;
|
|
1110
1118
|
timeToResolveMetric.name = AlertMetricType.TimeToResolve;
|
|
1111
|
-
timeToResolveMetric.description = "Time taken to resolve the alert";
|
|
1112
1119
|
timeToResolveMetric.value = OneUptimeDate.getDifferenceInSeconds(
|
|
1113
1120
|
resolvedAlertStateTimeline?.startsAt ||
|
|
1114
1121
|
OneUptimeDate.getCurrentDate(),
|
|
1115
1122
|
alertStartsAt,
|
|
1116
1123
|
);
|
|
1117
|
-
timeToResolveMetric.unit = "seconds";
|
|
1118
1124
|
timeToResolveMetric.attributes = {
|
|
1119
1125
|
alertId: data.alertId.toString(),
|
|
1120
1126
|
projectId: alert.projectId.toString(),
|
|
1121
|
-
monitorId: alert.monitor?.
|
|
1122
|
-
monitorName: alert.monitor?.name
|
|
1123
|
-
alertSeverityId: alert.alertSeverity?.
|
|
1124
|
-
alertSeverityName: alert.alertSeverity?.name
|
|
1127
|
+
monitorId: alert.monitor?._id?.toString(),
|
|
1128
|
+
monitorName: alert.monitor?.name?.toString(),
|
|
1129
|
+
alertSeverityId: alert.alertSeverity?._id?.toString(),
|
|
1130
|
+
alertSeverityName: alert.alertSeverity?.name?.toString(),
|
|
1125
1131
|
};
|
|
1126
1132
|
|
|
1127
1133
|
timeToResolveMetric.time =
|
|
@@ -1134,11 +1140,16 @@ ${alertSeverity.name}
|
|
|
1134
1140
|
timeToResolveMetric.metricPointType = MetricPointType.Sum;
|
|
1135
1141
|
|
|
1136
1142
|
itemsToSave.push(timeToResolveMetric);
|
|
1143
|
+
|
|
1144
|
+
const metricType: MetricType = new MetricType();
|
|
1145
|
+
metricType.name = timeToResolveMetric.name;
|
|
1146
|
+
metricType.description = "Time taken to resolve the alert";
|
|
1147
|
+
metricType.unit = "seconds";
|
|
1148
|
+
metricTypesMap[timeToResolveMetric.name] = metricType;
|
|
1137
1149
|
}
|
|
1138
1150
|
}
|
|
1139
1151
|
|
|
1140
1152
|
// alert duration
|
|
1141
|
-
|
|
1142
1153
|
const alertDurationMetric: Metric = new Metric();
|
|
1143
1154
|
|
|
1144
1155
|
const lastAlertStateTimeline: AlertStateTimeline | undefined =
|
|
@@ -1148,25 +1159,21 @@ ${alertSeverity.name}
|
|
|
1148
1159
|
const alertEndsAt: Date =
|
|
1149
1160
|
lastAlertStateTimeline.startsAt || OneUptimeDate.getCurrentDate();
|
|
1150
1161
|
|
|
1151
|
-
// save metric.
|
|
1152
|
-
|
|
1153
1162
|
alertDurationMetric.projectId = alert.projectId;
|
|
1154
1163
|
alertDurationMetric.serviceId = alert.id!;
|
|
1155
1164
|
alertDurationMetric.serviceType = ServiceType.Alert;
|
|
1156
1165
|
alertDurationMetric.name = AlertMetricType.AlertDuration;
|
|
1157
|
-
alertDurationMetric.description = "Duration of the alert";
|
|
1158
1166
|
alertDurationMetric.value = OneUptimeDate.getDifferenceInSeconds(
|
|
1159
1167
|
alertEndsAt,
|
|
1160
1168
|
alertStartsAt,
|
|
1161
1169
|
);
|
|
1162
|
-
alertDurationMetric.unit = "seconds";
|
|
1163
1170
|
alertDurationMetric.attributes = {
|
|
1164
1171
|
alertId: data.alertId.toString(),
|
|
1165
1172
|
projectId: alert.projectId.toString(),
|
|
1166
|
-
monitorId: alert.monitor?.
|
|
1167
|
-
monitorName: alert.monitor?.name
|
|
1168
|
-
alertSeverityId: alert.alertSeverity?.
|
|
1169
|
-
alertSeverityName: alert.alertSeverity?.name
|
|
1173
|
+
monitorId: alert.monitor?._id?.toString(),
|
|
1174
|
+
monitorName: alert.monitor?.name?.toString(),
|
|
1175
|
+
alertSeverityId: alert.alertSeverity?._id?.toString(),
|
|
1176
|
+
alertSeverityName: alert.alertSeverity?.name?.toString(),
|
|
1170
1177
|
};
|
|
1171
1178
|
|
|
1172
1179
|
alertDurationMetric.time =
|
|
@@ -1177,6 +1184,14 @@ ${alertSeverity.name}
|
|
|
1177
1184
|
alertDurationMetric.time,
|
|
1178
1185
|
);
|
|
1179
1186
|
alertDurationMetric.metricPointType = MetricPointType.Sum;
|
|
1187
|
+
|
|
1188
|
+
itemsToSave.push(alertDurationMetric);
|
|
1189
|
+
|
|
1190
|
+
const metricType: MetricType = new MetricType();
|
|
1191
|
+
metricType.name = alertDurationMetric.name;
|
|
1192
|
+
metricType.description = "Duration of the alert";
|
|
1193
|
+
metricType.unit = "seconds";
|
|
1194
|
+
metricTypesMap[alertDurationMetric.name] = metricType;
|
|
1180
1195
|
}
|
|
1181
1196
|
|
|
1182
1197
|
await MetricService.createMany({
|
|
@@ -1186,14 +1201,21 @@ ${alertSeverity.name}
|
|
|
1186
1201
|
},
|
|
1187
1202
|
});
|
|
1188
1203
|
|
|
1189
|
-
// index attributes
|
|
1204
|
+
// index attributes
|
|
1190
1205
|
TelemetryUtil.indexAttributes({
|
|
1191
|
-
attributes: ["monitorId", "projectId", "alertId", "
|
|
1206
|
+
attributes: ["monitorId", "projectId", "alertId", "monitorName"],
|
|
1192
1207
|
projectId: alert.projectId,
|
|
1193
1208
|
telemetryType: TelemetryType.Metric,
|
|
1194
1209
|
}).catch((err: Error) => {
|
|
1195
1210
|
logger.error(err);
|
|
1196
1211
|
});
|
|
1212
|
+
|
|
1213
|
+
TelemetryUtil.indexMetricNameServiceNameMap({
|
|
1214
|
+
metricNameServiceNameMap: metricTypesMap,
|
|
1215
|
+
projectId: alert.projectId,
|
|
1216
|
+
}).catch((err: Error) => {
|
|
1217
|
+
logger.error(err);
|
|
1218
|
+
});
|
|
1197
1219
|
}
|
|
1198
1220
|
|
|
1199
1221
|
@CaptureSpan()
|
|
@@ -59,6 +59,8 @@ import WorkspaceType from "../../Types/Workspace/WorkspaceType";
|
|
|
59
59
|
import { MessageBlocksByWorkspaceType } from "./WorkspaceNotificationRuleService";
|
|
60
60
|
import NotificationRuleWorkspaceChannel from "../../Types/Workspace/NotificationRules/NotificationRuleWorkspaceChannel";
|
|
61
61
|
import CaptureSpan from "../Utils/Telemetry/CaptureSpan";
|
|
62
|
+
import { Dictionary } from "lodash";
|
|
63
|
+
import MetricType from "../../Models/DatabaseModels/MetricType";
|
|
62
64
|
|
|
63
65
|
export class Service extends DatabaseService<Model> {
|
|
64
66
|
public constructor() {
|
|
@@ -1327,15 +1329,15 @@ ${incidentSeverity.name}
|
|
|
1327
1329
|
incident.createdAt ||
|
|
1328
1330
|
OneUptimeDate.getCurrentDate();
|
|
1329
1331
|
|
|
1332
|
+
const metricTypesMap: Dictionary<MetricType> = {};
|
|
1333
|
+
|
|
1330
1334
|
const incidentCountMetric: Metric = new Metric();
|
|
1331
1335
|
|
|
1332
1336
|
incidentCountMetric.projectId = incident.projectId;
|
|
1333
1337
|
incidentCountMetric.serviceId = incident.id!;
|
|
1334
1338
|
incidentCountMetric.serviceType = ServiceType.Incident;
|
|
1335
1339
|
incidentCountMetric.name = IncidentMetricType.IncidentCount;
|
|
1336
|
-
incidentCountMetric.description = "Number of incidents created";
|
|
1337
1340
|
incidentCountMetric.value = 1;
|
|
1338
|
-
incidentCountMetric.unit = "";
|
|
1339
1341
|
incidentCountMetric.attributes = {
|
|
1340
1342
|
incidentId: data.incidentId.toString(),
|
|
1341
1343
|
projectId: incident.projectId.toString(),
|
|
@@ -1359,6 +1361,16 @@ ${incidentSeverity.name}
|
|
|
1359
1361
|
|
|
1360
1362
|
itemsToSave.push(incidentCountMetric);
|
|
1361
1363
|
|
|
1364
|
+
// add metric type for this to map.
|
|
1365
|
+
const metricType: MetricType = new MetricType();
|
|
1366
|
+
metricType.name = incidentCountMetric.name;
|
|
1367
|
+
metricType.description = "Number of incidents created";
|
|
1368
|
+
metricType.unit = "";
|
|
1369
|
+
metricType.telemetryServices = [];
|
|
1370
|
+
|
|
1371
|
+
// add to map.
|
|
1372
|
+
metricTypesMap[incidentCountMetric.name] = metricType;
|
|
1373
|
+
|
|
1362
1374
|
// is the incident acknowledged?
|
|
1363
1375
|
const isIncidentAcknowledged: boolean = incidentStateTimelines.some(
|
|
1364
1376
|
(timeline: IncidentStateTimeline) => {
|
|
@@ -1379,13 +1391,10 @@ ${incidentSeverity.name}
|
|
|
1379
1391
|
timeToAcknowledgeMetric.serviceId = incident.id!;
|
|
1380
1392
|
timeToAcknowledgeMetric.serviceType = ServiceType.Incident;
|
|
1381
1393
|
timeToAcknowledgeMetric.name = IncidentMetricType.TimeToAcknowledge;
|
|
1382
|
-
timeToAcknowledgeMetric.description =
|
|
1383
|
-
"Time taken to acknowledge the incident";
|
|
1384
1394
|
timeToAcknowledgeMetric.value = OneUptimeDate.getDifferenceInSeconds(
|
|
1385
1395
|
ackIncidentStateTimeline?.startsAt || OneUptimeDate.getCurrentDate(),
|
|
1386
1396
|
incidentStartsAt,
|
|
1387
1397
|
);
|
|
1388
|
-
timeToAcknowledgeMetric.unit = "seconds";
|
|
1389
1398
|
timeToAcknowledgeMetric.attributes = {
|
|
1390
1399
|
incidentId: data.incidentId.toString(),
|
|
1391
1400
|
projectId: incident.projectId.toString(),
|
|
@@ -1411,6 +1420,15 @@ ${incidentSeverity.name}
|
|
|
1411
1420
|
timeToAcknowledgeMetric.metricPointType = MetricPointType.Sum;
|
|
1412
1421
|
|
|
1413
1422
|
itemsToSave.push(timeToAcknowledgeMetric);
|
|
1423
|
+
|
|
1424
|
+
// add metric type for this to map.
|
|
1425
|
+
const metricType: MetricType = new MetricType();
|
|
1426
|
+
metricType.name = timeToAcknowledgeMetric.name;
|
|
1427
|
+
metricType.description = "Time taken to acknowledge the incident";
|
|
1428
|
+
metricType.unit = "seconds";
|
|
1429
|
+
|
|
1430
|
+
// add to map.
|
|
1431
|
+
metricTypesMap[timeToAcknowledgeMetric.name] = metricType;
|
|
1414
1432
|
}
|
|
1415
1433
|
}
|
|
1416
1434
|
|
|
@@ -1434,13 +1452,11 @@ ${incidentSeverity.name}
|
|
|
1434
1452
|
timeToResolveMetric.serviceId = incident.id!;
|
|
1435
1453
|
timeToResolveMetric.serviceType = ServiceType.Incident;
|
|
1436
1454
|
timeToResolveMetric.name = IncidentMetricType.TimeToResolve;
|
|
1437
|
-
timeToResolveMetric.description = "Time taken to resolve the incident";
|
|
1438
1455
|
timeToResolveMetric.value = OneUptimeDate.getDifferenceInSeconds(
|
|
1439
1456
|
resolvedIncidentStateTimeline?.startsAt ||
|
|
1440
1457
|
OneUptimeDate.getCurrentDate(),
|
|
1441
1458
|
incidentStartsAt,
|
|
1442
1459
|
);
|
|
1443
|
-
timeToResolveMetric.unit = "seconds";
|
|
1444
1460
|
timeToResolveMetric.attributes = {
|
|
1445
1461
|
incidentId: data.incidentId.toString(),
|
|
1446
1462
|
projectId: incident.projectId.toString(),
|
|
@@ -1466,6 +1482,14 @@ ${incidentSeverity.name}
|
|
|
1466
1482
|
timeToResolveMetric.metricPointType = MetricPointType.Sum;
|
|
1467
1483
|
|
|
1468
1484
|
itemsToSave.push(timeToResolveMetric);
|
|
1485
|
+
|
|
1486
|
+
// add metric type for this to map.
|
|
1487
|
+
const metricType: MetricType = new MetricType();
|
|
1488
|
+
metricType.name = timeToResolveMetric.name;
|
|
1489
|
+
metricType.description = "Time taken to resolve the incident";
|
|
1490
|
+
metricType.unit = "seconds";
|
|
1491
|
+
// add to map.
|
|
1492
|
+
metricTypesMap[timeToResolveMetric.name] = metricType;
|
|
1469
1493
|
}
|
|
1470
1494
|
}
|
|
1471
1495
|
|
|
@@ -1486,12 +1510,10 @@ ${incidentSeverity.name}
|
|
|
1486
1510
|
incidentDurationMetric.serviceId = incident.id!;
|
|
1487
1511
|
incidentDurationMetric.serviceType = ServiceType.Incident;
|
|
1488
1512
|
incidentDurationMetric.name = IncidentMetricType.IncidentDuration;
|
|
1489
|
-
incidentDurationMetric.description = "Duration of the incident";
|
|
1490
1513
|
incidentDurationMetric.value = OneUptimeDate.getDifferenceInSeconds(
|
|
1491
1514
|
incidentEndsAt,
|
|
1492
1515
|
incidentStartsAt,
|
|
1493
1516
|
);
|
|
1494
|
-
incidentDurationMetric.unit = "seconds";
|
|
1495
1517
|
incidentDurationMetric.attributes = {
|
|
1496
1518
|
incidentId: data.incidentId.toString(),
|
|
1497
1519
|
projectId: incident.projectId.toString(),
|
|
@@ -1515,6 +1537,17 @@ ${incidentSeverity.name}
|
|
|
1515
1537
|
incidentDurationMetric.time,
|
|
1516
1538
|
);
|
|
1517
1539
|
incidentDurationMetric.metricPointType = MetricPointType.Sum;
|
|
1540
|
+
|
|
1541
|
+
itemsToSave.push(incidentDurationMetric);
|
|
1542
|
+
|
|
1543
|
+
// add metric type for this to map.
|
|
1544
|
+
const metricType: MetricType = new MetricType();
|
|
1545
|
+
metricType.name = incidentDurationMetric.name;
|
|
1546
|
+
metricType.description = "Duration of the incident";
|
|
1547
|
+
metricType.unit = "seconds";
|
|
1548
|
+
|
|
1549
|
+
// add to map.
|
|
1550
|
+
metricTypesMap[incidentDurationMetric.name] = metricType;
|
|
1518
1551
|
}
|
|
1519
1552
|
|
|
1520
1553
|
await MetricService.createMany({
|
|
@@ -1532,6 +1565,13 @@ ${incidentSeverity.name}
|
|
|
1532
1565
|
}).catch((err: Error) => {
|
|
1533
1566
|
logger.error(err);
|
|
1534
1567
|
});
|
|
1568
|
+
|
|
1569
|
+
TelemetryUtil.indexMetricNameServiceNameMap({
|
|
1570
|
+
metricNameServiceNameMap: metricTypesMap,
|
|
1571
|
+
projectId: incident.projectId,
|
|
1572
|
+
}).catch((err: Error) => {
|
|
1573
|
+
logger.error(err);
|
|
1574
|
+
});
|
|
1535
1575
|
}
|
|
1536
1576
|
|
|
1537
1577
|
@CaptureSpan()
|
|
@@ -55,6 +55,7 @@ import MetricMonitorCriteria from "./Criteria/MetricMonitorCriteria";
|
|
|
55
55
|
import MetricMonitorResponse from "../../../Types/Monitor/MetricMonitor/MetricMonitorResponse";
|
|
56
56
|
import FilterCondition from "../../../Types/Filter/FilterCondition";
|
|
57
57
|
import CaptureSpan from "../Telemetry/CaptureSpan";
|
|
58
|
+
import MetricType from "../../../Models/DatabaseModels/MetricType";
|
|
58
59
|
|
|
59
60
|
export default class MonitorResourceUtil {
|
|
60
61
|
@CaptureSpan()
|
|
@@ -621,6 +622,11 @@ export default class MonitorResourceUtil {
|
|
|
621
622
|
|
|
622
623
|
const itemsToSave: Array<Metric> = [];
|
|
623
624
|
|
|
625
|
+
// Metric name to serviceId map
|
|
626
|
+
// example: "cpu.usage" -> [serviceId1, serviceId2]
|
|
627
|
+
// since these are monitor metrics. They dont belong to any service so we can keep the array empty.
|
|
628
|
+
const metricNameServiceNameMap: Dictionary<MetricType> = {};
|
|
629
|
+
|
|
624
630
|
if (
|
|
625
631
|
(data.dataToProcess as ServerMonitorResponse).basicInfrastructureMetrics
|
|
626
632
|
) {
|
|
@@ -645,9 +651,9 @@ export default class MonitorResourceUtil {
|
|
|
645
651
|
monitorMetric.serviceId = data.monitorId;
|
|
646
652
|
monitorMetric.serviceType = ServiceType.Monitor;
|
|
647
653
|
monitorMetric.name = MonitorMetricType.IsOnline;
|
|
648
|
-
|
|
654
|
+
|
|
649
655
|
monitorMetric.value = isOnline ? 1 : 0;
|
|
650
|
-
|
|
656
|
+
|
|
651
657
|
monitorMetric.attributes = {
|
|
652
658
|
monitorId: data.monitorId.toString(),
|
|
653
659
|
projectId: data.projectId.toString(),
|
|
@@ -666,6 +672,15 @@ export default class MonitorResourceUtil {
|
|
|
666
672
|
monitorMetric.metricPointType = MetricPointType.Sum;
|
|
667
673
|
|
|
668
674
|
itemsToSave.push(monitorMetric);
|
|
675
|
+
|
|
676
|
+
// add MetricType
|
|
677
|
+
const metricType: MetricType = new MetricType();
|
|
678
|
+
metricType.name = MonitorMetricType.IsOnline;
|
|
679
|
+
metricType.description = CheckOn.IsOnline + " status for monitor";
|
|
680
|
+
metricType.unit = "";
|
|
681
|
+
|
|
682
|
+
// add to map
|
|
683
|
+
metricNameServiceNameMap[MonitorMetricType.IsOnline] = metricType;
|
|
669
684
|
}
|
|
670
685
|
|
|
671
686
|
const basicMetrics: BasicInfrastructureMetrics | undefined = (
|
|
@@ -683,9 +698,9 @@ export default class MonitorResourceUtil {
|
|
|
683
698
|
monitorMetric.serviceId = data.monitorId;
|
|
684
699
|
monitorMetric.serviceType = ServiceType.Monitor;
|
|
685
700
|
monitorMetric.name = MonitorMetricType.CPUUsagePercent;
|
|
686
|
-
|
|
701
|
+
|
|
687
702
|
monitorMetric.value = basicMetrics.cpuMetrics.percentUsed;
|
|
688
|
-
|
|
703
|
+
|
|
689
704
|
monitorMetric.attributes = {
|
|
690
705
|
monitorId: data.monitorId.toString(),
|
|
691
706
|
projectId: data.projectId.toString(),
|
|
@@ -704,6 +719,14 @@ export default class MonitorResourceUtil {
|
|
|
704
719
|
monitorMetric.metricPointType = MetricPointType.Sum;
|
|
705
720
|
|
|
706
721
|
itemsToSave.push(monitorMetric);
|
|
722
|
+
|
|
723
|
+
const metricType: MetricType = new MetricType();
|
|
724
|
+
metricType.name = MonitorMetricType.CPUUsagePercent;
|
|
725
|
+
metricType.description = CheckOn.CPUUsagePercent + " of Server/VM";
|
|
726
|
+
metricType.unit = "%";
|
|
727
|
+
|
|
728
|
+
metricNameServiceNameMap[MonitorMetricType.CPUUsagePercent] =
|
|
729
|
+
metricType;
|
|
707
730
|
}
|
|
708
731
|
|
|
709
732
|
if (basicMetrics.memoryMetrics) {
|
|
@@ -713,10 +736,9 @@ export default class MonitorResourceUtil {
|
|
|
713
736
|
monitorMetric.serviceId = data.monitorId;
|
|
714
737
|
monitorMetric.serviceType = ServiceType.Monitor;
|
|
715
738
|
monitorMetric.name = MonitorMetricType.MemoryUsagePercent;
|
|
716
|
-
|
|
717
|
-
CheckOn.MemoryUsagePercent + " of Server/VM";
|
|
739
|
+
|
|
718
740
|
monitorMetric.value = basicMetrics.memoryMetrics.percentUsed;
|
|
719
|
-
|
|
741
|
+
|
|
720
742
|
monitorMetric.attributes = {
|
|
721
743
|
monitorId: data.monitorId.toString(),
|
|
722
744
|
projectId: data.projectId.toString(),
|
|
@@ -735,6 +757,14 @@ export default class MonitorResourceUtil {
|
|
|
735
757
|
monitorMetric.metricPointType = MetricPointType.Sum;
|
|
736
758
|
|
|
737
759
|
itemsToSave.push(monitorMetric);
|
|
760
|
+
|
|
761
|
+
const metricType: MetricType = new MetricType();
|
|
762
|
+
metricType.name = MonitorMetricType.MemoryUsagePercent;
|
|
763
|
+
metricType.description = CheckOn.MemoryUsagePercent + " of Server/VM";
|
|
764
|
+
metricType.unit = "%";
|
|
765
|
+
|
|
766
|
+
metricNameServiceNameMap[MonitorMetricType.MemoryUsagePercent] =
|
|
767
|
+
metricType;
|
|
738
768
|
}
|
|
739
769
|
|
|
740
770
|
if (basicMetrics.diskMetrics && basicMetrics.diskMetrics.length > 0) {
|
|
@@ -745,10 +775,9 @@ export default class MonitorResourceUtil {
|
|
|
745
775
|
monitorMetric.serviceId = data.monitorId;
|
|
746
776
|
monitorMetric.serviceType = ServiceType.Monitor;
|
|
747
777
|
monitorMetric.name = MonitorMetricType.DiskUsagePercent;
|
|
748
|
-
|
|
749
|
-
CheckOn.DiskUsagePercent + " of Server/VM";
|
|
778
|
+
|
|
750
779
|
monitorMetric.value = diskMetric.percentUsed;
|
|
751
|
-
|
|
780
|
+
|
|
752
781
|
monitorMetric.attributes = {
|
|
753
782
|
monitorId: data.monitorId.toString(),
|
|
754
783
|
projectId: data.projectId.toString(),
|
|
@@ -769,6 +798,14 @@ export default class MonitorResourceUtil {
|
|
|
769
798
|
monitorMetric.metricPointType = MetricPointType.Sum;
|
|
770
799
|
|
|
771
800
|
itemsToSave.push(monitorMetric);
|
|
801
|
+
|
|
802
|
+
const metricType: MetricType = new MetricType();
|
|
803
|
+
metricType.name = MonitorMetricType.DiskUsagePercent;
|
|
804
|
+
metricType.description = CheckOn.DiskUsagePercent + " of Server/VM";
|
|
805
|
+
metricType.unit = "%";
|
|
806
|
+
|
|
807
|
+
metricNameServiceNameMap[MonitorMetricType.DiskUsagePercent] =
|
|
808
|
+
metricType;
|
|
772
809
|
}
|
|
773
810
|
}
|
|
774
811
|
}
|
|
@@ -783,11 +820,11 @@ export default class MonitorResourceUtil {
|
|
|
783
820
|
monitorMetric.serviceId = data.monitorId;
|
|
784
821
|
monitorMetric.serviceType = ServiceType.Monitor;
|
|
785
822
|
monitorMetric.name = MonitorMetricType.ExecutionTime;
|
|
786
|
-
|
|
823
|
+
|
|
787
824
|
monitorMetric.value = (
|
|
788
825
|
data.dataToProcess as ProbeMonitorResponse
|
|
789
826
|
).customCodeMonitorResponse?.executionTimeInMS;
|
|
790
|
-
|
|
827
|
+
|
|
791
828
|
monitorMetric.attributes = {
|
|
792
829
|
monitorId: data.monitorId.toString(),
|
|
793
830
|
projectId: data.projectId.toString(),
|
|
@@ -809,6 +846,13 @@ export default class MonitorResourceUtil {
|
|
|
809
846
|
monitorMetric.metricPointType = MetricPointType.Sum;
|
|
810
847
|
|
|
811
848
|
itemsToSave.push(monitorMetric);
|
|
849
|
+
|
|
850
|
+
const metricType: MetricType = new MetricType();
|
|
851
|
+
metricType.name = MonitorMetricType.ExecutionTime;
|
|
852
|
+
metricType.description = CheckOn.ExecutionTime + " of this monitor";
|
|
853
|
+
metricType.unit = "ms";
|
|
854
|
+
|
|
855
|
+
metricNameServiceNameMap[MonitorMetricType.ExecutionTime] = metricType;
|
|
812
856
|
}
|
|
813
857
|
|
|
814
858
|
if (
|
|
@@ -828,9 +872,9 @@ export default class MonitorResourceUtil {
|
|
|
828
872
|
monitorMetric.serviceId = data.monitorId;
|
|
829
873
|
monitorMetric.serviceType = ServiceType.Monitor;
|
|
830
874
|
monitorMetric.name = MonitorMetricType.ExecutionTime;
|
|
831
|
-
|
|
875
|
+
|
|
832
876
|
monitorMetric.value = syntheticMonitorResponse.executionTimeInMS;
|
|
833
|
-
|
|
877
|
+
|
|
834
878
|
monitorMetric.attributes = {
|
|
835
879
|
monitorId: data.monitorId.toString(),
|
|
836
880
|
projectId: data.projectId.toString(),
|
|
@@ -854,6 +898,13 @@ export default class MonitorResourceUtil {
|
|
|
854
898
|
monitorMetric.metricPointType = MetricPointType.Sum;
|
|
855
899
|
|
|
856
900
|
itemsToSave.push(monitorMetric);
|
|
901
|
+
|
|
902
|
+
const metricType: MetricType = new MetricType();
|
|
903
|
+
metricType.name = MonitorMetricType.ExecutionTime;
|
|
904
|
+
metricType.description = CheckOn.ExecutionTime + " of this monitor";
|
|
905
|
+
metricType.unit = "ms";
|
|
906
|
+
|
|
907
|
+
metricNameServiceNameMap[MonitorMetricType.ExecutionTime] = metricType;
|
|
857
908
|
}
|
|
858
909
|
}
|
|
859
910
|
|
|
@@ -864,11 +915,11 @@ export default class MonitorResourceUtil {
|
|
|
864
915
|
monitorMetric.serviceId = data.monitorId;
|
|
865
916
|
monitorMetric.serviceType = ServiceType.Monitor;
|
|
866
917
|
monitorMetric.name = MonitorMetricType.ResponseTime;
|
|
867
|
-
|
|
918
|
+
|
|
868
919
|
monitorMetric.value = (
|
|
869
920
|
data.dataToProcess as ProbeMonitorResponse
|
|
870
921
|
).responseTimeInMs;
|
|
871
|
-
|
|
922
|
+
|
|
872
923
|
monitorMetric.attributes = {
|
|
873
924
|
monitorId: data.monitorId.toString(),
|
|
874
925
|
projectId: data.projectId.toString(),
|
|
@@ -890,6 +941,13 @@ export default class MonitorResourceUtil {
|
|
|
890
941
|
monitorMetric.metricPointType = MetricPointType.Sum;
|
|
891
942
|
|
|
892
943
|
itemsToSave.push(monitorMetric);
|
|
944
|
+
|
|
945
|
+
const metricType: MetricType = new MetricType();
|
|
946
|
+
metricType.name = MonitorMetricType.ResponseTime;
|
|
947
|
+
metricType.description = CheckOn.ResponseTime + " of this monitor";
|
|
948
|
+
metricType.unit = "ms";
|
|
949
|
+
|
|
950
|
+
metricNameServiceNameMap[MonitorMetricType.ResponseTime] = metricType;
|
|
893
951
|
}
|
|
894
952
|
|
|
895
953
|
if ((data.dataToProcess as ProbeMonitorResponse).isOnline !== undefined) {
|
|
@@ -899,12 +957,12 @@ export default class MonitorResourceUtil {
|
|
|
899
957
|
monitorMetric.serviceId = data.monitorId;
|
|
900
958
|
monitorMetric.serviceType = ServiceType.Monitor;
|
|
901
959
|
monitorMetric.name = MonitorMetricType.IsOnline;
|
|
902
|
-
|
|
960
|
+
|
|
903
961
|
monitorMetric.value = (data.dataToProcess as ProbeMonitorResponse)
|
|
904
962
|
.isOnline
|
|
905
963
|
? 1
|
|
906
964
|
: 0;
|
|
907
|
-
|
|
965
|
+
|
|
908
966
|
monitorMetric.attributes = {
|
|
909
967
|
monitorId: data.monitorId.toString(),
|
|
910
968
|
projectId: data.projectId.toString(),
|
|
@@ -926,6 +984,13 @@ export default class MonitorResourceUtil {
|
|
|
926
984
|
monitorMetric.metricPointType = MetricPointType.Sum;
|
|
927
985
|
|
|
928
986
|
itemsToSave.push(monitorMetric);
|
|
987
|
+
|
|
988
|
+
const metricType: MetricType = new MetricType();
|
|
989
|
+
metricType.name = MonitorMetricType.IsOnline;
|
|
990
|
+
metricType.description = CheckOn.IsOnline + " status for monitor";
|
|
991
|
+
metricType.unit = "";
|
|
992
|
+
|
|
993
|
+
metricNameServiceNameMap[MonitorMetricType.IsOnline] = metricType;
|
|
929
994
|
}
|
|
930
995
|
|
|
931
996
|
if ((data.dataToProcess as ProbeMonitorResponse).responseCode) {
|
|
@@ -935,12 +1000,11 @@ export default class MonitorResourceUtil {
|
|
|
935
1000
|
monitorMetric.serviceId = data.monitorId;
|
|
936
1001
|
monitorMetric.serviceType = ServiceType.Monitor;
|
|
937
1002
|
monitorMetric.name = MonitorMetricType.ResponseStatusCode;
|
|
938
|
-
|
|
939
|
-
CheckOn.ResponseStatusCode + " for this monitor";
|
|
1003
|
+
|
|
940
1004
|
monitorMetric.value = (
|
|
941
1005
|
data.dataToProcess as ProbeMonitorResponse
|
|
942
1006
|
).responseCode;
|
|
943
|
-
|
|
1007
|
+
|
|
944
1008
|
monitorMetric.attributes = {
|
|
945
1009
|
monitorId: data.monitorId.toString(),
|
|
946
1010
|
projectId: data.projectId.toString(),
|
|
@@ -954,6 +1018,14 @@ export default class MonitorResourceUtil {
|
|
|
954
1018
|
monitorMetric.metricPointType = MetricPointType.Sum;
|
|
955
1019
|
|
|
956
1020
|
itemsToSave.push(monitorMetric);
|
|
1021
|
+
|
|
1022
|
+
const metricType: MetricType = new MetricType();
|
|
1023
|
+
metricType.name = MonitorMetricType.ResponseStatusCode;
|
|
1024
|
+
metricType.description = CheckOn.ResponseStatusCode + " for this monitor";
|
|
1025
|
+
metricType.unit = "Status Code";
|
|
1026
|
+
|
|
1027
|
+
metricNameServiceNameMap[MonitorMetricType.ResponseStatusCode] =
|
|
1028
|
+
metricType;
|
|
957
1029
|
}
|
|
958
1030
|
|
|
959
1031
|
await MetricService.createMany({
|
|
@@ -963,18 +1035,6 @@ export default class MonitorResourceUtil {
|
|
|
963
1035
|
},
|
|
964
1036
|
});
|
|
965
1037
|
|
|
966
|
-
// Metric name to serviceId map
|
|
967
|
-
// example: "cpu.usage" -> [serviceId1, serviceId2]
|
|
968
|
-
// since these are monitor metrics. They dont belong to any service so we can keep the array empty.
|
|
969
|
-
const metricNameServiceNameMap: Dictionary<Array<ObjectID>> = {};
|
|
970
|
-
|
|
971
|
-
for (const metric of itemsToSave) {
|
|
972
|
-
const metricName: string = metric.name!;
|
|
973
|
-
if (!metricNameServiceNameMap[metricName]) {
|
|
974
|
-
metricNameServiceNameMap[metricName] = [];
|
|
975
|
-
}
|
|
976
|
-
}
|
|
977
|
-
|
|
978
1038
|
// index metrics
|
|
979
1039
|
TelemetryUtil.indexMetricNameServiceNameMap({
|
|
980
1040
|
projectId: data.projectId,
|