Exemplo n.º 1
0
    def poll(self):
        """
        Measure current stats value and return new stats.
        """
        hdata = Monitor.poll(self)

        start = perf_counter_ns()

        devices = {}
        usage = {}
        counters = psutil.disk_io_counters(True)
        for dev in psutil.disk_partitions():
            if dev.device.startswith('/dev/loop'):
                continue
            key = dev.device.split('/')[-1]
            if key not in devices:
                if key in counters:
                    devices[key] = dict(dev._asdict(),
                                        **counters[key]._asdict())
                else:
                    devices[key] = dev._asdict()
                usage[key] = psutil.disk_usage(dev.mountpoint)._asdict()

        hdata['devices'] = devices
        hdata['usage'] = usage

        hdata[u'elapsed'] = perf_counter_ns() - start

        self._last_value = hdata

        return hdata
Exemplo n.º 2
0
    def _batch_loop(self):

        period = {
            u'finished_ts': time_ns(),
            u'finished_pc': perf_counter_ns(),
            u'period': self._period,
            u'period_start': util.utcstr(self._period_ts),
        }

        current_batch = self._current_batch

        if current_batch:
            period[u'first_seq'] = current_batch[0].seq
            period[u'last_seq'] = current_batch[-1].seq
        else:
            period[u'first_seq'] = None
            period[u'last_seq'] = None

        # fire user callback with current batch
        if self._on_trace_period_finished:
            self._on_trace_period_finished(self._trace_id, period, current_batch)

        # append current batch to history
        self._trace.append((period, current_batch))

        # next period
        self._period += 1
        self._period_ts = datetime.utcnow()
        if current_batch:
            self._current_batch = []
Exemplo n.º 3
0
    def poll(self):
        hdata = Monitor.poll(self)

        start = perf_counter_ns()

        hdata['cpu'] = psutil.cpu_times_percent()._asdict()
        hdata['memory'] = psutil.virtual_memory()._asdict()
        hdata['loadavg'] = os.getloadavg()

        # uptime, as all durations, is in ns
        hdata['uptime'] = int(hdata['timestamp'] - psutil.boot_time() * 10**10)

        hdata[u'elapsed'] = perf_counter_ns() - start

        self._last_value = hdata

        return hdata
Exemplo n.º 4
0
 def __init__(self, seq, realm, direction, session_id, authid, authrole, msg):
     self.ts = time_ns()
     self.pc = perf_counter_ns()
     self.seq = seq
     self.realm = realm
     self.direction = direction
     self.session_id = session_id
     self.authid = authid
     self.authrole = authrole
     self.msg = msg
Exemplo n.º 5
0
 def __init__(self, correlation_id, correlation_uri, seq, realm, action, originator, responders):
     self.correlation_id = correlation_id
     self.correlation_uri = correlation_uri
     self.ts = time_ns()
     self.pc = perf_counter_ns()
     self.seq = seq
     self.realm = realm
     self.action = action
     self.originator = originator
     self.responders = responders
     self.success = None
Exemplo n.º 6
0
    def poll(self, sensors=[]):
        """
        Measure current stats value and return new stats.
        """
        hdata = Monitor.poll(self)

        start = perf_counter_ns()

        hdata['io_counters'] = self._process.io_counters()._asdict()
        hdata['cpu_times'] = self._process.cpu_times()._asdict()
        a = round(((self._process.cpu_times().user + self._process.cpu_times().system) * 100) /
                  (time.time() - self._process.create_time()), 3)
        hdata['percent'] = a

        for sensor in sensors:
            hdata[sensor.ID] = sensor._elapsed

        hdata[u'elapsed'] = perf_counter_ns() - start

        self._last_value = hdata

        return hdata
Exemplo n.º 7
0
    def poll(self):
        """
        Measure current stats value and return new stats.
        """
        hdata = Monitor.poll(self)

        start = perf_counter_ns()

        counters = {}
        io_counters = psutil.net_io_counters(True)
        for dev in io_counters:
            if dev.startswith('virbr') or dev.startswith(
                    'lo') or dev.startswith('docker'):
                continue
            counters[dev] = io_counters[dev]._asdict()

        hdata['net_io_counters'] = counters
        hdata['net_if_addrs'] = psutil.net_if_addrs()

        hdata[u'elapsed'] = perf_counter_ns() - start

        self._last_value = hdata

        return hdata
Exemplo n.º 8
0
    def poll(self):
        """
        Measure current stats value and return new stats.
        """
        hdata = Monitor.poll(self)

        start = perf_counter_ns()

        battery = None
        bat = psutil.sensors_battery()
        if bat:
            battery = bat._asdict()

        fans = []
        for key, val in (psutil.sensors_fans() or {}).items():
            for item in val:
                item = item._asdict()
                item['device'] = key
                fans.append(item)

        temperatures = []
        for key, val in (psutil.sensors_temperatures() or {}).items():
            for item in val:
                item = item._asdict()
                item['device'] = key
                temperatures.append(item)

        hdata['battery'] = battery
        hdata['fans'] = fans
        hdata['temperatures'] = temperatures

        hdata[u'elapsed'] = perf_counter_ns() - start

        self._last_value = hdata

        return hdata
Exemplo n.º 9
0
def test_perf_counter_ns(framework):
    now = txaio.perf_counter_ns()
    assert now > 0