@oneuptime/common 8.0.5469 → 8.0.5480
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 +27 -11
- 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 +9 -3
- 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
|
@@ -44,7 +44,7 @@ import { TelemetryQuery } from "../../../Types/Telemetry/TelemetryQuery";
|
|
|
44
44
|
import MonitorIncident from "./MonitorIncident";
|
|
45
45
|
import MonitorAlert from "./MonitorAlert";
|
|
46
46
|
import MonitorStatusTimelineUtil from "./MonitorStatusTimeline";
|
|
47
|
-
import
|
|
47
|
+
import {
|
|
48
48
|
MetricPointType,
|
|
49
49
|
ServiceType,
|
|
50
50
|
} from "../../../Models/AnalyticsModels/Metric";
|
|
@@ -56,15 +56,80 @@ import MetricMonitorResponse from "../../../Types/Monitor/MetricMonitor/MetricMo
|
|
|
56
56
|
import FilterCondition from "../../../Types/Filter/FilterCondition";
|
|
57
57
|
import CaptureSpan from "../Telemetry/CaptureSpan";
|
|
58
58
|
import MetricType from "../../../Models/DatabaseModels/MetricType";
|
|
59
|
-
import MonitorLog from "../../../Models/AnalyticsModels/MonitorLog";
|
|
60
59
|
import MonitorLogService from "../../Services/MonitorLogService";
|
|
61
60
|
import ExceptionMessages from "../../../Types/Exception/ExceptionMessages";
|
|
62
61
|
|
|
63
62
|
export default class MonitorResourceUtil {
|
|
64
|
-
private static
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
private static buildMonitorMetricAttributes(data: {
|
|
64
|
+
monitorId: ObjectID;
|
|
65
|
+
projectId: ObjectID;
|
|
66
|
+
monitorName?: string | undefined;
|
|
67
|
+
probeName?: string | undefined;
|
|
68
|
+
extraAttributes?: JSONObject;
|
|
69
|
+
}): JSONObject {
|
|
70
|
+
const attributes: JSONObject = {
|
|
71
|
+
monitorId: data.monitorId.toString(),
|
|
72
|
+
projectId: data.projectId.toString(),
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
if (data.extraAttributes) {
|
|
76
|
+
Object.assign(attributes, data.extraAttributes);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (data.monitorName) {
|
|
80
|
+
attributes["monitorName"] = data.monitorName;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (data.probeName) {
|
|
84
|
+
attributes["probeName"] = data.probeName;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return attributes;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private static buildMonitorMetricRow(data: {
|
|
91
|
+
projectId: ObjectID;
|
|
92
|
+
monitorId: ObjectID;
|
|
93
|
+
metricName: string;
|
|
94
|
+
value: number | null | undefined;
|
|
95
|
+
attributes: JSONObject;
|
|
96
|
+
metricPointType?: MetricPointType;
|
|
97
|
+
}): JSONObject {
|
|
98
|
+
const ingestionDate: Date = OneUptimeDate.getCurrentDate();
|
|
99
|
+
const ingestionTimestamp: string =
|
|
100
|
+
OneUptimeDate.toClickhouseDateTime(ingestionDate);
|
|
101
|
+
const timeUnixNano: string =
|
|
102
|
+
OneUptimeDate.toUnixNano(ingestionDate).toString();
|
|
103
|
+
|
|
104
|
+
const attributes: JSONObject = { ...data.attributes };
|
|
105
|
+
const attributeKeys: Array<string> =
|
|
106
|
+
TelemetryUtil.getAttributeKeys(attributes);
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
_id: ObjectID.generate().toString(),
|
|
110
|
+
createdAt: ingestionTimestamp,
|
|
111
|
+
updatedAt: ingestionTimestamp,
|
|
112
|
+
projectId: data.projectId.toString(),
|
|
113
|
+
serviceId: data.monitorId.toString(),
|
|
114
|
+
serviceType: ServiceType.Monitor,
|
|
115
|
+
name: data.metricName,
|
|
116
|
+
aggregationTemporality: null,
|
|
117
|
+
metricPointType: data.metricPointType || MetricPointType.Sum,
|
|
118
|
+
time: ingestionTimestamp,
|
|
119
|
+
startTime: null,
|
|
120
|
+
timeUnixNano: timeUnixNano,
|
|
121
|
+
startTimeUnixNano: null,
|
|
122
|
+
attributes: attributes,
|
|
123
|
+
attributeKeys: attributeKeys,
|
|
124
|
+
isMonotonic: null,
|
|
125
|
+
count: null,
|
|
126
|
+
sum: null,
|
|
127
|
+
min: null,
|
|
128
|
+
max: null,
|
|
129
|
+
bucketCounts: [],
|
|
130
|
+
explicitBounds: [],
|
|
131
|
+
value: data.value ?? null,
|
|
132
|
+
} as JSONObject;
|
|
68
133
|
}
|
|
69
134
|
|
|
70
135
|
@CaptureSpan()
|
|
@@ -640,7 +705,7 @@ export default class MonitorResourceUtil {
|
|
|
640
705
|
return;
|
|
641
706
|
}
|
|
642
707
|
|
|
643
|
-
const
|
|
708
|
+
const metricRows: Array<JSONObject> = [];
|
|
644
709
|
|
|
645
710
|
/*
|
|
646
711
|
* Metric name to serviceId map
|
|
@@ -667,35 +732,23 @@ export default class MonitorResourceUtil {
|
|
|
667
732
|
isOnline = false;
|
|
668
733
|
}
|
|
669
734
|
|
|
670
|
-
const
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
monitorMetric.value = isOnline ? 1 : 0;
|
|
678
|
-
|
|
679
|
-
monitorMetric.attributes = {
|
|
680
|
-
monitorId: data.monitorId.toString(),
|
|
681
|
-
projectId: data.projectId.toString(),
|
|
682
|
-
};
|
|
683
|
-
|
|
684
|
-
if (data.monitorName) {
|
|
685
|
-
monitorMetric.attributes["monitorName"] = data.monitorName.toString();
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
if (data.probeName) {
|
|
689
|
-
monitorMetric.attributes["probeName"] = data.probeName.toString();
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
MonitorResourceUtil.setAttributeKeys(monitorMetric);
|
|
735
|
+
const attributes: JSONObject = this.buildMonitorMetricAttributes({
|
|
736
|
+
monitorId: data.monitorId,
|
|
737
|
+
projectId: data.projectId,
|
|
738
|
+
monitorName: data.monitorName,
|
|
739
|
+
probeName: data.probeName,
|
|
740
|
+
});
|
|
693
741
|
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
742
|
+
const metricRow: JSONObject = this.buildMonitorMetricRow({
|
|
743
|
+
projectId: data.projectId,
|
|
744
|
+
monitorId: data.monitorId,
|
|
745
|
+
metricName: MonitorMetricType.IsOnline,
|
|
746
|
+
value: isOnline ? 1 : 0,
|
|
747
|
+
attributes: attributes,
|
|
748
|
+
metricPointType: MetricPointType.Sum,
|
|
749
|
+
});
|
|
697
750
|
|
|
698
|
-
|
|
751
|
+
metricRows.push(metricRow);
|
|
699
752
|
|
|
700
753
|
// add MetricType
|
|
701
754
|
const metricType: MetricType = new MetricType();
|
|
@@ -716,35 +769,23 @@ export default class MonitorResourceUtil {
|
|
|
716
769
|
}
|
|
717
770
|
|
|
718
771
|
if (basicMetrics.cpuMetrics) {
|
|
719
|
-
const
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
monitorMetric.value = basicMetrics.cpuMetrics.percentUsed;
|
|
727
|
-
|
|
728
|
-
monitorMetric.attributes = {
|
|
729
|
-
monitorId: data.monitorId.toString(),
|
|
730
|
-
projectId: data.projectId.toString(),
|
|
731
|
-
};
|
|
732
|
-
|
|
733
|
-
if (data.monitorName) {
|
|
734
|
-
monitorMetric.attributes["monitorName"] = data.monitorName.toString();
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
if (data.probeName) {
|
|
738
|
-
monitorMetric.attributes["probeName"] = data.probeName.toString();
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
MonitorResourceUtil.setAttributeKeys(monitorMetric);
|
|
772
|
+
const attributes: JSONObject = this.buildMonitorMetricAttributes({
|
|
773
|
+
monitorId: data.monitorId,
|
|
774
|
+
projectId: data.projectId,
|
|
775
|
+
monitorName: data.monitorName,
|
|
776
|
+
probeName: data.probeName,
|
|
777
|
+
});
|
|
742
778
|
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
779
|
+
const metricRow: JSONObject = this.buildMonitorMetricRow({
|
|
780
|
+
projectId: data.projectId,
|
|
781
|
+
monitorId: data.monitorId,
|
|
782
|
+
metricName: MonitorMetricType.CPUUsagePercent,
|
|
783
|
+
value: basicMetrics.cpuMetrics.percentUsed ?? null,
|
|
784
|
+
attributes: attributes,
|
|
785
|
+
metricPointType: MetricPointType.Sum,
|
|
786
|
+
});
|
|
746
787
|
|
|
747
|
-
|
|
788
|
+
metricRows.push(metricRow);
|
|
748
789
|
|
|
749
790
|
const metricType: MetricType = new MetricType();
|
|
750
791
|
metricType.name = MonitorMetricType.CPUUsagePercent;
|
|
@@ -756,35 +797,23 @@ export default class MonitorResourceUtil {
|
|
|
756
797
|
}
|
|
757
798
|
|
|
758
799
|
if (basicMetrics.memoryMetrics) {
|
|
759
|
-
const
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
monitorMetric.value = basicMetrics.memoryMetrics.percentUsed;
|
|
767
|
-
|
|
768
|
-
monitorMetric.attributes = {
|
|
769
|
-
monitorId: data.monitorId.toString(),
|
|
770
|
-
projectId: data.projectId.toString(),
|
|
771
|
-
};
|
|
772
|
-
|
|
773
|
-
if (data.monitorName) {
|
|
774
|
-
monitorMetric.attributes["monitorName"] = data.monitorName.toString();
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
if (data.probeName) {
|
|
778
|
-
monitorMetric.attributes["probeName"] = data.probeName.toString();
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
MonitorResourceUtil.setAttributeKeys(monitorMetric);
|
|
800
|
+
const attributes: JSONObject = this.buildMonitorMetricAttributes({
|
|
801
|
+
monitorId: data.monitorId,
|
|
802
|
+
projectId: data.projectId,
|
|
803
|
+
monitorName: data.monitorName,
|
|
804
|
+
probeName: data.probeName,
|
|
805
|
+
});
|
|
782
806
|
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
807
|
+
const metricRow: JSONObject = this.buildMonitorMetricRow({
|
|
808
|
+
projectId: data.projectId,
|
|
809
|
+
monitorId: data.monitorId,
|
|
810
|
+
metricName: MonitorMetricType.MemoryUsagePercent,
|
|
811
|
+
value: basicMetrics.memoryMetrics.percentUsed ?? null,
|
|
812
|
+
attributes: attributes,
|
|
813
|
+
metricPointType: MetricPointType.Sum,
|
|
814
|
+
});
|
|
786
815
|
|
|
787
|
-
|
|
816
|
+
metricRows.push(metricRow);
|
|
788
817
|
|
|
789
818
|
const metricType: MetricType = new MetricType();
|
|
790
819
|
metricType.name = MonitorMetricType.MemoryUsagePercent;
|
|
@@ -797,37 +826,30 @@ export default class MonitorResourceUtil {
|
|
|
797
826
|
|
|
798
827
|
if (basicMetrics.diskMetrics && basicMetrics.diskMetrics.length > 0) {
|
|
799
828
|
for (const diskMetric of basicMetrics.diskMetrics) {
|
|
800
|
-
const
|
|
801
|
-
|
|
802
|
-
monitorMetric.projectId = data.projectId;
|
|
803
|
-
monitorMetric.serviceId = data.monitorId;
|
|
804
|
-
monitorMetric.serviceType = ServiceType.Monitor;
|
|
805
|
-
monitorMetric.name = MonitorMetricType.DiskUsagePercent;
|
|
806
|
-
|
|
807
|
-
monitorMetric.value = diskMetric.percentUsed;
|
|
808
|
-
|
|
809
|
-
monitorMetric.attributes = {
|
|
810
|
-
monitorId: data.monitorId.toString(),
|
|
811
|
-
projectId: data.projectId.toString(),
|
|
812
|
-
diskPath: diskMetric.diskPath,
|
|
813
|
-
};
|
|
814
|
-
|
|
815
|
-
if (data.monitorName) {
|
|
816
|
-
monitorMetric.attributes["monitorName"] =
|
|
817
|
-
data.monitorName.toString();
|
|
818
|
-
}
|
|
829
|
+
const extraAttributes: JSONObject = {};
|
|
819
830
|
|
|
820
|
-
if (
|
|
821
|
-
|
|
831
|
+
if (diskMetric.diskPath) {
|
|
832
|
+
extraAttributes["diskPath"] = diskMetric.diskPath;
|
|
822
833
|
}
|
|
823
834
|
|
|
824
|
-
|
|
835
|
+
const attributes: JSONObject = this.buildMonitorMetricAttributes({
|
|
836
|
+
monitorId: data.monitorId,
|
|
837
|
+
projectId: data.projectId,
|
|
838
|
+
monitorName: data.monitorName,
|
|
839
|
+
probeName: data.probeName,
|
|
840
|
+
extraAttributes: extraAttributes,
|
|
841
|
+
});
|
|
825
842
|
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
843
|
+
const metricRow: JSONObject = this.buildMonitorMetricRow({
|
|
844
|
+
projectId: data.projectId,
|
|
845
|
+
monitorId: data.monitorId,
|
|
846
|
+
metricName: MonitorMetricType.DiskUsagePercent,
|
|
847
|
+
value: diskMetric.percentUsed ?? null,
|
|
848
|
+
attributes: attributes,
|
|
849
|
+
metricPointType: MetricPointType.Sum,
|
|
850
|
+
});
|
|
829
851
|
|
|
830
|
-
|
|
852
|
+
metricRows.push(metricRow);
|
|
831
853
|
|
|
832
854
|
const metricType: MetricType = new MetricType();
|
|
833
855
|
metricType.name = MonitorMetricType.DiskUsagePercent;
|
|
@@ -844,40 +866,30 @@ export default class MonitorResourceUtil {
|
|
|
844
866
|
(data.dataToProcess as ProbeMonitorResponse).customCodeMonitorResponse
|
|
845
867
|
?.executionTimeInMS
|
|
846
868
|
) {
|
|
847
|
-
const
|
|
848
|
-
|
|
849
|
-
monitorMetric.projectId = data.projectId;
|
|
850
|
-
monitorMetric.serviceId = data.monitorId;
|
|
851
|
-
monitorMetric.serviceType = ServiceType.Monitor;
|
|
852
|
-
monitorMetric.name = MonitorMetricType.ExecutionTime;
|
|
853
|
-
|
|
854
|
-
monitorMetric.value = (
|
|
855
|
-
data.dataToProcess as ProbeMonitorResponse
|
|
856
|
-
).customCodeMonitorResponse?.executionTimeInMS;
|
|
857
|
-
|
|
858
|
-
monitorMetric.attributes = {
|
|
859
|
-
monitorId: data.monitorId.toString(),
|
|
860
|
-
projectId: data.projectId.toString(),
|
|
869
|
+
const extraAttributes: JSONObject = {
|
|
861
870
|
probeId: (
|
|
862
871
|
data.dataToProcess as ProbeMonitorResponse
|
|
863
872
|
).probeId.toString(),
|
|
864
873
|
};
|
|
865
874
|
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
monitorMetric.attributes["probeName"] = data.probeName.toString();
|
|
872
|
-
}
|
|
873
|
-
|
|
874
|
-
MonitorResourceUtil.setAttributeKeys(monitorMetric);
|
|
875
|
+
const attributes: JSONObject = this.buildMonitorMetricAttributes({
|
|
876
|
+
monitorId: data.monitorId,
|
|
877
|
+
projectId: data.projectId,
|
|
878
|
+
extraAttributes: extraAttributes,
|
|
879
|
+
});
|
|
875
880
|
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
881
|
+
const metricRow: JSONObject = this.buildMonitorMetricRow({
|
|
882
|
+
projectId: data.projectId,
|
|
883
|
+
monitorId: data.monitorId,
|
|
884
|
+
metricName: MonitorMetricType.ExecutionTime,
|
|
885
|
+
value:
|
|
886
|
+
(data.dataToProcess as ProbeMonitorResponse).customCodeMonitorResponse
|
|
887
|
+
?.executionTimeInMS ?? null,
|
|
888
|
+
attributes: attributes,
|
|
889
|
+
metricPointType: MetricPointType.Sum,
|
|
890
|
+
});
|
|
879
891
|
|
|
880
|
-
|
|
892
|
+
metricRows.push(metricRow);
|
|
881
893
|
|
|
882
894
|
const metricType: MetricType = new MetricType();
|
|
883
895
|
metricType.name = MonitorMetricType.ExecutionTime;
|
|
@@ -898,40 +910,39 @@ export default class MonitorResourceUtil {
|
|
|
898
910
|
for (const syntheticMonitorResponse of (
|
|
899
911
|
data.dataToProcess as ProbeMonitorResponse
|
|
900
912
|
).syntheticMonitorResponse || []) {
|
|
901
|
-
const
|
|
902
|
-
|
|
903
|
-
monitorMetric.projectId = data.projectId;
|
|
904
|
-
monitorMetric.serviceId = data.monitorId;
|
|
905
|
-
monitorMetric.serviceType = ServiceType.Monitor;
|
|
906
|
-
monitorMetric.name = MonitorMetricType.ExecutionTime;
|
|
907
|
-
|
|
908
|
-
monitorMetric.value = syntheticMonitorResponse.executionTimeInMS;
|
|
909
|
-
|
|
910
|
-
monitorMetric.attributes = {
|
|
911
|
-
monitorId: data.monitorId.toString(),
|
|
912
|
-
projectId: data.projectId.toString(),
|
|
913
|
+
const extraAttributes: JSONObject = {
|
|
913
914
|
probeId: (
|
|
914
915
|
data.dataToProcess as ProbeMonitorResponse
|
|
915
916
|
).probeId.toString(),
|
|
916
|
-
browserType: syntheticMonitorResponse.browserType,
|
|
917
|
-
screenSizeType: syntheticMonitorResponse.screenSizeType,
|
|
918
917
|
};
|
|
919
918
|
|
|
920
|
-
if (
|
|
921
|
-
|
|
919
|
+
if (syntheticMonitorResponse.browserType) {
|
|
920
|
+
extraAttributes["browserType"] = syntheticMonitorResponse.browserType;
|
|
922
921
|
}
|
|
923
922
|
|
|
924
|
-
if (
|
|
925
|
-
|
|
923
|
+
if (syntheticMonitorResponse.screenSizeType) {
|
|
924
|
+
extraAttributes["screenSizeType"] =
|
|
925
|
+
syntheticMonitorResponse.screenSizeType;
|
|
926
926
|
}
|
|
927
927
|
|
|
928
|
-
|
|
928
|
+
const attributes: JSONObject = this.buildMonitorMetricAttributes({
|
|
929
|
+
monitorId: data.monitorId,
|
|
930
|
+
projectId: data.projectId,
|
|
931
|
+
monitorName: data.monitorName,
|
|
932
|
+
probeName: data.probeName,
|
|
933
|
+
extraAttributes: extraAttributes,
|
|
934
|
+
});
|
|
929
935
|
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
936
|
+
const metricRow: JSONObject = this.buildMonitorMetricRow({
|
|
937
|
+
projectId: data.projectId,
|
|
938
|
+
monitorId: data.monitorId,
|
|
939
|
+
metricName: MonitorMetricType.ExecutionTime,
|
|
940
|
+
value: syntheticMonitorResponse.executionTimeInMS ?? null,
|
|
941
|
+
attributes: attributes,
|
|
942
|
+
metricPointType: MetricPointType.Sum,
|
|
943
|
+
});
|
|
933
944
|
|
|
934
|
-
|
|
945
|
+
metricRows.push(metricRow);
|
|
935
946
|
|
|
936
947
|
const metricType: MetricType = new MetricType();
|
|
937
948
|
metricType.name = MonitorMetricType.ExecutionTime;
|
|
@@ -943,40 +954,31 @@ export default class MonitorResourceUtil {
|
|
|
943
954
|
}
|
|
944
955
|
|
|
945
956
|
if ((data.dataToProcess as ProbeMonitorResponse).responseTimeInMs) {
|
|
946
|
-
const
|
|
947
|
-
|
|
948
|
-
monitorMetric.projectId = data.projectId;
|
|
949
|
-
monitorMetric.serviceId = data.monitorId;
|
|
950
|
-
monitorMetric.serviceType = ServiceType.Monitor;
|
|
951
|
-
monitorMetric.name = MonitorMetricType.ResponseTime;
|
|
952
|
-
|
|
953
|
-
monitorMetric.value = (
|
|
954
|
-
data.dataToProcess as ProbeMonitorResponse
|
|
955
|
-
).responseTimeInMs;
|
|
956
|
-
|
|
957
|
-
monitorMetric.attributes = {
|
|
958
|
-
monitorId: data.monitorId.toString(),
|
|
959
|
-
projectId: data.projectId.toString(),
|
|
957
|
+
const extraAttributes: JSONObject = {
|
|
960
958
|
probeId: (
|
|
961
959
|
data.dataToProcess as ProbeMonitorResponse
|
|
962
960
|
).probeId.toString(),
|
|
963
961
|
};
|
|
964
962
|
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
}
|
|
972
|
-
|
|
973
|
-
MonitorResourceUtil.setAttributeKeys(monitorMetric);
|
|
963
|
+
const attributes: JSONObject = this.buildMonitorMetricAttributes({
|
|
964
|
+
monitorId: data.monitorId,
|
|
965
|
+
projectId: data.projectId,
|
|
966
|
+
monitorName: data.monitorName,
|
|
967
|
+
probeName: data.probeName,
|
|
968
|
+
extraAttributes: extraAttributes,
|
|
969
|
+
});
|
|
974
970
|
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
971
|
+
const metricRow: JSONObject = this.buildMonitorMetricRow({
|
|
972
|
+
projectId: data.projectId,
|
|
973
|
+
monitorId: data.monitorId,
|
|
974
|
+
metricName: MonitorMetricType.ResponseTime,
|
|
975
|
+
value:
|
|
976
|
+
(data.dataToProcess as ProbeMonitorResponse).responseTimeInMs ?? null,
|
|
977
|
+
attributes: attributes,
|
|
978
|
+
metricPointType: MetricPointType.Sum,
|
|
979
|
+
});
|
|
978
980
|
|
|
979
|
-
|
|
981
|
+
metricRows.push(metricRow);
|
|
980
982
|
|
|
981
983
|
const metricType: MetricType = new MetricType();
|
|
982
984
|
metricType.name = MonitorMetricType.ResponseTime;
|
|
@@ -987,41 +989,30 @@ export default class MonitorResourceUtil {
|
|
|
987
989
|
}
|
|
988
990
|
|
|
989
991
|
if ((data.dataToProcess as ProbeMonitorResponse).isOnline !== undefined) {
|
|
990
|
-
const
|
|
991
|
-
|
|
992
|
-
monitorMetric.projectId = data.projectId;
|
|
993
|
-
monitorMetric.serviceId = data.monitorId;
|
|
994
|
-
monitorMetric.serviceType = ServiceType.Monitor;
|
|
995
|
-
monitorMetric.name = MonitorMetricType.IsOnline;
|
|
996
|
-
|
|
997
|
-
monitorMetric.value = (data.dataToProcess as ProbeMonitorResponse)
|
|
998
|
-
.isOnline
|
|
999
|
-
? 1
|
|
1000
|
-
: 0;
|
|
1001
|
-
|
|
1002
|
-
monitorMetric.attributes = {
|
|
1003
|
-
monitorId: data.monitorId.toString(),
|
|
1004
|
-
projectId: data.projectId.toString(),
|
|
992
|
+
const extraAttributes: JSONObject = {
|
|
1005
993
|
probeId: (
|
|
1006
994
|
data.dataToProcess as ProbeMonitorResponse
|
|
1007
995
|
).probeId.toString(),
|
|
1008
996
|
};
|
|
1009
997
|
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
}
|
|
1017
|
-
|
|
1018
|
-
MonitorResourceUtil.setAttributeKeys(monitorMetric);
|
|
998
|
+
const attributes: JSONObject = this.buildMonitorMetricAttributes({
|
|
999
|
+
monitorId: data.monitorId,
|
|
1000
|
+
projectId: data.projectId,
|
|
1001
|
+
monitorName: data.monitorName,
|
|
1002
|
+
probeName: data.probeName,
|
|
1003
|
+
extraAttributes: extraAttributes,
|
|
1004
|
+
});
|
|
1019
1005
|
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1006
|
+
const metricRow: JSONObject = this.buildMonitorMetricRow({
|
|
1007
|
+
projectId: data.projectId,
|
|
1008
|
+
monitorId: data.monitorId,
|
|
1009
|
+
metricName: MonitorMetricType.IsOnline,
|
|
1010
|
+
value: (data.dataToProcess as ProbeMonitorResponse).isOnline ? 1 : 0,
|
|
1011
|
+
attributes: attributes,
|
|
1012
|
+
metricPointType: MetricPointType.Sum,
|
|
1013
|
+
});
|
|
1023
1014
|
|
|
1024
|
-
|
|
1015
|
+
metricRows.push(metricRow);
|
|
1025
1016
|
|
|
1026
1017
|
const metricType: MetricType = new MetricType();
|
|
1027
1018
|
metricType.name = MonitorMetricType.IsOnline;
|
|
@@ -1032,32 +1023,31 @@ export default class MonitorResourceUtil {
|
|
|
1032
1023
|
}
|
|
1033
1024
|
|
|
1034
1025
|
if ((data.dataToProcess as ProbeMonitorResponse).responseCode) {
|
|
1035
|
-
const
|
|
1036
|
-
|
|
1037
|
-
monitorMetric.projectId = data.projectId;
|
|
1038
|
-
monitorMetric.serviceId = data.monitorId;
|
|
1039
|
-
monitorMetric.serviceType = ServiceType.Monitor;
|
|
1040
|
-
monitorMetric.name = MonitorMetricType.ResponseStatusCode;
|
|
1041
|
-
|
|
1042
|
-
monitorMetric.value = (
|
|
1043
|
-
data.dataToProcess as ProbeMonitorResponse
|
|
1044
|
-
).responseCode;
|
|
1045
|
-
|
|
1046
|
-
monitorMetric.attributes = {
|
|
1047
|
-
monitorId: data.monitorId.toString(),
|
|
1048
|
-
projectId: data.projectId.toString(),
|
|
1026
|
+
const extraAttributes: JSONObject = {
|
|
1049
1027
|
probeId: (
|
|
1050
1028
|
data.dataToProcess as ProbeMonitorResponse
|
|
1051
1029
|
).probeId.toString(),
|
|
1052
1030
|
};
|
|
1053
1031
|
|
|
1054
|
-
|
|
1032
|
+
const attributes: JSONObject = this.buildMonitorMetricAttributes({
|
|
1033
|
+
monitorId: data.monitorId,
|
|
1034
|
+
projectId: data.projectId,
|
|
1035
|
+
monitorName: data.monitorName,
|
|
1036
|
+
probeName: data.probeName,
|
|
1037
|
+
extraAttributes: extraAttributes,
|
|
1038
|
+
});
|
|
1055
1039
|
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1040
|
+
const metricRow: JSONObject = this.buildMonitorMetricRow({
|
|
1041
|
+
projectId: data.projectId,
|
|
1042
|
+
monitorId: data.monitorId,
|
|
1043
|
+
metricName: MonitorMetricType.ResponseStatusCode,
|
|
1044
|
+
value:
|
|
1045
|
+
(data.dataToProcess as ProbeMonitorResponse).responseCode ?? null,
|
|
1046
|
+
attributes: attributes,
|
|
1047
|
+
metricPointType: MetricPointType.Sum,
|
|
1048
|
+
});
|
|
1059
1049
|
|
|
1060
|
-
|
|
1050
|
+
metricRows.push(metricRow);
|
|
1061
1051
|
|
|
1062
1052
|
const metricType: MetricType = new MetricType();
|
|
1063
1053
|
metricType.name = MonitorMetricType.ResponseStatusCode;
|
|
@@ -1068,12 +1058,9 @@ export default class MonitorResourceUtil {
|
|
|
1068
1058
|
metricType;
|
|
1069
1059
|
}
|
|
1070
1060
|
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
isRoot: true,
|
|
1075
|
-
},
|
|
1076
|
-
});
|
|
1061
|
+
if (metricRows.length > 0) {
|
|
1062
|
+
await MetricService.insertJsonRows(metricRows);
|
|
1063
|
+
}
|
|
1077
1064
|
|
|
1078
1065
|
// index metrics
|
|
1079
1066
|
TelemetryUtil.indexMetricNameServiceNameMap({
|
|
@@ -1084,18 +1071,21 @@ export default class MonitorResourceUtil {
|
|
|
1084
1071
|
});
|
|
1085
1072
|
|
|
1086
1073
|
// save monitor log.
|
|
1087
|
-
const
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1074
|
+
const logIngestionDate: Date = OneUptimeDate.getCurrentDate();
|
|
1075
|
+
const logTimestamp: string =
|
|
1076
|
+
OneUptimeDate.toClickhouseDateTime(logIngestionDate);
|
|
1077
|
+
|
|
1078
|
+
const monitorLogRow: JSONObject = {
|
|
1079
|
+
_id: ObjectID.generate().toString(),
|
|
1080
|
+
createdAt: logTimestamp,
|
|
1081
|
+
updatedAt: logTimestamp,
|
|
1082
|
+
projectId: data.projectId.toString(),
|
|
1083
|
+
monitorId: data.monitorId.toString(),
|
|
1084
|
+
time: logTimestamp,
|
|
1085
|
+
logBody: JSON.parse(JSON.stringify(data.dataToProcess)),
|
|
1086
|
+
};
|
|
1087
|
+
|
|
1088
|
+
MonitorLogService.insertJsonRows([monitorLogRow]).catch((err: Error) => {
|
|
1099
1089
|
logger.error(err);
|
|
1100
1090
|
});
|
|
1101
1091
|
}
|