Coder Social home page Coder Social logo

django-traffic-monitor's Introduction

django-traffic-monitor

PyPi Downloads

django-traffic-monitor is a Django application that eases to monitor server traffic.

Quick start

  1. install with pip:

    pip install django-traffic-monitor django-crontab
    
  2. Add "traffic_monitor" and "django-crontab" to your INSTALLED_APPS setting like this:

    INSTALLED_APPS = [
        ...
        'django_crontab',
        'traffic_monitor',
    ]
    
  3. Include the traffic_monitor URLconf in your project urls.py like this:

    urlpatterns += [
        path('traffic/', include('traffic_monitor.urls', namespace='traffic_monitor'))
    ]
    
  1. If you are more of url person than path:

    urlpatterns += [
        url(r'^traffic/', include('traffic_monitor.urls'), namespace='traffic_monitor')),
    ]
    
  2. Run migrate to create the traffic_monitor models.:

    python manage.py migrate
    
  3. Find out your server's network interface names using Linux command like ifconfig then set the name or names you wish to monitor in your project setting such as settings.py.:

    TRAFFIC_MONITOR_INTERFACE_NAMES = 'docker0,p2p1,eth0'
    
  4. Email setting required for Django. If sending email in your project is currently working, no need to change it or add it to your settings.:

    EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
    EMAIL_HOST = 'smtp.gmail.com',
    EMAIL_PORT = 587
    EMAIL_USE_TLS = True
    EMAIL_HOST_USER = '[email protected]',
    EMAIL_HOST_PASSWORD = 'your_password,
    DEFAULT_FROM_EMAIL = '[email protected]'
    
  5. (Optional) Set more configurations if you want to change from default.:

    # Permission to use: superuser, staff, member, all
    TRAFFIC_MONITOR_PERMISSION = 'staff'
    
    # Template for traffic monitoring page
    TRAFFIC_MONITOR_TEMPLATE = 'traffic_monitor/show_traffic.html'
    
    # Alarm will be sent if daily traffic exceeds
    TRAFFIC_MONITOR_DAILY_ALARM_BYTES = 100 * 1024 * 1024 * 1024
    
    # Alarm will be sent if monthly traffic exceeds
    TRAFFIC_MONITOR_MONTHLY_ALARM_BYTES = 800 * 1024 * 1024 * 1024
    
    # Alarm From Email
    TRAFFIC_MONITOR_EMAIL_FROM = DEFAULT_FROM_EMAIL
    
    # Alarm Email To (comma seperated list, can be more than one)
    TRAFFIC_MONITOR_EMAIL_TO = [DEFAULT_FROM_EMAIL]
    
    # Set False if you do not want to get email
    TRAFFIC_MONITOR_ALARM_SEND_EMAIL = True
    
    # Subject of email
    TRAFFIC_MONITOR_ALARM_EMAIL_SUBJECT = 'Traffic limit alert'
    
    # If traffic limit exceeds, the next alarm will be sent only if the traffic exceeds threshold from previous alarm
    TRAFFIC_MONITOR_ALARM_BYTES_THRESHOLD = 10 * 1024 * 1024 * 1024
    
  6. Add cronjob in your settings.py to collect traffic automatically. (i.e. run every 5 minutes):

    CRONJOBS = [
        ('*/5 * * * *', 'traffic_monitor.tools.read_bytes', '>> /var/log/cronjob.log'),
    ]
    
  7. Run following command to add CRONJOBS to your system crontab:

    python manage.py crontab add
    
  8. Connect <server address>/traffic/ to check current traffic.

docs/show_traffic.png

  1. If traffic limit exceeds, email will be sent.

docs/alarm_email.png

  1. If error especially UNKNOWN APP NAME happens while installing with pip, please upgrade your setuptools.:

    pip install setuptools --upgrade

django-traffic-monitor's People

Contributors

genonfire avatar

Stargazers

 avatar Nikolaus Schlemm avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.