infra migration
This commit is contained in:
1 parent
6f9fefddd2
commit
fcd9e78367
8 files changed
+16
-37
No files matched your search
@@ -92,9 +92,7 @@ const CreateInfrastructureMonitor = () => {
|
|||||||
initializeInfrastructureMonitorForUpdate(monitor);
|
initializeInfrastructureMonitorForUpdate(monitor);
|
||||||
const fetchLastCheck = async () => {
|
const fetchLastCheck = async () => {
|
||||||
try {
|
try {
|
||||||
const { stats } = monitor ?? {};
|
let disks = monitor?.recentChecks?.[0]?.disk || [];
|
||||||
let latestCheck = stats?.aggregateData?.latestCheck;
|
|
||||||
let disks = latestCheck?.disk || [];
|
|
||||||
|
|
||||||
if (disks.length > 0) {
|
if (disks.length > 0) {
|
||||||
setAvailableDisks(disks);
|
setAvailableDisks(disks);
|
||||||
|
|||||||
@@ -19,8 +19,7 @@ const Gauges = ({ isLoading = false, monitor }) => {
|
|||||||
return <SkeletonLayout />;
|
return <SkeletonLayout />;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { stats } = monitor ?? {};
|
const latestCheck = monitor?.recentChecks?.[0];
|
||||||
let latestCheck = stats?.aggregateData?.latestCheck;
|
|
||||||
const memoryUsagePercent = latestCheck?.memory?.usage_percent ?? 0;
|
const memoryUsagePercent = latestCheck?.memory?.usage_percent ?? 0;
|
||||||
const memoryUsedBytes = latestCheck?.memory?.used_bytes ?? 0;
|
const memoryUsedBytes = latestCheck?.memory?.used_bytes ?? 0;
|
||||||
const memoryTotalBytes = latestCheck?.memory?.total_bytes ?? 0;
|
const memoryTotalBytes = latestCheck?.memory?.total_bytes ?? 0;
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ const InfraStatBoxes = ({ shouldRender, monitor }) => {
|
|||||||
const { determineState } = useMonitorUtils();
|
const { determineState } = useMonitorUtils();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const { stats } = monitor ?? {};
|
const latestCheck = monitor?.recentChecks?.[0];
|
||||||
const latestCheck = stats?.aggregateData?.latestCheck;
|
|
||||||
|
|
||||||
// Get data from latest check
|
// Get data from latest check
|
||||||
const physicalCores = latestCheck?.cpu?.physical_core ?? 0;
|
const physicalCores = latestCheck?.cpu?.physical_core ?? 0;
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ const InfrastructureDetails = () => {
|
|||||||
)}
|
)}
|
||||||
{tab === "network" && (
|
{tab === "network" && (
|
||||||
<NetworkStats
|
<NetworkStats
|
||||||
net={monitor?.stats?.aggregateData?.latestCheck?.net || []}
|
net={monitor?.recentChecks?.[0]?.net || []}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
checks={monitor?.stats?.checks}
|
checks={monitor?.stats?.checks}
|
||||||
dateRange={dateRange}
|
dateRange={dateRange}
|
||||||
|
|||||||
@@ -102,10 +102,10 @@ const MonitorsTable = ({
|
|||||||
|
|
||||||
const data = monitors?.map((monitor) => {
|
const data = monitors?.map((monitor) => {
|
||||||
const processor =
|
const processor =
|
||||||
((monitor.checks[0]?.cpu?.frequency ?? 0) / 1000).toFixed(2) + " GHz";
|
((monitor.recentChecks?.[0]?.cpu?.frequency ?? 0) / 1000).toFixed(2) + " GHz";
|
||||||
const cpu = (monitor?.checks[0]?.cpu.usage_percent ?? 0) * 100;
|
const cpu = (monitor?.recentChecks?.[0]?.cpu?.usage_percent ?? 0) * 100;
|
||||||
const mem = (monitor?.checks[0]?.memory.usage_percent ?? 0) * 100;
|
const mem = (monitor?.recentChecks?.[0]?.memory?.usage_percent ?? 0) * 100;
|
||||||
const disk = (monitor?.checks[0]?.disk[0]?.usage_percent ?? 0) * 100;
|
const disk = (monitor?.recentChecks?.[0]?.disk?.[0]?.usage_percent ?? 0) * 100;
|
||||||
const status = determineState(monitor);
|
const status = determineState(monitor);
|
||||||
const percentageColor =
|
const percentageColor =
|
||||||
monitor.uptimePercentage < 0.25
|
monitor.uptimePercentage < 0.25
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ const dateRangeLookup: Record<string, Date | undefined> = {
|
|||||||
|
|
||||||
export type LatestChecksMap = Record<string, Check[]>;
|
export type LatestChecksMap = Record<string, Check[]>;
|
||||||
type DateRange = { start: Date; end: Date };
|
type DateRange = { start: Date; end: Date };
|
||||||
type HardwareAggregateData = { latestCheck: CheckDocument | null; totalChecks: number };
|
|
||||||
type HardwareUpChecks = { totalChecks: number };
|
type HardwareUpChecks = { totalChecks: number };
|
||||||
|
|
||||||
class MongoChecksRepository implements IChecksRepository {
|
class MongoChecksRepository implements IChecksRepository {
|
||||||
@@ -526,14 +525,13 @@ class MongoChecksRepository implements IChecksRepository {
|
|||||||
const monitorId = monitorObjectId.toHexString();
|
const monitorId = monitorObjectId.toHexString();
|
||||||
const dates = { start: startDate, end: endDate };
|
const dates = { start: startDate, end: endDate };
|
||||||
const [aggregateDataDoc, upChecksDoc, hardwareMetrics] = await Promise.all([
|
const [aggregateDataDoc, upChecksDoc, hardwareMetrics] = await Promise.all([
|
||||||
this.getHardwareAggregateData(monitorId, dates),
|
this.getHardwareTotalChecks(monitorId, dates),
|
||||||
this.getHardwareUpChecks(monitorId, dates),
|
this.getHardwareUpChecks(monitorId, dates),
|
||||||
this.getHardwareStats(monitorId, dates, dateString),
|
this.getHardwareStats(monitorId, dates, dateString),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const aggregateData = {
|
const aggregateData = {
|
||||||
latestCheck: aggregateDataDoc?.latestCheck ? this.toEntity(aggregateDataDoc.latestCheck as CheckDocument) : null,
|
totalChecks: aggregateDataDoc ?? 0,
|
||||||
totalChecks: aggregateDataDoc?.totalChecks ?? 0,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const upChecks = {
|
const upChecks = {
|
||||||
@@ -589,25 +587,12 @@ class MongoChecksRepository implements IChecksRepository {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
private getHardwareAggregateData = async (monitorId: string, dates: DateRange): Promise<HardwareAggregateData> => {
|
private getHardwareTotalChecks = async (monitorId: string, dates: DateRange): Promise<number> => {
|
||||||
const result = await CheckModel.aggregate([
|
return await CheckModel.countDocuments({
|
||||||
{
|
"metadata.monitorId": new mongoose.Types.ObjectId(monitorId),
|
||||||
$match: {
|
"metadata.type": "hardware",
|
||||||
"metadata.monitorId": new mongoose.Types.ObjectId(monitorId),
|
createdAt: { $gte: dates.start, $lte: dates.end },
|
||||||
"metadata.type": "hardware",
|
});
|
||||||
createdAt: { $gte: dates.start, $lte: dates.end },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ $sort: { createdAt: -1 } },
|
|
||||||
{
|
|
||||||
$group: {
|
|
||||||
_id: null,
|
|
||||||
latestCheck: { $first: "$$ROOT" },
|
|
||||||
totalChecks: { $sum: 1 },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
return result[0] || { totalChecks: 0, latestCheck: null };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private getHardwareUpChecks = async (monitorId: string, dates: DateRange): Promise<HardwareUpChecks> => {
|
private getHardwareUpChecks = async (monitorId: string, dates: DateRange): Promise<HardwareUpChecks> => {
|
||||||
|
|||||||
@@ -121,7 +121,6 @@ export interface PageSpeedChecksResult {
|
|||||||
export interface HardwareChecksResult {
|
export interface HardwareChecksResult {
|
||||||
monitorType: "hardware";
|
monitorType: "hardware";
|
||||||
aggregateData: {
|
aggregateData: {
|
||||||
latestCheck: Check | null;
|
|
||||||
totalChecks: number;
|
totalChecks: number;
|
||||||
};
|
};
|
||||||
upChecks: {
|
upChecks: {
|
||||||
|
|||||||
@@ -78,7 +78,6 @@ export interface UptimeDetailsResult {
|
|||||||
export interface HardwareDetailsResult extends Monitor {
|
export interface HardwareDetailsResult extends Monitor {
|
||||||
stats: {
|
stats: {
|
||||||
aggregateData: {
|
aggregateData: {
|
||||||
latestCheck: import("./check.js").Check | null;
|
|
||||||
totalChecks: number;
|
totalChecks: number;
|
||||||
};
|
};
|
||||||
upChecks: {
|
upChecks: {
|
||||||
|
|||||||
Reference in new issue
Block a user