Skip to content

Commit

Permalink
Merge pull request #65 from discordextremelist/Cairo2k18-patch-1
Browse files Browse the repository at this point in the history
Add new metrics
  • Loading branch information
carolinaisslaying authored Jul 16, 2020
2 parents 78ffb47 + eddf7e0 commit 0c661b5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "del-website",
"version": "5.1.0-Release",
"version": "5.1.1-Release",
"description": "Discord Extreme List, Discord's unbiased list! Official source code for the DEL v5 website!",
"main": "dist/src/app.js",
"directories": {
Expand Down
2 changes: 1 addition & 1 deletion release-info.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "5.1.0-Release",
"version": "5.1.1-Release",
"channel": "Release",
"cssVersion": "756d2e7250ac825ed3ea2a5097dfa2df"
}
47 changes: 28 additions & 19 deletions src/Util/Services/discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,33 +106,47 @@ export async function postMetric() {
}

export async function postWebMetric(type: string) {
switch (type) {
case "bot":
const bots: delBot[] = await global.db
const bots: delBot[] = await global.db
.collection("bots")
.find()
.toArray();


const servers: delServer[] = await global.db
.collection("servers")
.find()
.toArray();

const templates: delTemplate[] = await global.db
.collection("templates")
.find()
.toArray();

const users: delUser[] = await global.db
.collection("users")
.find()
.toArray();

switch (type) {
case "bot":
settings.website.dev
? metrics.gauge("del.website.dev.botCount", bots.length)
: metrics.gauge("del.website.botCount", bots.length);
break;
case "bot_unapproved":
const unapprovedBots = bots.filter(
(b) => !b.status.approved && !b.status.archived
)

settings.website.dev
? metrics.gauge("del.website.dev.botCount.unapproved", unapprovedBots.length)
: metrics.gauge("del.website.botCount.unapproved", unapprovedBots.length);
break;
case "server":
const servers: delServer[] = await global.db
.collection("servers")
.find()
.toArray();

settings.website.dev
? metrics.gauge("del.website.dev.serverCount", servers.length)
: metrics.gauge("del.website.serverCount", servers.length);
break;
case "template":
const templates: delTemplate[] = await global.db
.collection("templates")
.find()
.toArray();

settings.website.dev
? metrics.gauge(
"del.website.dev.templateCount",
Expand All @@ -141,11 +155,6 @@ export async function postWebMetric(type: string) {
: metrics.gauge("del.website.templateCount", templates.length);
break;
case "user":
const users: delUser[] = await global.db
.collection("users")
.find()
.toArray();

settings.website.dev
? metrics.gauge("del.website.dev.userCount", users.length)
: metrics.gauge("del.website.userCount", users.length);
Expand Down
6 changes: 6 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ new Promise((resolve, reject) => {
await ddosMode.updateCache();
await botStatsUpdate();
await tokenManager.tokenResetAll();

await discord.postWebMetric("bot");
await discord.postWebMetric("bot_unapproved");
await discord.postWebMetric("server");
await discord.postWebMetric("template");
await discord.postWebMetric("user");

setTimeout(async () => {
await discord.postMetric();
Expand Down

0 comments on commit 0c661b5

Please sign in to comment.