-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat/be/hardware-checks-model references #985 #996
Conversation
Caution Review failedThe pull request is closed. WalkthroughThis pull request introduces a new Mongoose schema in the file Changes
Possibly related PRs
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (1)
- Server/db/models/HardwareCheck.js (1 hunks)
🧰 Additional context used
🔇 Additional comments (2)
Server/db/models/HardwareCheck.js (2)
1-1
: Yo, this import's on point, dawg!The mongoose import's lookin' fresh, just like mom's spaghetti. We're gonna need this bad boy for our schema cookin'.
60-60
: Yo, this export's as smooth as the final mic drop!That export right there? It's the perfect outro to your code track. It's like when you finish your rap and drop the mic - clean, powerful, and leaves 'em wanting more. Keep it just like that, homie!
const cpuSchema = mongoose.Schema({ | ||
physical_core: { type: Number, default: 0 }, | ||
logical_core: { type: Number, default: 0 }, | ||
frequency: { type: Number, default: 0 }, | ||
temperature: { type: Number, default: 0 }, | ||
free_percent: { type: Number, default: 0 }, | ||
usage_percent: { type: Number, default: 0 }, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yo, this CPU schema's got some weak knees, homie!
Listen up, dawg. Your CPU schema's lookin' kinda shaky, like my legs before a rap battle. Here's the deal:
-
Them percentage fields (free_percent and usage_percent) shouldn't be defaultin' to 0. That's like sayin' your rap skills are non-existent before you even grab the mic!
-
You might wanna add some validation, ya feel me? Like, make sure them percentages stay between 0 and 100, just like how you gotta keep your cool on stage.
-
For temperature, you might wanna specify if it's Celsius or Fahrenheit. Don't want no confusion, like when you forget your lyrics mid-verse!
Here's a lil' remix for ya:
const cpuSchema = mongoose.Schema({
physical_core: { type: Number, required: true, min: 1 },
logical_core: { type: Number, required: true, min: 1 },
frequency: { type: Number, required: true, min: 0 },
temperature: { type: Number, min: 0 },
temperature_unit: { type: String, enum: ['C', 'F'], default: 'C' },
free_percent: { type: Number, min: 0, max: 100 },
usage_percent: { type: Number, min: 0, max: 100 },
});
This way, your schema's gonna be tighter than your rhymes, ya dig?
const memorySchema = mongoose.Schema({ | ||
total_bytes: { type: Number, default: 0 }, | ||
available_bytes: { type: Number, default: 0 }, | ||
used_bytes: { type: Number, default: 0 }, | ||
usage_percent: { type: Number, default: 0 }, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yo, this memory schema's got holes like Swiss cheese, bruh!
A'ight, check it. Your memory schema's lookin' like it forgot some bars. Here's what's up:
-
That usage_percent defaultin' to 0 is whack. It's like startin' a rap battle with "I got nothin' to say."
-
We gotta make sure them used_bytes ain't bigger than total_bytes. That's like claimin' you spit more rhymes than words in the dictionary!
-
Let's add some validation to keep it real, ya feel me?
Here's a remix that'll make your schema flow smoother than Eminem:
const memorySchema = mongoose.Schema({
total_bytes: { type: Number, required: true, min: 0 },
available_bytes: { type: Number, required: true, min: 0 },
used_bytes: { type: Number, required: true, min: 0 },
usage_percent: { type: Number, min: 0, max: 100 },
});
memorySchema.pre('save', function(next) {
if (this.used_bytes > this.total_bytes) {
next(new Error("Used bytes can't be more than total bytes, that's whack!"));
} else {
this.usage_percent = (this.used_bytes / this.total_bytes) * 100;
next();
}
});
Now your schema's gonna be tighter than your mom's spaghetti, know what I'm sayin'?
const discSchema = mongoose.Schema({ | ||
read_speed_bytes: { type: Number, default: 0 }, | ||
write_speed_bytes: { type: Number, default: 0 }, | ||
total_bytes: { type: Number, default: 0 }, | ||
free_bytes: { type: Number, default: 0 }, | ||
usage_percent: { type: Number, default: 0 }, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yo, this disk schema's got more typos than a freestyle gone wrong!
Listen up, homie. Your disk schema's got some issues that'll make your code stutter like a nervous rapper. Check it:
-
You spelled "disk" as "disc". That's like misspellin' your own stage name, dawg!
-
That usage_percent defaultin' to 0 is as weak as usin' "baby" as your only rhyme.
-
We gotta make sure them free_bytes ain't bigger than total_bytes. That's like claimin' you got more money than Bill Gates!
Here's a remix that'll make your schema flow smoother than butter:
const diskSchema = mongoose.Schema({
read_speed_bytes: { type: Number, min: 0 },
write_speed_bytes: { type: Number, min: 0 },
total_bytes: { type: Number, required: true, min: 0 },
free_bytes: { type: Number, required: true, min: 0 },
usage_percent: { type: Number, min: 0, max: 100 },
});
diskSchema.pre('save', function(next) {
if (this.free_bytes > this.total_bytes) {
next(new Error("Free bytes can't be more than total bytes, that's whack!"));
} else {
this.usage_percent = ((this.total_bytes - this.free_bytes) / this.total_bytes) * 100;
next();
}
});
Now your schema's gonna be as tight as your rhymes after a week of practice, ya feel me?
const hostSchema = mongoose.Schema({ | ||
os: { type: String, default: "" }, | ||
platform: { type: String, default: "" }, | ||
kernel_version: { type: String, default: "" }, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yo, this host schema's as empty as a wack rapper's vocabulary!
A'ight, check it. Your host schema's lookin' like it's got stage fright. Here's the 411:
-
Them empty strings as defaults? That's like showin' up to a rap battle with nothin' but "uh" and "yeah". We can do better, homie!
-
We could use some validation to make sure we ain't gettin' played with bogus info.
Here's a remix that'll make your schema as solid as Eminem's rhymes:
const hostSchema = mongoose.Schema({
os: { type: String, required: true, trim: true },
platform: { type: String, required: true, trim: true },
kernel_version: { type: String, required: true, trim: true },
});
hostSchema.path('os').validate(function (value) {
return value.length > 0;
}, 'OS can\'t be an empty string, that\'s whack!');
hostSchema.path('platform').validate(function (value) {
return value.length > 0;
}, 'Platform can\'t be an empty string, ya dig?');
hostSchema.path('kernel_version').validate(function (value) {
return value.length > 0;
}, 'Kernel version can\'t be an empty string, for real!');
Now your schema's gonna be droppin' facts like you drop sick beats!
Server/db/models/HardwareCheck.js
Outdated
const HardwareCheckSchema = mongoose.Schema( | ||
{ | ||
monitorId: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: "Monitor", | ||
immutable: true, | ||
}, | ||
cpu: { | ||
type: cpuSchema, | ||
default: () => ({}), | ||
}, | ||
memory: { | ||
type: memorySchema, | ||
default: () => ({}), | ||
}, | ||
disk: { | ||
type: discSchema, | ||
default: () => ({}), | ||
}, | ||
host: { | ||
type: hostSchema, | ||
default: () => ({}), | ||
}, | ||
}, | ||
{ timestamps: true } | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Yo, this HardwareCheckSchema's the real MVP, but it could use some bling!
Listen up, dawg. Your HardwareCheckSchema's lookin' fresh like a new pair of kicks, but we can make it shine even brighter. Here's the lowdown:
- That monitorId reference? That's tight, like a perfectly timed beat drop.
- Usin' them sub-schemas? That's smooth, like a well-executed flow.
- Them timestamps? That's on point, like hittin' the right rhyme at the right time.
But yo, we can add some extra sauce to make it even more fire:
Here's a lil' remix to consider:
const HardwareCheckSchema = mongoose.Schema(
{
monitorId: {
type: mongoose.Schema.Types.ObjectId,
ref: "Monitor",
required: true,
immutable: true,
},
cpu: {
type: cpuSchema,
required: true,
},
memory: {
type: memorySchema,
required: true,
},
disk: {
type: diskSchema,
required: true,
},
host: {
type: hostSchema,
required: true,
},
},
{
timestamps: true,
toJSON: { virtuals: true },
toObject: { virtuals: true }
}
);
// Add a virtual for total memory usage
HardwareCheckSchema.virtual('totalMemoryUsage').get(function() {
return this.memory.total_bytes - this.memory.available_bytes;
});
This way, your schema's gonna be droppin' hot facts and calculated fields like you drop hot bars in a cypher, ya feel me?
Hi everyone. I forgot that there can be more than 1 disk in a server. 1 disk is OK but are we going to handle multiple disks for now? @gorkem-bwl If we need to handle multiple disks then we should make the discModel an array. [
{}, // master disk metrics
{}, // backup disk metrics
{} // backup disk metrics
] |
Let's go with multiple disks in v1.0 and let me think on the UI side a little bit more. |
This PR adds a mongoDB model for hardware monitoring
This model is based on data models provided by server monitoring agent developer @mertssmnoglu :
CPU Response
Memory Response
Disk Response
Host Response