Merge lp:~therve/landscape-client/limit-network-data into lp:~landscape/landscape-client/trunk

Proposed by Thomas Herve
Status: Merged
Approved by: Free Ekanayaka
Approved revision: 325
Merged at revision: 323
Proposed branch: lp:~therve/landscape-client/limit-network-data
Merge into: lp:~landscape/landscape-client/trunk
Diff against target: 100 lines (+49/-10)
2 files modified
landscape/monitor/networkactivity.py (+13/-2)
landscape/monitor/tests/test_networkactivity.py (+36/-8)
To merge this branch: bzr merge lp:~therve/landscape-client/limit-network-data
Reviewer Review Type Date Requested Status
Free Ekanayaka (community) Approve
Kevin McDermott (community) Approve
Review via email: mp+57642@code.launchpad.net

Description of the change

The way to count the number of items is a bit tricky. It will also won't push the older first, but I think it's fine.

To post a comment you must log in.
Revision history for this message
Kevin McDermott (bigkevmcd) wrote :

+ max_free_space_items_to_exchange = 200

Am not sure this is the right name for a limit on network data :-)

Other than that, +1

review: Approve
Revision history for this message
Kevin McDermott (bigkevmcd) wrote :

It might be nice to make this generic... :-)

325. By Thomas Herve

Rename class variable

Revision history for this message
Free Ekanayaka (free.ekanayaka) wrote :

Cool, +1!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'landscape/monitor/networkactivity.py'
--- landscape/monitor/networkactivity.py 2010-09-20 20:53:24 +0000
+++ landscape/monitor/networkactivity.py 2011-04-14 10:32:33 +0000
@@ -21,6 +21,8 @@
21 run_interval = 3021 run_interval = 30
22 _rollover_maxint = 022 _rollover_maxint = 0
2323
24 max_network_items_to_exchange = 200
25
24 def __init__(self, network_activity_file="/proc/net/dev",26 def __init__(self, network_activity_file="/proc/net/dev",
25 create_time=time.time):27 create_time=time.time):
26 self._source_file = network_activity_file28 self._source_file = network_activity_file
@@ -39,10 +41,19 @@
39 self.call_on_accepted("network-activity", self.exchange, True)41 self.call_on_accepted("network-activity", self.exchange, True)
4042
41 def create_message(self):43 def create_message(self):
42 network_activity = self._network_activity44 network_activity = {}
45 items = 0
46 for interface, data in list(self._network_activity.items()):
47 if data:
48 network_activity[interface] = []
49 while data and items < self.max_network_items_to_exchange:
50 item = data.pop(0)
51 network_activity[interface].append(item)
52 items += 1
53 if items >= self.max_network_items_to_exchange:
54 break
43 if not network_activity:55 if not network_activity:
44 return56 return
45 self._network_activity = {}
46 return {"type": "network-activity", "activities": network_activity}57 return {"type": "network-activity", "activities": network_activity}
4758
48 def send_message(self, urgent):59 def send_message(self, urgent):
4960
=== modified file 'landscape/monitor/tests/test_networkactivity.py'
--- landscape/monitor/tests/test_networkactivity.py 2010-09-17 13:41:22 +0000
+++ landscape/monitor/tests/test_networkactivity.py 2011-04-14 10:32:33 +0000
@@ -10,8 +10,8 @@
10 stats_template = """\10 stats_template = """\
11Inter-| Receive | Transmit11Inter-| Receive | Transmit
12 face |bytes packets compressed multicast|bytes packets errs drop fifo12 face |bytes packets compressed multicast|bytes packets errs drop fifo
13 lo:%(lo_in)d %(lo_in_p)d 0 0 %(lo_out)d %(lo_out_p)d 0 0 013 lo:%(lo_in)d %(lo_in_p)d 0 0 %(lo_out)d %(lo_out_p)d 0 0 0
14 eth0: %(eth0_in)d 12539 0 62 %(eth0_out)d 12579 0 0 014 eth0: %(eth0_in)d 12539 0 62 %(eth0_out)d 12579 0 0 0
15 %(extra)s15 %(extra)s
16"""16"""
1717
@@ -31,12 +31,12 @@
31 def write_activity(self, lo_in=0, lo_out=0, eth0_in=0, eth0_out=0,31 def write_activity(self, lo_in=0, lo_out=0, eth0_in=0, eth0_out=0,
32 extra="", lo_in_p=0, lo_out_p=0, **kw):32 extra="", lo_in_p=0, lo_out_p=0, **kw):
33 kw.update(dict(33 kw.update(dict(
34 lo_in = lo_in,34 lo_in=lo_in,
35 lo_out = lo_out,35 lo_out=lo_out,
36 lo_in_p = lo_in_p,36 lo_in_p=lo_in_p,
37 lo_out_p = lo_out_p,37 lo_out_p=lo_out_p,
38 eth0_in = eth0_in,38 eth0_in=eth0_in,
39 eth0_out = eth0_out,39 eth0_out=eth0_out,
40 extra=extra))40 extra=extra))
41 self.activity_file.seek(0, 0)41 self.activity_file.seek(0, 0)
42 self.activity_file.truncate()42 self.activity_file.truncate()
@@ -188,3 +188,31 @@
188 def test_config(self):188 def test_config(self):
189 """The network activity plugin is enabled by default."""189 """The network activity plugin is enabled by default."""
190 self.assertIn("NetworkActivity", self.config.plugin_factories)190 self.assertIn("NetworkActivity", self.config.plugin_factories)
191
192 def test_limit_amount_of_items(self):
193 """
194 The network plugin doesn't send too many items at once in a single
195 network message, to not crush the server.
196 """
197 def extra(data):
198 result = ""
199 for i in range(50):
200 result += (
201"""eth%d: %d 12539 0 62 %d 12579 0 0 0\n """
202 % (i, data, data))
203 return result
204 for i in range(1, 10):
205 data = i * 1000
206 self.write_activity(lo_out=data, eth0_out=data, extra=extra(data))
207 self.plugin.run()
208 self.reactor.advance(self.monitor.step_size)
209 # We have created 408 items. It should be sent in 3 messages.
210 message = self.plugin.create_message()
211 items = sum(len(i) for i in message["activities"].values())
212 self.assertEqual(200, items)
213 message = self.plugin.create_message()
214 items = sum(len(i) for i in message["activities"].values())
215 self.assertEqual(200, items)
216 message = self.plugin.create_message()
217 items = sum(len(i) for i in message["activities"].values())
218 self.assertEqual(8, items)

Subscribers

People subscribed via source and target branches

to all changes: