forked from engineering/cloudservices
fix memory checking issue
parent
4ca2e9b188
commit
271cfe1959
|
@ -15,66 +15,72 @@ export const memoryLimits = {
|
||||||
|
|
||||||
export default function memory(client: Client) {
|
export default function memory(client: Client) {
|
||||||
setInterval(async () => {
|
setInterval(async () => {
|
||||||
const accounts = await client.db.Account.find();
|
try {
|
||||||
console.log(accounts);
|
const accounts = await client.db.Account.find();
|
||||||
for (const acc of accounts) {
|
console.log(accounts);
|
||||||
console.log(acc);
|
for (const acc of accounts) {
|
||||||
if (acc.root) return;
|
console.log(acc);
|
||||||
// memory in bytes
|
if (acc.root === true) return;
|
||||||
const mem = Number(await client.util.exec(`memory ${acc.username}`)) * 1000;
|
// memory in bytes
|
||||||
// memory in megabytes
|
const mem = Number(await client.util.exec(`memory ${acc.username}`)) * 1000;
|
||||||
const memoryConversion = mem / 1024 / 1024;
|
console.log(mem);
|
||||||
let userLimits: { soft: number, hard: number };
|
// memory in megabytes
|
||||||
if (acc.tier === 1) {
|
const memoryConversion = mem / 1024 / 1024;
|
||||||
userLimits = { soft: memoryLimits.TIER_1_SOFT, hard: memoryLimits.TIER_1_HARD };
|
console.log(memoryConversion);
|
||||||
} else if (acc.tier === 2) {
|
let userLimits: { soft: number, hard: number };
|
||||||
userLimits = { soft: memoryLimits.TIER_2_SOFT, hard: memoryLimits.TIER_2_HARD };
|
if (acc.tier === 1) {
|
||||||
} else if (acc.tier === 3) {
|
userLimits = { soft: memoryLimits.TIER_1_SOFT, hard: memoryLimits.TIER_1_HARD };
|
||||||
userLimits = { soft: memoryLimits.TIER_3_SOFT, hard: memoryLimits.TIER_3_HARD };
|
} else if (acc.tier === 2) {
|
||||||
}
|
userLimits = { soft: memoryLimits.TIER_2_SOFT, hard: memoryLimits.TIER_2_HARD };
|
||||||
|
} else if (acc.tier === 3) {
|
||||||
/* if the user has exceeded their soft memory limit, which is the one described in the
|
userLimits = { soft: memoryLimits.TIER_3_SOFT, hard: memoryLimits.TIER_3_HARD };
|
||||||
resource limit guidelines, we'll inform staff.
|
}
|
||||||
*/
|
|
||||||
console.log(memoryConversion, userLimits.soft, userLimits.hard);
|
/* if the user has exceeded their soft memory limit, which is the one described in the
|
||||||
if (memoryConversion >= userLimits.soft) {
|
resource limit guidelines, we'll inform staff.
|
||||||
client.signale.info(`RAM Soft Limit Reached | ${acc.username} | ${memoryConversion}/${userLimits.soft} MB`);
|
*/
|
||||||
const embed = new RichEmbed();
|
console.log(memoryConversion, userLimits.soft, userLimits.hard);
|
||||||
if (client.users.get(acc.userID)) embed.setThumbnail(client.users.get(acc.userID).avatarURL);
|
if (memoryConversion >= userLimits.soft) {
|
||||||
embed.addField('User', `${acc.username} | <@${acc.userID}> | ${acc.userID}`, true);
|
client.signale.info(`RAM Soft Limit Reached | ${acc.username} | ${memoryConversion}/${userLimits.soft} MB`);
|
||||||
embed.addField('Tier', String(acc.tier), true);
|
const embed = new RichEmbed();
|
||||||
embed.addField('Memory Usage', `${String(memoryConversion)} MB`, true);
|
if (client.users.get(acc.userID)) embed.setThumbnail(client.users.get(acc.userID).avatarURL);
|
||||||
embed.addField('Memory Limit', `${String(userLimits.soft)} MB`, true);
|
embed.addField('User', `${acc.username} | <@${acc.userID}> | ${acc.userID}`, true);
|
||||||
embed.setFooter(client.user.username, client.user.avatarURL);
|
embed.addField('Tier', String(acc.tier), true);
|
||||||
embed.setTimestamp();
|
embed.addField('Memory Usage', `${String(memoryConversion)} MB`, true);
|
||||||
|
embed.addField('Memory Limit', `${String(userLimits.soft)} MB`, true);
|
||||||
// if they exceed the hard limit, we'll kill all of their processes.
|
embed.setFooter(client.user.username, client.user.avatarURL);
|
||||||
if (memoryConversion >= userLimits.hard) {
|
embed.setTimestamp();
|
||||||
client.signale.info(`RAM Hard Limit Reached | ${acc.username} | ${memoryConversion}/${userLimits.hard} MB`);
|
|
||||||
client.util.exec(`killall -9 -u ${acc.username}`);
|
// if they exceed the hard limit, we'll kill all of their processes.
|
||||||
embed.setTitle('Resource Enforcement Notification');
|
if (memoryConversion >= userLimits.hard) {
|
||||||
embed.setDescription('Someone has reached the (hard) resource limit for their tier on RAM. The system has automatically killed all of their processes.');
|
client.signale.info(`RAM Hard Limit Reached | ${acc.username} | ${memoryConversion}/${userLimits.hard} MB`);
|
||||||
client.util.createModerationLog(acc.userID, client.guilds.get('446067825673633794').members.get(client.user.id), 1, '[AUTO] Exceeded resource limit for RAM.');
|
client.util.exec(`killall -9 -u ${acc.username}`);
|
||||||
client.util.transport.sendMail({
|
embed.setTitle('Resource Enforcement Notification');
|
||||||
to: acc.emailAddress,
|
embed.setDescription('Someone has reached the (hard) resource limit for their tier on RAM. The system has automatically killed all of their processes.');
|
||||||
from: 'Library of Code sp-us | Cloud Services <help@libraryofcode.org>',
|
client.util.createModerationLog(acc.userID, client.guilds.get('446067825673633794').members.get(client.user.id), 1, '[AUTO] Exceeded resource limit for RAM.');
|
||||||
subject: 'Your account has been warned',
|
client.util.transport.sendMail({
|
||||||
html: `
|
to: acc.emailAddress,
|
||||||
<h1>Library of Code sp-us | Cloud Services</h1>
|
from: 'Library of Code sp-us | Cloud Services <help@libraryofcode.org>',
|
||||||
<p>Your account has received an official warning from a Moderator. Please get the underlying issue resolved to avoid <i>possible</i> moderative action.</p>
|
subject: 'Your account has been warned',
|
||||||
<p><strong>Reason:</strong> [AUTO] Exceeded resource limit for RAM.</p>
|
html: `
|
||||||
<p><strong>Moderator:</strong> ${client.user.username}</p>
|
<h1>Library of Code sp-us | Cloud Services</h1>
|
||||||
|
<p>Your account has received an official warning from a Moderator. Please get the underlying issue resolved to avoid <i>possible</i> moderative action.</p>
|
||||||
<b><i>Library of Code sp-us | Support Team</i></b>
|
<p><strong>Reason:</strong> [AUTO] Exceeded resource limit for RAM.</p>
|
||||||
`,
|
<p><strong>Moderator:</strong> ${client.user.username}</p>
|
||||||
});
|
|
||||||
} else {
|
<b><i>Library of Code sp-us | Support Team</i></b>
|
||||||
embed.setTitle('Resource Limit Notification');
|
`,
|
||||||
embed.setDescription('Someone has reached the (soft) resource limit for their tier on RAM.');
|
});
|
||||||
|
} else {
|
||||||
|
embed.setTitle('Resource Limit Notification');
|
||||||
|
embed.setDescription('Someone has reached the (soft) resource limit for their tier on RAM.');
|
||||||
|
}
|
||||||
|
// @ts-ignore
|
||||||
|
client.createMessage(channelID, { embed });
|
||||||
}
|
}
|
||||||
// @ts-ignore
|
|
||||||
client.createMessage(channelID, { embed });
|
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
client.util.handleError(err);
|
||||||
}
|
}
|
||||||
}, 60000);
|
}, 60000);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue