Skip to content

Instantly share code, notes, and snippets.

@Lance1o7
Lance1o7 / guard.py
Last active November 21, 2024 04:48
Using vnstat to monitor the monthly traffic of a Linux server, if it exceeds the limit, send a notification to Discord.
from subprocess import run
import requests
INTERFACE = "enp0s6"
LIMIT = "500"
WEBHOOK_URL = ''
MESSAGE = 'Traffic Warning'
p = run(["vnstat", INTERFACE, "--alert", "0", "3", "m", "total", LIMIT, "GB"])
class BIT:
def __init__(self, n):
self.n = n
self.t = [0] * (n + 1)
def update(self, idx, val):
idx += 1
while idx <= self.n:
self.t[idx] += val
idx += idx & -idx
# certbot
# keep 80 accessable
sudo apt install certbot
sudo certbot certonly --standalone --preferred-challenges http -d DOMAIN_NAME
# gost config
log:
output: stderr # none, stderr, stdout, /path/to/file
level: info # debug, info, warn, error, fatal