Skip to content

Commit 3261cf3

Browse files
authored
Merge branch 'master' into patch-1
2 parents 4eedae7 + 77d0fef commit 3261cf3

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

docs/scenarios/admin.rst

+19-21
Original file line numberDiff line numberDiff line change
@@ -155,44 +155,42 @@ tests (net, CPU) fail, it will send an email.
155155
# Package for email services:
156156
import smtplib
157157
import string
158-
MAX_NET_USAGE = 400000
158+
MAX_NET_USAGE = 400000 # bytes per seconds
159159
MAX_ATTACKS = 4
160160
attack = 0
161-
counter = 0
162161
while attack <= MAX_ATTACKS:
163162
sleep(4)
164-
counter = counter + 1
165-
# Check the cpu usage
166-
if cpu_percent(interval = 1) > 70:
167-
attack = attack + 1
168-
# Check the net usage
169-
neti1 = net_io_counters()[1]
170-
neto1 = net_io_counters()[0]
163+
164+
# Check the net usage wit named tuples
165+
neti1 = net_io_counters().bytes_recv
166+
neto1 = net_io_counters().bytes_sent
171167
sleep(1)
172-
neti2 = net_io_counters()[1]
173-
neto2 = net_io_counters()[0]
168+
neti2 = net_io_counters().bytes_recv
169+
neto2 = net_io_counters().bytes_sent
170+
174171
# Calculate the bytes per second
175172
net = ((neti2+neto2) - (neti1+neto1))/2
176-
if net > MAX_NET_USAGE:
177-
attack = attack + 1
178-
if counter > 25:
179-
attack = 0
180-
counter = 0
173+
174+
# Check the net and cpu usage
175+
if (net > MAX_NET_USAGE) or (cpu_percent(interval = 1) > 70):
176+
attack+=1
177+
elif attack > 1:
178+
attack-=1
179+
181180
# Write a very important email if attack is higher than 4
182181
TO = "you@your_email.com"
183182
FROM = "webmaster@your_domain.com"
184183
SUBJECT = "Your domain is out of system resources!"
185184
text = "Go and fix your server!"
186-
BODY = string.join(("From: %s" %FROM,"To: %s" %TO,"Subject: %s" %SUBJECT, "",text), "\r\n")
185+
string="\r\n"
186+
BODY = string.join(("From: %s" %FROM,"To: %s" %TO,
187+
"Subject: %s" %SUBJECT, "",text))
187188
server = smtplib.SMTP('127.0.0.1')
188189
server.sendmail(FROM, [TO], BODY)
189190
server.quit()
190191
191192
192-
A full terminal application like a widely extended top which is based on
193-
psutil and with the ability of a client-server monitoring is
194-
`glance <https://github.com/nicolargo/glances/>`_.
195-
193+
A full terminal application like a widely extended top is `Glance <https://github.com/nicolargo/glances/>`_, which is based on psutil and has the ability for client-server monitoring.
196194

197195
*******
198196
Ansible

0 commit comments

Comments
 (0)