mirror of
https://github.com/tgbot-collection/ytdlbot.git
synced 2025-02-23 06:44:18 +08:00
add vnstat
This commit is contained in:
parent
46856ba374
commit
f2aabf6a1d
2 changed files with 19 additions and 5 deletions
10
Dockerfile
10
Dockerfile
|
@ -6,12 +6,14 @@ RUN pip3 install --user -r /tmp/requirements.txt && rm /tmp/requirements.txt
|
|||
|
||||
|
||||
FROM python:alpine
|
||||
RUN apk update && apk add --no-cache ffmpeg
|
||||
WORKDIR /ytdlbot
|
||||
ENV TZ=Asia/Shanghai
|
||||
|
||||
RUN apk update && apk add --no-cache ffmpeg vnstat
|
||||
COPY --from=builder /root/.local /usr/local
|
||||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
|
||||
COPY . /ytdlbot
|
||||
RUN echo "/usr/sbin/vnstatd -d;/usr/local/bin/python ytdl.py"> /ytdlbot/start.sh
|
||||
|
||||
WORKDIR /ytdlbot
|
||||
ENV TZ=Asia/Shanghai
|
||||
CMD ["python", "ytdl.py"]
|
||||
CMD ["sh", "start.sh"]
|
14
limit.py
14
limit.py
|
@ -13,6 +13,7 @@ import math
|
|||
import os
|
||||
import re
|
||||
import sqlite3
|
||||
import subprocess
|
||||
import tempfile
|
||||
import time
|
||||
from io import BytesIO
|
||||
|
@ -39,6 +40,7 @@ class Redis:
|
|||
quota_banner = "=" * 20 + "Quota" + "=" * 20
|
||||
metrics_banner = "=" * 20 + "Metrics" + "=" * 20
|
||||
usage_banner = "=" * 20 + "Usage" + "=" * 20
|
||||
vnstat_banner = "=" * 20 + "vnstat" + "=" * 20
|
||||
self.final_text = f"""
|
||||
{db_banner}
|
||||
%s
|
||||
|
@ -53,6 +55,10 @@ class Redis:
|
|||
|
||||
|
||||
{usage_banner}
|
||||
%s
|
||||
|
||||
|
||||
{vnstat_banner}
|
||||
%s
|
||||
"""
|
||||
|
||||
|
@ -108,7 +114,13 @@ class Redis:
|
|||
fd.sort(key=lambda x: int(x[1]))
|
||||
quota_text = self.generate_table(["UserID", "bytes", "human readable", "refresh time"], fd)
|
||||
|
||||
return self.final_text % (db_text, quota_text, metrics_text, usage_text)
|
||||
# vnstat
|
||||
if os.uname().sysname == "Darwin":
|
||||
cmd = "/usr/local/bin/vnstat -i en0".split()
|
||||
else:
|
||||
cmd = "/usr/bin/vnstat -i eth0".split()
|
||||
vnstat_text = subprocess.check_output(cmd).decode('u8')
|
||||
return self.final_text % (db_text, quota_text, metrics_text, usage_text, vnstat_text)
|
||||
|
||||
def reset_today(self):
|
||||
pairs = self.r.hgetall("metrics")
|
||||
|
|
Loading…
Reference in a new issue