17
使用vnStat监控Linux流量并发送每日总结到Telegram
source link: https://blog.landon.li/2019/12/30/%E4%BD%BF%E7%94%A8vnstat%E7%9B%91%E6%8E%A7linux%E6%B5%81%E9%87%8F%E5%B9%B6%E5%8F%91%E9%80%81%E6%AF%8F%E6%97%A5%E6%80%BB%E7%BB%93%E5%88%B0telegram/?amp%3Butm_medium=rss&%3Butm_campaign=%25e4%25bd%25bf%25e7%2594%25a8vnstat%25e7%259b%2591%25e6%258e%25a7linux%25e6%25b5%2581%25e9%2587%258f%25e5%25b9%25b6%25e5%258f%2591%25e9%2580%2581%25e6%25af%258f%25e6%2597%25a5%25e6%2580%25bb%25e7%25bb%2593%25e5%2588%25b0telegram
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
本文最后更新于 793 天前,其中的信息可能已经有所发展或是发生改变。
vnStat 是一款适用于 Linux 和 BSD 操作系统的基于命令行的网络流量监控程序。
本文将使用 vnStat 监控 Linux 流量,使用 vnStati 将 vnStat 的统计结果生成为图片,并调用 Telegram Bot API 将图片发送到 Telegram 对话。
安装 vnStat 和 vnStati
apt install vnstat vnstati
(可选)修改默认网络接口
将 /etc/vnstat.conf
中的 eth0
修改为需要监控的网络接口
Interface "eth0"
title="*`hostname` - Today's VnStat Summary*"vnstati -s -o <path to summary.png> curl -X POST \ -H "Content-Type: application/json" \ -d "{\"chat_id\": \"<Your chat id>\", \"text\": \"${title}\", \"parse_mode\": \"Markdown\"}" \ https://api.telegram.org/bot<Your bot token>/sendMessage curl -F "chat_id=<Your chat id>" \ -F "caption=\"Today's VnStat Summary\"" \ -F "photo=@/<path to summary.png>" \ https://api.telegram.org/bot<Your bot token>/sendPhoto
赋予执行权限
chmod +x /path/to/vnstat2telegram.sh
(可选)添加 Crontab 任务
crontab -e# 添加一行0 0 * * * /bin/bash /path/to/vnstat2telegram.sh
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK