mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Bandwidth monitoring on the file hosting servers
This commit is contained in:
parent
e7a3db383b
commit
94741bab3b
56
setup/file-hosting-bw.py
Normal file
56
setup/file-hosting-bw.py
Normal file
@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=utf-8
|
||||
from __future__ import (unicode_literals, division, absolute_import,
|
||||
print_function)
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
import os, subprocess, socket
|
||||
|
||||
BASE = '/srv/download/bw'
|
||||
|
||||
def main():
|
||||
if not os.path.exists(BASE):
|
||||
os.makedirs(BASE)
|
||||
os.chdir(BASE)
|
||||
|
||||
for name in 'hours days months top10 summary'.split():
|
||||
subprocess.check_call(['vnstati', '--' + name, '-o', name + '.png'])
|
||||
|
||||
html = '''\
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head><title>Bandwidth usage for {host}</title></head>
|
||||
<body>
|
||||
<style> .float {{ float: left; margin-right:30px; margin-left:30px; text-align:center; width: 500px; }}</style>
|
||||
<h1>Bandwidth usage for {host}</h1>
|
||||
<div class="float">
|
||||
<h2>Summary</h2>
|
||||
<img src="summary.png"/>
|
||||
</div>
|
||||
<div class="float">
|
||||
<h2>Hours</h2>
|
||||
<img src="hours.png"/>
|
||||
</div>
|
||||
<div class="float">
|
||||
<h2>Days</h2>
|
||||
<img src="days.png"/>
|
||||
</div>
|
||||
<div class="float">
|
||||
<h2>Months</h2>
|
||||
<img src="months.png"/>
|
||||
</div>
|
||||
<div class="float">
|
||||
<h2>Top10</h2>
|
||||
<img src="top10.png"/>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
'''.format(host=socket.gethostname())
|
||||
|
||||
with open('index.html', 'wb') as f:
|
||||
f.write(html.encode('utf-8'))
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -9,14 +9,19 @@ service ssh restart
|
||||
hostname whatever
|
||||
Edit /etc/hosts and put in FQDN in the appropriate places, for example::
|
||||
127.0.0.1 download.calibre-ebook.com download
|
||||
46.28.49.116 download.calibre-ebook.com download
|
||||
46.28.49.116 download.calibre-ebook.com download
|
||||
|
||||
echo "Asia/Kolkata" > /etc/timezone && dpkg-reconfigure -f noninteractive tzdata && ntpdate ntp.ubuntu.com
|
||||
apt-get update
|
||||
apt-get install vim nginx zsh python-lxml python-mechanize iotop htop smartmontools mosh git ntp
|
||||
apt-get install vim nginx zsh python-lxml python-mechanize iotop htop smartmontools mosh git ntp vnstat vnstati
|
||||
chsh -s /bin/zsh
|
||||
mkdir -p /root/staging /root/work/vim /srv/download /srv/manual
|
||||
|
||||
Edit /etc/vnstat.conf and change the default interface to whatever the interface for
|
||||
the server is and change the max bandwidth to 1024
|
||||
|
||||
service vnstat restart
|
||||
|
||||
export server=whatever
|
||||
scp ~/.zshrc ~/.vimrc $server:
|
||||
scp -r ~/work/vim/zsh-syntax-highlighting $server:work/vim
|
||||
@ -28,6 +33,7 @@ echo '#!/bin/sh\ncd /usr/local/calibre && git pull -q' > /usr/local/bin/update-c
|
||||
Add the following to crontab::
|
||||
@hourly /usr/bin/python /usr/local/calibre/setup/plugins_mirror.py
|
||||
@hourly /usr/local/bin/update-calibre
|
||||
@hourly /usr/bin/python /usr/local/calibre/setup/file-hosting-bw.py
|
||||
|
||||
If the server has a backup hard-disk, mount it at /mnt/backup and edit /etc/fstab so that it is auto-mounted.
|
||||
Then, add the following to crontab::
|
||||
@ -43,6 +49,7 @@ ssh $server cat /etc/nginx/mime.types > /etc/nginx/mime.types
|
||||
rsync -avz $server:/srv/ /srv/
|
||||
service nginx start
|
||||
|
||||
|
||||
Services
|
||||
---------
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user