Skip to content

Commit

Permalink
fixed to send email in case of last_total_bytes is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
KJ Kim committed Apr 18, 2021
1 parent 8e85d8e commit 97381f4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def read(f):

setup(
name='django-traffic-monitor',
version=1.3,
version=1.6,
url='https://github.com/genonfire/django-traffic-monitor',
license='MIT',
description='a Django application that eases to monitor server traffic.',
Expand Down
8 changes: 7 additions & 1 deletion traffic_monitor/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ def skip_alarm(total_bytes):
return SKIP

last_total_bytes = conf.settings.get_last_total_bytes()
if last_total_bytes == 0:
return DO_NOT_SKIP

bytes_threshold = conf.settings.TRAFFIC_MONITOR_ALARM_BYTES_THRESHOLD

if total_bytes > last_total_bytes + bytes_threshold:
Expand Down Expand Up @@ -165,13 +168,16 @@ def read_bytes():
else:
previous_traffic = models.Traffic.objects.get_earlier()

instance, _ = models.Traffic.objects.get_or_create(
instance, created = models.Traffic.objects.get_or_create(
date=timezone.localtime(timezone.now()).date()
)
instance.interface = interfaces
instance.rx_read = rx_read
instance.tx_read = tx_read

if created:
conf.settings.set_last_total_bytes(0)

if (
previous_traffic.rx_read > rx_read or
previous_traffic.tx_read > tx_read
Expand Down

0 comments on commit 97381f4

Please sign in to comment.