~ahasenack/landscape-client/landscape-client-11.07.1.1-0ubuntu0.11.10.0

« back to all changes in this revision

Viewing changes to landscape/monitor/networkactivity.py

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Hasenack
  • Date: 2010-09-08 15:34:09 UTC
  • mto: This revision was merged to the branch mainline in revision 32.
  • Revision ID: james.westby@ubuntu.com-20100908153409-cuhirosnil6hk1f9
Tags: upstream-1.5.5
ImportĀ upstreamĀ versionĀ 1.5.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
import time
7
7
 
8
 
from landscape.lib.network import get_network_traffic
 
8
from landscape.lib.network import get_network_traffic, is_64
9
9
from landscape.accumulate import Accumulator
10
10
 
11
11
from landscape.monitor.plugin import MonitorPlugin
28
28
        # our last traffic sample for calculating a traffic delta
29
29
        self._last_activity = {}
30
30
        self._create_time = create_time
 
31
        self._rollover_maxint = pow(2, 64) if is_64() else pow(2, 32)
31
32
 
32
33
    def register(self, registry):
33
34
        super(NetworkActivity, self).register(registry)
66
67
                delta_in = traffic["recv_bytes"] - previous_in
67
68
                if not delta_out and not delta_in:
68
69
                    continue
 
70
                if delta_out < 0:
 
71
                    delta_out += self._rollover_maxint
 
72
                if delta_in < 0:
 
73
                    delta_in += self._rollover_maxint
 
74
 
69
75
                yield interface, delta_out, delta_in
70
76
            self._last_activity[interface] = (
71
77
                traffic["send_bytes"], traffic["recv_bytes"])
79
85
        new_traffic = get_network_traffic(self._source_file)
80
86
        for interface, delta_out, delta_in in self._traffic_delta(new_traffic):
81
87
            out_step_data = self._accumulate(
82
 
                new_timestamp, delta_out, "delta-out-%s"%interface)
 
88
                new_timestamp, delta_out, "delta-out-%s" % interface)
83
89
 
84
90
            in_step_data = self._accumulate(
85
 
                new_timestamp, delta_in, "delta-in-%s"%interface)
 
91
                new_timestamp, delta_in, "delta-in-%s" % interface)
86
92
 
87
93
            # there's only data when we cross a step boundary
88
94
            if not (in_step_data and out_step_data):