@oneuptime/common 8.0.5469 → 8.0.5479
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/Server/Services/DatabaseService.ts +70 -0
- package/Server/Services/ProjectService.ts +24 -0
- package/Server/Types/Database/FindAllBy.ts +25 -0
- package/Server/Utils/CodeRepository/CodeRepository.ts +145 -84
- package/Server/Utils/CodeRepository/GitHub/GitHub.ts +20 -9
- package/Server/Utils/Execute.ts +25 -4
- package/Server/Utils/Monitor/MonitorResource.ts +246 -256
- package/build/dist/Server/Services/DatabaseService.js +59 -0
- package/build/dist/Server/Services/DatabaseService.js.map +1 -1
- package/build/dist/Server/Services/ProjectService.js +19 -0
- package/build/dist/Server/Services/ProjectService.js.map +1 -1
- package/build/dist/Server/Types/Database/FindAllBy.js +2 -0
- package/build/dist/Server/Types/Database/FindAllBy.js.map +1 -0
- package/build/dist/Server/Utils/CodeRepository/CodeRepository.js +107 -56
- package/build/dist/Server/Utils/CodeRepository/CodeRepository.js.map +1 -1
- package/build/dist/Server/Utils/CodeRepository/GitHub/GitHub.js +15 -6
- package/build/dist/Server/Utils/CodeRepository/GitHub/GitHub.js.map +1 -1
- package/build/dist/Server/Utils/Execute.js +10 -4
- package/build/dist/Server/Utils/Execute.js.map +1 -1
- package/build/dist/Server/Utils/Monitor/MonitorResource.js +220 -206
- package/build/dist/Server/Utils/Monitor/MonitorResource.js.map +1 -1
- package/package.json +1 -1
|
@@ -23,6 +23,7 @@ import BadDataException from "../../../Types/Exception/BadDataException";
|
|
|
23
23
|
import Semaphore from "../../Infrastructure/Semaphore";
|
|
24
24
|
import { CheckOn } from "../../../Types/Monitor/CriteriaFilter";
|
|
25
25
|
import MonitorType, { MonitorTypeHelper, } from "../../../Types/Monitor/MonitorType";
|
|
26
|
+
import ObjectID from "../../../Types/ObjectID";
|
|
26
27
|
import Typeof from "../../../Types/Typeof";
|
|
27
28
|
import MonitorStatusTimeline from "../../../Models/DatabaseModels/MonitorStatusTimeline";
|
|
28
29
|
import OneUptimeDate from "../../../Types/Date";
|
|
@@ -32,7 +33,7 @@ import TraceMonitorCriteria from "./Criteria/TraceMonitorCriteria";
|
|
|
32
33
|
import MonitorIncident from "./MonitorIncident";
|
|
33
34
|
import MonitorAlert from "./MonitorAlert";
|
|
34
35
|
import MonitorStatusTimelineUtil from "./MonitorStatusTimeline";
|
|
35
|
-
import
|
|
36
|
+
import { MetricPointType, ServiceType, } from "../../../Models/AnalyticsModels/Metric";
|
|
36
37
|
import MetricService from "../../Services/MetricService";
|
|
37
38
|
import MonitorMetricType from "../../../Types/Monitor/MonitorMetricType";
|
|
38
39
|
import TelemetryUtil from "../Telemetry/Telemetry";
|
|
@@ -40,12 +41,57 @@ import MetricMonitorCriteria from "./Criteria/MetricMonitorCriteria";
|
|
|
40
41
|
import FilterCondition from "../../../Types/Filter/FilterCondition";
|
|
41
42
|
import CaptureSpan from "../Telemetry/CaptureSpan";
|
|
42
43
|
import MetricType from "../../../Models/DatabaseModels/MetricType";
|
|
43
|
-
import MonitorLog from "../../../Models/AnalyticsModels/MonitorLog";
|
|
44
44
|
import MonitorLogService from "../../Services/MonitorLogService";
|
|
45
45
|
import ExceptionMessages from "../../../Types/Exception/ExceptionMessages";
|
|
46
46
|
export default class MonitorResourceUtil {
|
|
47
|
-
static
|
|
48
|
-
|
|
47
|
+
static buildMonitorMetricAttributes(data) {
|
|
48
|
+
const attributes = {
|
|
49
|
+
monitorId: data.monitorId.toString(),
|
|
50
|
+
projectId: data.projectId.toString(),
|
|
51
|
+
};
|
|
52
|
+
if (data.extraAttributes) {
|
|
53
|
+
Object.assign(attributes, data.extraAttributes);
|
|
54
|
+
}
|
|
55
|
+
if (data.monitorName) {
|
|
56
|
+
attributes["monitorName"] = data.monitorName;
|
|
57
|
+
}
|
|
58
|
+
if (data.probeName) {
|
|
59
|
+
attributes["probeName"] = data.probeName;
|
|
60
|
+
}
|
|
61
|
+
return attributes;
|
|
62
|
+
}
|
|
63
|
+
static buildMonitorMetricRow(data) {
|
|
64
|
+
var _a;
|
|
65
|
+
const ingestionDate = OneUptimeDate.getCurrentDate();
|
|
66
|
+
const ingestionTimestamp = OneUptimeDate.toClickhouseDateTime(ingestionDate);
|
|
67
|
+
const timeUnixNano = OneUptimeDate.toUnixNano(ingestionDate).toString();
|
|
68
|
+
const attributes = Object.assign({}, data.attributes);
|
|
69
|
+
const attributeKeys = TelemetryUtil.getAttributeKeys(attributes);
|
|
70
|
+
return {
|
|
71
|
+
_id: ObjectID.generate().toString(),
|
|
72
|
+
createdAt: ingestionTimestamp,
|
|
73
|
+
updatedAt: ingestionTimestamp,
|
|
74
|
+
projectId: data.projectId.toString(),
|
|
75
|
+
serviceId: data.monitorId.toString(),
|
|
76
|
+
serviceType: ServiceType.Monitor,
|
|
77
|
+
name: data.metricName,
|
|
78
|
+
aggregationTemporality: null,
|
|
79
|
+
metricPointType: data.metricPointType || MetricPointType.Sum,
|
|
80
|
+
time: ingestionTimestamp,
|
|
81
|
+
startTime: null,
|
|
82
|
+
timeUnixNano: timeUnixNano,
|
|
83
|
+
startTimeUnixNano: null,
|
|
84
|
+
attributes: attributes,
|
|
85
|
+
attributeKeys: attributeKeys,
|
|
86
|
+
isMonotonic: null,
|
|
87
|
+
count: null,
|
|
88
|
+
sum: null,
|
|
89
|
+
min: null,
|
|
90
|
+
max: null,
|
|
91
|
+
bucketCounts: [],
|
|
92
|
+
explicitBounds: [],
|
|
93
|
+
value: (_a = data.value) !== null && _a !== void 0 ? _a : null,
|
|
94
|
+
};
|
|
49
95
|
}
|
|
50
96
|
static async monitorResource(dataToProcess) {
|
|
51
97
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
@@ -419,7 +465,7 @@ export default class MonitorResourceUtil {
|
|
|
419
465
|
return response;
|
|
420
466
|
}
|
|
421
467
|
static async saveMonitorMetrics(data) {
|
|
422
|
-
var _a, _b;
|
|
468
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
423
469
|
if (!data.monitorId) {
|
|
424
470
|
return;
|
|
425
471
|
}
|
|
@@ -429,7 +475,7 @@ export default class MonitorResourceUtil {
|
|
|
429
475
|
if (!data.dataToProcess) {
|
|
430
476
|
return;
|
|
431
477
|
}
|
|
432
|
-
const
|
|
478
|
+
const metricRows = [];
|
|
433
479
|
/*
|
|
434
480
|
* Metric name to serviceId map
|
|
435
481
|
* example: "cpu.usage" -> [serviceId1, serviceId2]
|
|
@@ -444,27 +490,21 @@ export default class MonitorResourceUtil {
|
|
|
444
490
|
if (differenceInMinutes > 2) {
|
|
445
491
|
isOnline = false;
|
|
446
492
|
}
|
|
447
|
-
const
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
}
|
|
463
|
-
MonitorResourceUtil.setAttributeKeys(monitorMetric);
|
|
464
|
-
monitorMetric.time = OneUptimeDate.getCurrentDate();
|
|
465
|
-
monitorMetric.timeUnixNano = OneUptimeDate.getCurrentDateAsUnixNano();
|
|
466
|
-
monitorMetric.metricPointType = MetricPointType.Sum;
|
|
467
|
-
itemsToSave.push(monitorMetric);
|
|
493
|
+
const attributes = this.buildMonitorMetricAttributes({
|
|
494
|
+
monitorId: data.monitorId,
|
|
495
|
+
projectId: data.projectId,
|
|
496
|
+
monitorName: data.monitorName,
|
|
497
|
+
probeName: data.probeName,
|
|
498
|
+
});
|
|
499
|
+
const metricRow = this.buildMonitorMetricRow({
|
|
500
|
+
projectId: data.projectId,
|
|
501
|
+
monitorId: data.monitorId,
|
|
502
|
+
metricName: MonitorMetricType.IsOnline,
|
|
503
|
+
value: isOnline ? 1 : 0,
|
|
504
|
+
attributes: attributes,
|
|
505
|
+
metricPointType: MetricPointType.Sum,
|
|
506
|
+
});
|
|
507
|
+
metricRows.push(metricRow);
|
|
468
508
|
// add MetricType
|
|
469
509
|
const metricType = new MetricType();
|
|
470
510
|
metricType.name = MonitorMetricType.IsOnline;
|
|
@@ -478,27 +518,21 @@ export default class MonitorResourceUtil {
|
|
|
478
518
|
return;
|
|
479
519
|
}
|
|
480
520
|
if (basicMetrics.cpuMetrics) {
|
|
481
|
-
const
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
}
|
|
497
|
-
MonitorResourceUtil.setAttributeKeys(monitorMetric);
|
|
498
|
-
monitorMetric.time = OneUptimeDate.getCurrentDate();
|
|
499
|
-
monitorMetric.timeUnixNano = OneUptimeDate.getCurrentDateAsUnixNano();
|
|
500
|
-
monitorMetric.metricPointType = MetricPointType.Sum;
|
|
501
|
-
itemsToSave.push(monitorMetric);
|
|
521
|
+
const attributes = this.buildMonitorMetricAttributes({
|
|
522
|
+
monitorId: data.monitorId,
|
|
523
|
+
projectId: data.projectId,
|
|
524
|
+
monitorName: data.monitorName,
|
|
525
|
+
probeName: data.probeName,
|
|
526
|
+
});
|
|
527
|
+
const metricRow = this.buildMonitorMetricRow({
|
|
528
|
+
projectId: data.projectId,
|
|
529
|
+
monitorId: data.monitorId,
|
|
530
|
+
metricName: MonitorMetricType.CPUUsagePercent,
|
|
531
|
+
value: (_a = basicMetrics.cpuMetrics.percentUsed) !== null && _a !== void 0 ? _a : null,
|
|
532
|
+
attributes: attributes,
|
|
533
|
+
metricPointType: MetricPointType.Sum,
|
|
534
|
+
});
|
|
535
|
+
metricRows.push(metricRow);
|
|
502
536
|
const metricType = new MetricType();
|
|
503
537
|
metricType.name = MonitorMetricType.CPUUsagePercent;
|
|
504
538
|
metricType.description = CheckOn.CPUUsagePercent + " of Server/VM";
|
|
@@ -507,27 +541,21 @@ export default class MonitorResourceUtil {
|
|
|
507
541
|
metricType;
|
|
508
542
|
}
|
|
509
543
|
if (basicMetrics.memoryMetrics) {
|
|
510
|
-
const
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
}
|
|
526
|
-
MonitorResourceUtil.setAttributeKeys(monitorMetric);
|
|
527
|
-
monitorMetric.time = OneUptimeDate.getCurrentDate();
|
|
528
|
-
monitorMetric.timeUnixNano = OneUptimeDate.getCurrentDateAsUnixNano();
|
|
529
|
-
monitorMetric.metricPointType = MetricPointType.Sum;
|
|
530
|
-
itemsToSave.push(monitorMetric);
|
|
544
|
+
const attributes = this.buildMonitorMetricAttributes({
|
|
545
|
+
monitorId: data.monitorId,
|
|
546
|
+
projectId: data.projectId,
|
|
547
|
+
monitorName: data.monitorName,
|
|
548
|
+
probeName: data.probeName,
|
|
549
|
+
});
|
|
550
|
+
const metricRow = this.buildMonitorMetricRow({
|
|
551
|
+
projectId: data.projectId,
|
|
552
|
+
monitorId: data.monitorId,
|
|
553
|
+
metricName: MonitorMetricType.MemoryUsagePercent,
|
|
554
|
+
value: (_b = basicMetrics.memoryMetrics.percentUsed) !== null && _b !== void 0 ? _b : null,
|
|
555
|
+
attributes: attributes,
|
|
556
|
+
metricPointType: MetricPointType.Sum,
|
|
557
|
+
});
|
|
558
|
+
metricRows.push(metricRow);
|
|
531
559
|
const metricType = new MetricType();
|
|
532
560
|
metricType.name = MonitorMetricType.MemoryUsagePercent;
|
|
533
561
|
metricType.description = CheckOn.MemoryUsagePercent + " of Server/VM";
|
|
@@ -537,29 +565,26 @@ export default class MonitorResourceUtil {
|
|
|
537
565
|
}
|
|
538
566
|
if (basicMetrics.diskMetrics && basicMetrics.diskMetrics.length > 0) {
|
|
539
567
|
for (const diskMetric of basicMetrics.diskMetrics) {
|
|
540
|
-
const
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
monitorMetric.serviceType = ServiceType.Monitor;
|
|
544
|
-
monitorMetric.name = MonitorMetricType.DiskUsagePercent;
|
|
545
|
-
monitorMetric.value = diskMetric.percentUsed;
|
|
546
|
-
monitorMetric.attributes = {
|
|
547
|
-
monitorId: data.monitorId.toString(),
|
|
548
|
-
projectId: data.projectId.toString(),
|
|
549
|
-
diskPath: diskMetric.diskPath,
|
|
550
|
-
};
|
|
551
|
-
if (data.monitorName) {
|
|
552
|
-
monitorMetric.attributes["monitorName"] =
|
|
553
|
-
data.monitorName.toString();
|
|
568
|
+
const extraAttributes = {};
|
|
569
|
+
if (diskMetric.diskPath) {
|
|
570
|
+
extraAttributes["diskPath"] = diskMetric.diskPath;
|
|
554
571
|
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
572
|
+
const attributes = this.buildMonitorMetricAttributes({
|
|
573
|
+
monitorId: data.monitorId,
|
|
574
|
+
projectId: data.projectId,
|
|
575
|
+
monitorName: data.monitorName,
|
|
576
|
+
probeName: data.probeName,
|
|
577
|
+
extraAttributes: extraAttributes,
|
|
578
|
+
});
|
|
579
|
+
const metricRow = this.buildMonitorMetricRow({
|
|
580
|
+
projectId: data.projectId,
|
|
581
|
+
monitorId: data.monitorId,
|
|
582
|
+
metricName: MonitorMetricType.DiskUsagePercent,
|
|
583
|
+
value: (_c = diskMetric.percentUsed) !== null && _c !== void 0 ? _c : null,
|
|
584
|
+
attributes: attributes,
|
|
585
|
+
metricPointType: MetricPointType.Sum,
|
|
586
|
+
});
|
|
587
|
+
metricRows.push(metricRow);
|
|
563
588
|
const metricType = new MetricType();
|
|
564
589
|
metricType.name = MonitorMetricType.DiskUsagePercent;
|
|
565
590
|
metricType.description = CheckOn.DiskUsagePercent + " of Server/VM";
|
|
@@ -569,29 +594,24 @@ export default class MonitorResourceUtil {
|
|
|
569
594
|
}
|
|
570
595
|
}
|
|
571
596
|
}
|
|
572
|
-
if ((
|
|
573
|
-
const
|
|
574
|
-
monitorMetric.projectId = data.projectId;
|
|
575
|
-
monitorMetric.serviceId = data.monitorId;
|
|
576
|
-
monitorMetric.serviceType = ServiceType.Monitor;
|
|
577
|
-
monitorMetric.name = MonitorMetricType.ExecutionTime;
|
|
578
|
-
monitorMetric.value = (_b = data.dataToProcess.customCodeMonitorResponse) === null || _b === void 0 ? void 0 : _b.executionTimeInMS;
|
|
579
|
-
monitorMetric.attributes = {
|
|
580
|
-
monitorId: data.monitorId.toString(),
|
|
581
|
-
projectId: data.projectId.toString(),
|
|
597
|
+
if ((_d = data.dataToProcess.customCodeMonitorResponse) === null || _d === void 0 ? void 0 : _d.executionTimeInMS) {
|
|
598
|
+
const extraAttributes = {
|
|
582
599
|
probeId: data.dataToProcess.probeId.toString(),
|
|
583
600
|
};
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
601
|
+
const attributes = this.buildMonitorMetricAttributes({
|
|
602
|
+
monitorId: data.monitorId,
|
|
603
|
+
projectId: data.projectId,
|
|
604
|
+
extraAttributes: extraAttributes,
|
|
605
|
+
});
|
|
606
|
+
const metricRow = this.buildMonitorMetricRow({
|
|
607
|
+
projectId: data.projectId,
|
|
608
|
+
monitorId: data.monitorId,
|
|
609
|
+
metricName: MonitorMetricType.ExecutionTime,
|
|
610
|
+
value: (_f = (_e = data.dataToProcess.customCodeMonitorResponse) === null || _e === void 0 ? void 0 : _e.executionTimeInMS) !== null && _f !== void 0 ? _f : null,
|
|
611
|
+
attributes: attributes,
|
|
612
|
+
metricPointType: MetricPointType.Sum,
|
|
613
|
+
});
|
|
614
|
+
metricRows.push(metricRow);
|
|
595
615
|
const metricType = new MetricType();
|
|
596
616
|
metricType.name = MonitorMetricType.ExecutionTime;
|
|
597
617
|
metricType.description = CheckOn.ExecutionTime + " of this monitor";
|
|
@@ -603,30 +623,32 @@ export default class MonitorResourceUtil {
|
|
|
603
623
|
(data.dataToProcess.syntheticMonitorResponse ||
|
|
604
624
|
[]).length > 0) {
|
|
605
625
|
for (const syntheticMonitorResponse of data.dataToProcess.syntheticMonitorResponse || []) {
|
|
606
|
-
const
|
|
607
|
-
monitorMetric.projectId = data.projectId;
|
|
608
|
-
monitorMetric.serviceId = data.monitorId;
|
|
609
|
-
monitorMetric.serviceType = ServiceType.Monitor;
|
|
610
|
-
monitorMetric.name = MonitorMetricType.ExecutionTime;
|
|
611
|
-
monitorMetric.value = syntheticMonitorResponse.executionTimeInMS;
|
|
612
|
-
monitorMetric.attributes = {
|
|
613
|
-
monitorId: data.monitorId.toString(),
|
|
614
|
-
projectId: data.projectId.toString(),
|
|
626
|
+
const extraAttributes = {
|
|
615
627
|
probeId: data.dataToProcess.probeId.toString(),
|
|
616
|
-
browserType: syntheticMonitorResponse.browserType,
|
|
617
|
-
screenSizeType: syntheticMonitorResponse.screenSizeType,
|
|
618
628
|
};
|
|
619
|
-
if (
|
|
620
|
-
|
|
629
|
+
if (syntheticMonitorResponse.browserType) {
|
|
630
|
+
extraAttributes["browserType"] = syntheticMonitorResponse.browserType;
|
|
621
631
|
}
|
|
622
|
-
if (
|
|
623
|
-
|
|
632
|
+
if (syntheticMonitorResponse.screenSizeType) {
|
|
633
|
+
extraAttributes["screenSizeType"] =
|
|
634
|
+
syntheticMonitorResponse.screenSizeType;
|
|
624
635
|
}
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
636
|
+
const attributes = this.buildMonitorMetricAttributes({
|
|
637
|
+
monitorId: data.monitorId,
|
|
638
|
+
projectId: data.projectId,
|
|
639
|
+
monitorName: data.monitorName,
|
|
640
|
+
probeName: data.probeName,
|
|
641
|
+
extraAttributes: extraAttributes,
|
|
642
|
+
});
|
|
643
|
+
const metricRow = this.buildMonitorMetricRow({
|
|
644
|
+
projectId: data.projectId,
|
|
645
|
+
monitorId: data.monitorId,
|
|
646
|
+
metricName: MonitorMetricType.ExecutionTime,
|
|
647
|
+
value: (_g = syntheticMonitorResponse.executionTimeInMS) !== null && _g !== void 0 ? _g : null,
|
|
648
|
+
attributes: attributes,
|
|
649
|
+
metricPointType: MetricPointType.Sum,
|
|
650
|
+
});
|
|
651
|
+
metricRows.push(metricRow);
|
|
630
652
|
const metricType = new MetricType();
|
|
631
653
|
metricType.name = MonitorMetricType.ExecutionTime;
|
|
632
654
|
metricType.description = CheckOn.ExecutionTime + " of this monitor";
|
|
@@ -635,28 +657,25 @@ export default class MonitorResourceUtil {
|
|
|
635
657
|
}
|
|
636
658
|
}
|
|
637
659
|
if (data.dataToProcess.responseTimeInMs) {
|
|
638
|
-
const
|
|
639
|
-
monitorMetric.projectId = data.projectId;
|
|
640
|
-
monitorMetric.serviceId = data.monitorId;
|
|
641
|
-
monitorMetric.serviceType = ServiceType.Monitor;
|
|
642
|
-
monitorMetric.name = MonitorMetricType.ResponseTime;
|
|
643
|
-
monitorMetric.value = data.dataToProcess.responseTimeInMs;
|
|
644
|
-
monitorMetric.attributes = {
|
|
645
|
-
monitorId: data.monitorId.toString(),
|
|
646
|
-
projectId: data.projectId.toString(),
|
|
660
|
+
const extraAttributes = {
|
|
647
661
|
probeId: data.dataToProcess.probeId.toString(),
|
|
648
662
|
};
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
663
|
+
const attributes = this.buildMonitorMetricAttributes({
|
|
664
|
+
monitorId: data.monitorId,
|
|
665
|
+
projectId: data.projectId,
|
|
666
|
+
monitorName: data.monitorName,
|
|
667
|
+
probeName: data.probeName,
|
|
668
|
+
extraAttributes: extraAttributes,
|
|
669
|
+
});
|
|
670
|
+
const metricRow = this.buildMonitorMetricRow({
|
|
671
|
+
projectId: data.projectId,
|
|
672
|
+
monitorId: data.monitorId,
|
|
673
|
+
metricName: MonitorMetricType.ResponseTime,
|
|
674
|
+
value: (_h = data.dataToProcess.responseTimeInMs) !== null && _h !== void 0 ? _h : null,
|
|
675
|
+
attributes: attributes,
|
|
676
|
+
metricPointType: MetricPointType.Sum,
|
|
677
|
+
});
|
|
678
|
+
metricRows.push(metricRow);
|
|
660
679
|
const metricType = new MetricType();
|
|
661
680
|
metricType.name = MonitorMetricType.ResponseTime;
|
|
662
681
|
metricType.description = CheckOn.ResponseTime + " of this monitor";
|
|
@@ -664,31 +683,25 @@ export default class MonitorResourceUtil {
|
|
|
664
683
|
metricNameServiceNameMap[MonitorMetricType.ResponseTime] = metricType;
|
|
665
684
|
}
|
|
666
685
|
if (data.dataToProcess.isOnline !== undefined) {
|
|
667
|
-
const
|
|
668
|
-
monitorMetric.projectId = data.projectId;
|
|
669
|
-
monitorMetric.serviceId = data.monitorId;
|
|
670
|
-
monitorMetric.serviceType = ServiceType.Monitor;
|
|
671
|
-
monitorMetric.name = MonitorMetricType.IsOnline;
|
|
672
|
-
monitorMetric.value = data.dataToProcess
|
|
673
|
-
.isOnline
|
|
674
|
-
? 1
|
|
675
|
-
: 0;
|
|
676
|
-
monitorMetric.attributes = {
|
|
677
|
-
monitorId: data.monitorId.toString(),
|
|
678
|
-
projectId: data.projectId.toString(),
|
|
686
|
+
const extraAttributes = {
|
|
679
687
|
probeId: data.dataToProcess.probeId.toString(),
|
|
680
688
|
};
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
689
|
+
const attributes = this.buildMonitorMetricAttributes({
|
|
690
|
+
monitorId: data.monitorId,
|
|
691
|
+
projectId: data.projectId,
|
|
692
|
+
monitorName: data.monitorName,
|
|
693
|
+
probeName: data.probeName,
|
|
694
|
+
extraAttributes: extraAttributes,
|
|
695
|
+
});
|
|
696
|
+
const metricRow = this.buildMonitorMetricRow({
|
|
697
|
+
projectId: data.projectId,
|
|
698
|
+
monitorId: data.monitorId,
|
|
699
|
+
metricName: MonitorMetricType.IsOnline,
|
|
700
|
+
value: data.dataToProcess.isOnline ? 1 : 0,
|
|
701
|
+
attributes: attributes,
|
|
702
|
+
metricPointType: MetricPointType.Sum,
|
|
703
|
+
});
|
|
704
|
+
metricRows.push(metricRow);
|
|
692
705
|
const metricType = new MetricType();
|
|
693
706
|
metricType.name = MonitorMetricType.IsOnline;
|
|
694
707
|
metricType.description = CheckOn.IsOnline + " status for monitor";
|
|
@@ -696,22 +709,25 @@ export default class MonitorResourceUtil {
|
|
|
696
709
|
metricNameServiceNameMap[MonitorMetricType.IsOnline] = metricType;
|
|
697
710
|
}
|
|
698
711
|
if (data.dataToProcess.responseCode) {
|
|
699
|
-
const
|
|
700
|
-
monitorMetric.projectId = data.projectId;
|
|
701
|
-
monitorMetric.serviceId = data.monitorId;
|
|
702
|
-
monitorMetric.serviceType = ServiceType.Monitor;
|
|
703
|
-
monitorMetric.name = MonitorMetricType.ResponseStatusCode;
|
|
704
|
-
monitorMetric.value = data.dataToProcess.responseCode;
|
|
705
|
-
monitorMetric.attributes = {
|
|
706
|
-
monitorId: data.monitorId.toString(),
|
|
707
|
-
projectId: data.projectId.toString(),
|
|
712
|
+
const extraAttributes = {
|
|
708
713
|
probeId: data.dataToProcess.probeId.toString(),
|
|
709
714
|
};
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
+
const attributes = this.buildMonitorMetricAttributes({
|
|
716
|
+
monitorId: data.monitorId,
|
|
717
|
+
projectId: data.projectId,
|
|
718
|
+
monitorName: data.monitorName,
|
|
719
|
+
probeName: data.probeName,
|
|
720
|
+
extraAttributes: extraAttributes,
|
|
721
|
+
});
|
|
722
|
+
const metricRow = this.buildMonitorMetricRow({
|
|
723
|
+
projectId: data.projectId,
|
|
724
|
+
monitorId: data.monitorId,
|
|
725
|
+
metricName: MonitorMetricType.ResponseStatusCode,
|
|
726
|
+
value: (_j = data.dataToProcess.responseCode) !== null && _j !== void 0 ? _j : null,
|
|
727
|
+
attributes: attributes,
|
|
728
|
+
metricPointType: MetricPointType.Sum,
|
|
729
|
+
});
|
|
730
|
+
metricRows.push(metricRow);
|
|
715
731
|
const metricType = new MetricType();
|
|
716
732
|
metricType.name = MonitorMetricType.ResponseStatusCode;
|
|
717
733
|
metricType.description = CheckOn.ResponseStatusCode + " for this monitor";
|
|
@@ -719,12 +735,9 @@ export default class MonitorResourceUtil {
|
|
|
719
735
|
metricNameServiceNameMap[MonitorMetricType.ResponseStatusCode] =
|
|
720
736
|
metricType;
|
|
721
737
|
}
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
isRoot: true,
|
|
726
|
-
},
|
|
727
|
-
});
|
|
738
|
+
if (metricRows.length > 0) {
|
|
739
|
+
await MetricService.insertJsonRows(metricRows);
|
|
740
|
+
}
|
|
728
741
|
// index metrics
|
|
729
742
|
TelemetryUtil.indexMetricNameServiceNameMap({
|
|
730
743
|
projectId: data.projectId,
|
|
@@ -733,17 +746,18 @@ export default class MonitorResourceUtil {
|
|
|
733
746
|
logger.error(err);
|
|
734
747
|
});
|
|
735
748
|
// save monitor log.
|
|
736
|
-
const
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
}
|
|
749
|
+
const logIngestionDate = OneUptimeDate.getCurrentDate();
|
|
750
|
+
const logTimestamp = OneUptimeDate.toClickhouseDateTime(logIngestionDate);
|
|
751
|
+
const monitorLogRow = {
|
|
752
|
+
_id: ObjectID.generate().toString(),
|
|
753
|
+
createdAt: logTimestamp,
|
|
754
|
+
updatedAt: logTimestamp,
|
|
755
|
+
projectId: data.projectId.toString(),
|
|
756
|
+
monitorId: data.monitorId.toString(),
|
|
757
|
+
time: logTimestamp,
|
|
758
|
+
logBody: JSON.parse(JSON.stringify(data.dataToProcess)),
|
|
759
|
+
};
|
|
760
|
+
MonitorLogService.insertJsonRows([monitorLogRow]).catch((err) => {
|
|
747
761
|
logger.error(err);
|
|
748
762
|
});
|
|
749
763
|
}
|