Logo signature de Brรฉval Le Floch

How to Monitor Your Server Disk Usage with Discord? ๐Ÿš€๐ŸŒŸ

How to Monitor Your Server Disk Usage with Discord? ๐Ÿš€๐ŸŒŸ

How to Monitor Your Server Disk Usage with Discord? ๐Ÿš€๐ŸŒŸ

Ever thought your server could talk to you? Imagine receiving daily disk space updates directly on Discord. Sounds like magic, right? ๐ŸŽฉโœจ

Letโ€™s dive in and set this up !

๐Ÿ•ต๏ธ Step 1: Create a Discord Webhook

Creating a Discord webhook is like assigning a secret agent to your server. It's the first step in enabling seamless communication between your server and your Discord channel.

How to Set Up Your Secret Agent

  1. Navigate to Discord: Choose the channel for updates and select Edit channel > Integrations.
  2. Webhook Setup: If you're a webhook newbie, click Create Webhook. Otherwise, hit View Webhooks and then New Webhook.
  3. Identity Assignment: Give your webhook a name and an avatar to make it recognizable.
  4. Secure the Code: Copy the WEBHOOK URL; this is your secret code for communication.
  5. Mission Save: Donโ€™t forget to hit Save.

Pasted image 20240310013126.png

Pasted image 20240310013304.png

๐Ÿš€ Connect to Your Server

Itโ€™s time to go undercover. SSH into your server because this operation requires some command-line finesse.

๐ŸŒŸ Step 2: The Magic Script

Create a script named check-disk.sh. This script is the heart of our operation, allowing your server to send those crucial disk space updates.

Craft Your Spell

#!/bin/bash

# Insert your webhook URL here - it's the direct line to Discord.
DISCORD_WEBHOOK_URL="https://discord.com/api/webhooks/XXXXXXXX/XXXXXXXXXX"

# Capturing the free space on your server. Everyone loves a bit of freedom, right?
ESPACE=$(df -h | grep '/dev/sda2' | awk '{print $4}')

# Sending the update through the magical portal of the internet.
curl -H "Content-Type: application/json" -X POST -d "{\"content\": \"๐Ÿ—ƒ๏ธ Free disk space: $ESPACE\"}" "$DISCORD_WEBHOOK_URL"

This spell enables your server to whisper sweet nothings about its available disk space directly into your Discord.

โญ Step 3: Bring the Magic to Life

  1. Embed the Secret Code: Replace DISCORD_WEBHOOK_URL with your unique webhook URL.
  2. Awaken the Script: Grant it the power to execute:
sudo chmod +x ./check-disk.sh

๐ŸŽฅ Step 4: The Daily Ritual

We want this magical communication to be a daily delight. Let's automate it:

crontab -e

Whisper this incantation at the document's end:

0 12 * * * /bin/bash /home/username/check-disk.sh

Now, like clockwork, your server will serenade you with updates every noon. ๐Ÿฝ๏ธ๐Ÿ•›

โค๏ธ Step 5: Reignite Cronโ€™s Heart

Sometimes, even ancient spirits need a reminder:

systemctl restart cron

๐ŸŒ Step 7: Bask in the Glory

Congratulations! Youโ€™ve successfully bridged worlds. Your server is now sending daily disk space updates directly to your Discord. Welcome to a future where technology connects more deeply with our lives. ๐Ÿš€๐Ÿ”ฎ

Pasted image 20240310013946.png