Last active
April 3, 2021 15:49
-
-
Save dtsmith2001/728fa28bbd8882e8f1c570a6a3ae90a2 to your computer and use it in GitHub Desktop.
Monitor the Bandwidth Used by your Digital Ocean droplet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# monitor-bandwidth.service | |
# | |
[Unit] | |
Description=Ocean Network Allocation Monitor | |
After=network.target | |
Requires=network.target | |
[Service] | |
Type=simple | |
ExecStart=/usr/local/bin/monitor.sh | |
ExecStop=/usr/bin/pkill -TERM monitor.sh | |
User=<your_username> | |
Group=<your_username> | |
UMask=002 | |
StandardOutput=syslog | |
StandardError=inherit | |
SyslogFacility=local0 | |
Restart=always | |
RestartSec=30 | |
[Install] | |
WantedBy=multi-user.target |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Copyright 2021 Vallum Software, LLC. MIT license. | |
# | |
# | |
# Send an alert when network traffic allocation exceeds 900 GiB | |
# | |
webhook_url='' | |
while [ true ] | |
do | |
traffic=$(vnstat --oneline | awk -F ";" '{print $11}') | |
if [[ "${traffic}" == "GiB" ]] | |
then | |
if [ $(echo "$(echo "${traffic}" | sed 's/ GiB//g') > 900" | bc) -eq 1 ] | |
then | |
curl -X POST -H 'Content-type: application/json' --data "{\"text\":\"Traffic level ${traffic}\"}" ${webhook_url} | |
fi | |
fi | |
sleep 600 | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment