mirror of
https://github.com/minoplhy/scriptbox.git
synced 2024-12-05 01:46:57 +00:00
sysstat_webhook : init
This commit is contained in:
parent
2e4bd40258
commit
1de2ccafd9
6
sysstat_webhook/README.md
Normal file
6
sysstat_webhook/README.md
Normal file
@ -0,0 +1,6 @@
|
||||
# Sysstat_Webhook
|
||||
|
||||
currrently, WIP. But yeah, Discord sucks! They don't rendering SVG.
|
||||
```
|
||||
sudo apt install -y librsvg2-bin
|
||||
```
|
83
sysstat_webhook/stat_discord.sh
Normal file
83
sysstat_webhook/stat_discord.sh
Normal file
@ -0,0 +1,83 @@
|
||||
#!/bin/bash
|
||||
|
||||
while getopts 'w:crdnf:' flag
|
||||
do
|
||||
case "${flag}" in
|
||||
w) webhook_url=${OPTARG};; # Discord Webhook URL
|
||||
c) CPU="True";; # CPU
|
||||
r) RAM="True";; # RAM
|
||||
d) DISK_IO="True";; # DISK I/O
|
||||
n) NETWORK="True";; # Network
|
||||
f) datafile=${OPTARG};; # where your data belongs!
|
||||
esac
|
||||
done
|
||||
|
||||
MAKE_DIR=$(mktemp -d)
|
||||
DATETIME=$(date +"%Y-%m-%d")
|
||||
|
||||
function cpu {
|
||||
graph_gen "-u" "cpu"
|
||||
}
|
||||
|
||||
function ram {
|
||||
graph_gen "-r" "ram"
|
||||
}
|
||||
|
||||
function diskIO {
|
||||
graph_gen "-b" "diskio"
|
||||
}
|
||||
|
||||
function network {
|
||||
graph_gen "-n DEV" "network"
|
||||
}
|
||||
|
||||
function graph_gen {
|
||||
POSTSVG=$MAKE_DIR/sysstat_"$2"_data.svg
|
||||
POSTPNG=$MAKE_DIR/sysstat_"$2"_data.png
|
||||
|
||||
/usr/bin/sadf -g $EXPANSION -O oneday,skipempty -- $1 > $POSTSVG
|
||||
svg_to_png $POSTSVG $POSTPNG
|
||||
Process $POSTPNG
|
||||
}
|
||||
|
||||
function Process {
|
||||
POSTFILE=$1
|
||||
Discord_hooks
|
||||
}
|
||||
|
||||
function svg_to_png {
|
||||
/usr/bin/rsvg-convert $1 -o $2
|
||||
}
|
||||
function Discord_hooks {
|
||||
curl \
|
||||
-F 'payload_json={"content": "'$DATETIME'"}' \
|
||||
-F "file1=@$POSTFILE" \
|
||||
$webhook_url
|
||||
}
|
||||
|
||||
if [ ! -n "${webhook_url}" ]; then
|
||||
echo "Fatal : no webhook_url (-w) suppiled"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -f "$datafile" ]; then
|
||||
EXPANSION="-f $datafile"
|
||||
fi
|
||||
|
||||
if [ "$CPU" == "True" ]; then
|
||||
cpu
|
||||
fi
|
||||
|
||||
if [ "$RAM" == "True" ]; then
|
||||
ram
|
||||
fi
|
||||
|
||||
if [ "$DISK_IO" == "True" ]; then
|
||||
diskIO
|
||||
fi
|
||||
|
||||
if [ "$NETWORK" == "True" ]; then
|
||||
network
|
||||
fi
|
||||
|
||||
rm -rf $MAKE_DIR
|
Loading…
Reference in New Issue
Block a user