Update script.sh
This commit is contained in:
@@ -1,79 +1,88 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Récupération des données
|
||||
mem_usage=$(free -m | awk 'NR==2{printf "%.2f%%\t", $3*100/$2 }')
|
||||
disk_usage=$(df -h | awk '$NF=="/"{printf "%s\t", $5}')
|
||||
net_usage=$(ifstat -i enp6s18 1 1 | awk 'NR==3{print $1, $3}') # enp6s18 = interface réseau
|
||||
server_response=$(ping -c 1 google.com | awk -F '/' 'END {print $5}')
|
||||
running_processes=$(ps aux | wc -l)
|
||||
uptime=$(uptime -p)
|
||||
cpu_name=$(lscpu | grep "Model name" | awk -F: '{print $2}')
|
||||
distrib_name=$(lsb_release -s -d)
|
||||
# Replace the URL below with your Discord webhook URL
|
||||
WEBHOOK_URL="https://discord.com/api/webhooks/"
|
||||
|
||||
# Envoi des données à Discord en utilisant jq
|
||||
data=$(jq -n \
|
||||
--arg title "Statistiques du VPS" \
|
||||
--arg color "10281099" \
|
||||
--arg mem_usage "$mem_usage" \
|
||||
--arg disk_usage "$disk_usage" \
|
||||
--arg net_usage "$net_usage %" \
|
||||
--arg server_response "$server_response ms" \
|
||||
--arg running_processes "$running_processes" \
|
||||
--arg uptime "$uptime" \
|
||||
--arg cpu_name "$cpu_name" \
|
||||
--arg distrib_name "$distrib_name" \
|
||||
--arg thumbnail_url "https://i.imgur.com/XT82bq2.png" \ # Image du système d'exploitation
|
||||
'{
|
||||
embeds: [
|
||||
# Replace the URL below with the desired image URL
|
||||
IMAGE_URL="https://i.imgur.com/XT82bq2.png"
|
||||
|
||||
# Collecting server information
|
||||
used_ram=$(free -m | awk 'NR==2{printf "%.2f", $3*100/$2}')
|
||||
disk_usage=$(df -h | awk '$NF=="/"{printf "%s", $5}')
|
||||
server_response_time=$(ping -c 1 google.com | awk -F '/' 'END {print $5}')
|
||||
running_processes=$(ps aux | wc -l)
|
||||
uptime=$(uptime -p | cut -d " " -f 2-)
|
||||
cpu_name=$(lscpu | grep "Model name" | awk -F: '{print $2}')
|
||||
distro_full_name=$(lsb_release -s -d)
|
||||
network_bandwidth_usage=$(ifstat -i enp6s18 1 1 | awk 'NR==3{print $1, $3}') # enp6s18 = network interface
|
||||
|
||||
# Creating JSON data for the Discord embed
|
||||
timestamp=$(date +%s)
|
||||
time_string=$(date --date="@${timestamp}" +%H:%M)
|
||||
title="Linux Server Statistics ➜ <t:${timestamp}:f>"
|
||||
json_data=$(cat <<EOF
|
||||
{
|
||||
"embeds": [
|
||||
{
|
||||
title: $title,
|
||||
color: $color,
|
||||
thumbnail: {
|
||||
url: $thumbnail_url
|
||||
},
|
||||
fields: [
|
||||
"title": "$title",
|
||||
"color": 65407,
|
||||
"fields": [
|
||||
{
|
||||
name: "Utilisation de la mémoire",
|
||||
value: $mem_usage,
|
||||
inline: true
|
||||
"name": "💻・CPU Name",
|
||||
"value": "$cpu_name",
|
||||
"inline": true
|
||||
},
|
||||
{
|
||||
name: "Utilisation du disque",
|
||||
value: $disk_usage,
|
||||
inline: true
|
||||
"name": "📂・Distribution",
|
||||
"value": "$distro_full_name",
|
||||
"inline": true
|
||||
},
|
||||
{
|
||||
name: "Utilisation de la bande passante du réseau",
|
||||
value: $net_usage,
|
||||
inline: true
|
||||
"name": "📡・Uptime",
|
||||
"value": "$uptime",
|
||||
"inline": true
|
||||
},
|
||||
{
|
||||
name: "Temps de réponse du serveur",
|
||||
value: $server_response,
|
||||
inline: true
|
||||
"name": "🖧・Network Bandwidth Usage (RX/TX)",
|
||||
"value": "$network_bandwidth_usage GiB",
|
||||
"inline": true
|
||||
},
|
||||
{
|
||||
name: "Nombre de processus en cours",
|
||||
value: $running_processes,
|
||||
inline: true
|
||||
"name": "💽・Used RAM Memory",
|
||||
"value": "$used_ram%",
|
||||
"inline": true
|
||||
},
|
||||
{
|
||||
name: "Uptime du serveur",
|
||||
value: $uptime,
|
||||
inline: true
|
||||
"name": "💾・Disk Usage",
|
||||
"value": "$disk_usage",
|
||||
"inline": true
|
||||
},
|
||||
{
|
||||
name: "Nom du CPU",
|
||||
value: $cpu_name,
|
||||
inline: true
|
||||
"name": "⏳・Server Response Time",
|
||||
"value": "$server_response_time ms",
|
||||
"inline": true
|
||||
},
|
||||
{
|
||||
name: "Nom complet de la distribution",
|
||||
value: $distrib_name,
|
||||
inline: true
|
||||
"name": "📇・Running Processes",
|
||||
"value": "$running_processes",
|
||||
"inline": true
|
||||
}
|
||||
],
|
||||
"thumbnail": {
|
||||
"url": "$IMAGE_URL"
|
||||
},
|
||||
"footer": {
|
||||
"text": "Copyright UltraLion#0404 © $(date +%Y)"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}')
|
||||
curl -H "Content-Type: application/json" -X POST -d "$data" https://discord.com/api/webhooks/ # Mettre votre webhook discord ici
|
||||
}
|
||||
|
||||
EOF
|
||||
)
|
||||
|
||||
# Sending the embed to the Discord webhook
|
||||
curl -X POST -H "Content-Type: application/json" -d "$json_data" $WEBHOOK_URL
|
||||
|
||||
# Exit the script
|
||||
exit
|
||||
|
||||
Reference in New Issue
Block a user