changes to memory
parent
0a7ebc9f34
commit
ee2ea41d8b
|
@ -16,6 +16,10 @@ const memoryLimits = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function memory(client: Client) {
|
export default function memory(client: Client) {
|
||||||
|
const set = new Set<string>();
|
||||||
|
setInterval(() => {
|
||||||
|
set.clear();
|
||||||
|
}, 3600000);
|
||||||
setInterval(async () => {
|
setInterval(async () => {
|
||||||
try {
|
try {
|
||||||
const accounts = await client.db.Account.find();
|
const accounts = await client.db.Account.find();
|
||||||
|
@ -27,49 +31,76 @@ export default function memory(client: Client) {
|
||||||
const memoryConversion = mem / 1024 / 1024;
|
const memoryConversion = mem / 1024 / 1024;
|
||||||
const userLimits: { soft?: number, hard?: number } = {};
|
const userLimits: { soft?: number, hard?: number } = {};
|
||||||
const tier: TierInterface = await client.db.Tier.findOne({ id: acc.tier }).lean().exec();
|
const tier: TierInterface = await client.db.Tier.findOne({ id: acc.tier }).lean().exec();
|
||||||
userLimits.soft = tier.resourceLimits.ram;
|
userLimits.soft = tier.resourceLimits.ram - 50;
|
||||||
userLimits.hard = tier.resourceLimits.ram + 5;
|
userLimits.hard = tier.resourceLimits.ram + 10;
|
||||||
|
|
||||||
/* if the user has exceeded their soft memory limit, which is the one described in the
|
/* if the user has exceeded their soft memory limit, which is the one described in the
|
||||||
resource limit guidelines, we'll inform staff.
|
resource limit guidelines, we'll inform staff.
|
||||||
*/
|
*/
|
||||||
if (memoryConversion >= userLimits.soft) {
|
if (memoryConversion >= userLimits.hard && set.has(acc.username)) {
|
||||||
client.signale.info(`RAM Soft Limit Reached | ${acc.username} | ${memoryConversion}/${userLimits.soft} MB`);
|
client.signale.info(`RAM Hard Limit Reached | ${acc.username} | ${memoryConversion}/${userLimits.hard} MB`);
|
||||||
|
client.util.exec(`killall -9 -u ${acc.username}`);
|
||||||
const embed = new RichEmbed();
|
const embed = new RichEmbed();
|
||||||
if (client.users.get(acc.userID)) embed.setThumbnail(client.users.get(acc.userID).avatarURL);
|
embed.setTitle('Resource Enforcement Notification');
|
||||||
|
embed.setDescription('Someone has reached the (hard) resource limit for their tier on RAM. The system has automatically killed all of their processes.');
|
||||||
embed.addField('User', `${acc.username} | <@${acc.userID}> | ${acc.userID}`, true);
|
embed.addField('User', `${acc.username} | <@${acc.userID}> | ${acc.userID}`, true);
|
||||||
embed.addField('Tier', String(acc.tier), true);
|
embed.addField('Tier', String(acc.tier), true);
|
||||||
embed.addField('Memory Usage', `${String(memoryConversion)} MB`, true);
|
embed.addField('Memory Usage', `${String(memoryConversion)} MB`, true);
|
||||||
embed.addField('Memory Limit', `${String(userLimits.soft)} MB`, true);
|
embed.addField('Memory Limit', `${String(userLimits.hard)} MB`, true);
|
||||||
|
client.createMessage(channelID, { embed });
|
||||||
|
client.util.createModerationLog(acc.userID, client.guilds.get('446067825673633794').members.get(client.user.id), 1, '[AUTO] Exceeded resource limit for RAM.');
|
||||||
|
client.util.transport.sendMail({
|
||||||
|
to: acc.emailAddress,
|
||||||
|
from: 'Library of Code sp-us | Cloud Services <help@libraryofcode.org>',
|
||||||
|
subject: 'Your account has been warned',
|
||||||
|
html: `
|
||||||
|
<h1>Library of Code sp-us | Cloud Services</h1>
|
||||||
|
<p>Your account has received an official warning from a Technician. Please get the underlying issue resolved to avoid <i>possible</i> moderative action.</p>
|
||||||
|
<p><strong>Reason:</strong> [AUTO] Exceeded resource limit for RAM.</p>
|
||||||
|
<p><strong>Moderator:</strong> ${client.user.username}</p>
|
||||||
|
|
||||||
|
<b><i>Library of Code sp-us | Support Team</i></b>
|
||||||
|
`,
|
||||||
|
});
|
||||||
|
client.createMessage(channelID, { embed });
|
||||||
|
set.delete(acc.username);
|
||||||
|
} else if (memoryConversion >= userLimits.soft && !set.has(acc.username)) {
|
||||||
|
client.signale.info(`RAM Soft Limit Reached | ${acc.username} | ${memoryConversion}/${userLimits.soft} MB`);
|
||||||
|
const embed = new RichEmbed();
|
||||||
|
if (client.users.get(acc.userID)) embed.setThumbnail(client.users.get(acc.userID).avatarURL);
|
||||||
|
embed.setTitle('Resource Limit Notification');
|
||||||
|
embed.setDescription('Someone has reached the (soft) resource limit for their tier on RAM.');
|
||||||
|
embed.addField('User', `${acc.username} | <@${acc.userID}> | ${acc.userID}`, true);
|
||||||
|
embed.addField('Tier', String(acc.tier), true);
|
||||||
|
embed.addField('Memory Usage', `${String(memoryConversion)} MB`, true);
|
||||||
|
embed.addField('Memory Limit', `${String(userLimits.hard)} MB`, true);
|
||||||
embed.setFooter(client.user.username, client.user.avatarURL);
|
embed.setFooter(client.user.username, client.user.avatarURL);
|
||||||
embed.setTimestamp();
|
embed.setTimestamp();
|
||||||
|
await client.createMessage(channelID, { embed });
|
||||||
|
const notifyEmbed = new RichEmbed()
|
||||||
|
.setTitle('Cloud Account | Notification')
|
||||||
|
.setDescription(`You are about to reach your RAM resource limits, you are currently using '${String(memoryConversion)} MB' and your limit is '${String(userLimits.hard)} MB'. Please correct your usage to avoid further action.`)
|
||||||
|
.addField('Technician', 'SYSTEM', true)
|
||||||
|
.setFooter(this.client.user.username, this.client.user.avatarURL)
|
||||||
|
.setTimestamp();
|
||||||
|
this.client.getDMChannel(acc.userID).then((channel) => {
|
||||||
|
channel.createMessage({ notifyEmbed });
|
||||||
|
});
|
||||||
|
notifyEmbed.addField('User', `${acc.username} | <@${acc.userID}>`, true);
|
||||||
|
this.client.createMessage('580950455581147146', { embed });
|
||||||
|
this.client.util.transport.sendMail({
|
||||||
|
to: acc.emailAddress,
|
||||||
|
from: 'Library of Code sp-us | Cloud Services <help@libraryofcode.org>',
|
||||||
|
subject: 'Notification',
|
||||||
|
html: `
|
||||||
|
<h1>Library of Code sp-us | Cloud Services</h1>
|
||||||
|
<p>You are about to reach your RAM resource limits, you are currently using '${String(memoryConversion)} MB' and your limit is '${String(userLimits.hard)} MB'. Please correct your usage to avoid further action.</p>
|
||||||
|
<p><strong>Technician:</strong> SYSTEM</p>
|
||||||
|
|
||||||
// if they exceed the hard limit, we'll kill all of their processes.
|
<b><i>Library of Code sp-us | Support Team</i></b>
|
||||||
if (memoryConversion >= userLimits.hard) {
|
`,
|
||||||
client.signale.info(`RAM Hard Limit Reached | ${acc.username} | ${memoryConversion}/${userLimits.hard} MB`);
|
});
|
||||||
client.util.exec(`killall -9 -u ${acc.username}`);
|
set.add(acc.username);
|
||||||
embed.setTitle('Resource Enforcement Notification');
|
|
||||||
embed.setDescription('Someone has reached the (hard) resource limit for their tier on RAM. The system has automatically killed all of their processes.');
|
|
||||||
client.util.createModerationLog(acc.userID, client.guilds.get('446067825673633794').members.get(client.user.id), 1, '[AUTO] Exceeded resource limit for RAM.');
|
|
||||||
client.util.transport.sendMail({
|
|
||||||
to: acc.emailAddress,
|
|
||||||
from: 'Library of Code sp-us | Cloud Services <help@libraryofcode.org>',
|
|
||||||
subject: 'Your account has been warned',
|
|
||||||
html: `
|
|
||||||
<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>
|
|
||||||
<p><strong>Reason:</strong> [AUTO] Exceeded resource limit for RAM.</p>
|
|
||||||
<p><strong>Moderator:</strong> ${client.user.username}</p>
|
|
||||||
|
|
||||||
<b><i>Library of Code sp-us | Support Team</i></b>
|
|
||||||
`,
|
|
||||||
});
|
|
||||||
} 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 });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
Loading…
Reference in New Issue