Nexus
Discord
  • 📗Getting Started
    • Nexus Website
  • 👥Contributors
  • 🤝Code of Conduct
  • 🚨License
  • 📔Contributing
  • git
    • 🍎Installing Git on MacOS
    • 🪟Installing Git on Windows
    • 🐧Installing Git on Linux
    • 🛠️Git Guide
  • Building the Bot
    • Before you begin
    • First Steps
    • The .env file
    • Custom Bot Functions
  • Commands
    • Creating Commands
    • Creating User Installed Commands
    • Creating Developer Commands
    • Developer Guild Commands
    • Autocomplete
  • Client Modifications
    • client.m
  • handler
    • Handling Discord Events
    • Handling Components
  • Scripts
    • Our customs scripts
    • package.json
    • cleardb
    • db
    • client
    • fetch
    • reset
  • Database
    • MongoDB Connection
    • MongoDB Schemas
  • Resources
    • Privacy Policy
    • Terms of Service
    • NodeJS Download
    • Discord.js
    • Discord.js v14 Guide
    • Discord.js v14 Docs
  • Code Editors
    • Finding your best Code editor
    • Visual Studio IDE Download
    • Visual Studio Code Download
    • VS Code Insiders Download
    • Jetbrains WebStorm Download
    • Jetbrains Fleet Download
    • Jetbrains Aqua Download
Powered by GitBook
On this page
  1. Scripts

db

db is a script to ping your mongodb shards. It console logs the ping (obviuosly)

Code:

const urls = [
    "nexus-db-shard-00-00.1llff.mongodb.net",
    "nexus-db-shard-00-01.1llff.mongodb.net",
    "nexus-db-shard-00-02.1llff.mongodb.net" //replace them with your own shards btw
];

const util = require('util');
const exec = util.promisify(require('child_process').exec);
const chalk = require('chalk');
const os = require('os');

// Function to extract latency from ping output
function extractLatency(output) {
    const lines = output.split('\n');
    const latencyLines = lines.filter(line => line.includes('time='));
    
    return latencyLines.map(line => {
        const match = line.match(/time=(\d+ms)/);
        return match ? match[1] : null;
    }).filter(latency => latency != null);
}

const ping = async (host, shardNumber) => {
    let cmd = '';

    if (os.platform() === 'win32') {
        cmd = `ping -n 1 ${host}`;
    } else {
        cmd = `ping -c 1 ${host}`;
    }

    try {
        const { stdout } = await exec(cmd);
        const latencies = extractLatency(stdout);
        console.log(chalk.green(`Latency for shard ${shardNumber}:`), chalk.magenta(latencies.join(', ')));
    } catch (error) {
        console.error(chalk.red('Error:', error));
    }
};

urls.forEach((u, index) => {
    const shardNumber = index + 1;
    console.log(chalk.cyan(`Testing MongoDB Shard ${shardNumber}...`));
    ping(u, shardNumber);
});
PreviouscleardbNextclient

Last updated 9 months ago