当前位置: 首页>>代码示例>>Python>>正文


Python Monitor.poll方法代码示例

本文整理汇总了Python中monitor.Monitor.poll方法的典型用法代码示例。如果您正苦于以下问题:Python Monitor.poll方法的具体用法?Python Monitor.poll怎么用?Python Monitor.poll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在monitor.Monitor的用法示例。


在下文中一共展示了Monitor.poll方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: poll

# 需要导入模块: from monitor import Monitor [as 别名]
# 或者: from monitor.Monitor import poll [as 别名]
    def poll(self):
        """
        Measure current stats value and return new stats.
        """
        Monitor.poll(self)

        # create new, empty event
        #
        current = {
            # the UTC timestamp when measurement was taken
            u'timestamp': utcnow(),

            # the effective last period in secods
            u'last_period': self._last_period,
        }

        # FIXME: add ratio of ram usage

        with open("/proc/meminfo") as f:
            res = f.read()
            new = res.split()
            new_clean = [x.replace(":", "") for x in new if x != 'kB']
            for i in range(0, len(new_clean), 2):
                k = u'{}'.format(new_clean[i])
                current[k] = int( new_clean[i + 1])

        self._last_value = current

        return succeed(self._last_value)
开发者ID:oberstet,项目名称:scratchbox,代码行数:31,代码来源:rammonitor.py

示例2: poll

# 需要导入模块: from monitor import Monitor [as 别名]
# 或者: from monitor.Monitor import poll [as 别名]
    def poll(self):
        """
        Measure current stats value and return new stats.
        """
        Monitor.poll(self)

        # create new, empty event
        #
        current = {
            # the UTC timestamp when measurement was taken
            u'timestamp': utcnow(),

            # the effective last period in secods
            u'last_period': self._last_period,

            # duration in seconds the retrieval of sensor values took
            u'command_duration': None,

            # actual sensor readings
            u'sensors': []
        }

        # read out IPMI sensor data via ipmitool (which needs root!)
        #
        cmd_started = time.time()
        res = yield getProcessOutput('/usr/bin/ipmitool', ['sdr'])
        current[u'command_duration'] = time.time() - cmd_started

        # extract sensor reading
        #
        for line in res.splitlines():
            sensor, value, status = tuple([x.strip() for x in line.split('|')])
            if sensor in self._sensors:
                value, unit = value.split(' ', 1)
                value = float(value)
                unit = unit.strip()
                current[u'sensors'].append({
                    u'id': sensor,
                    u'value': value,
                    u'unit': unit,
                    u'status': status
                })

        self._last_value = current

        returnValue(self._last_value)
开发者ID:oberstet,项目名称:scratchbox,代码行数:48,代码来源:hwmonitor.py

示例3: poll

# 需要导入模块: from monitor import Monitor [as 别名]
# 或者: from monitor.Monitor import poll [as 别名]
    def poll(self):
        """
        Measure current stats value and return new stats.
        """
        Monitor.poll(self)

        # create new, empty event
        #
        current = {
            # the UTC timestamp when measurement was taken
            u'timestamp': utcnow(),

            # the effective last period in secods
            u'last_period': self._last_period,

            # readings per CPU socket
            u'sockets': []
        }

        # fill in per-socket/per-core structures
        #
        for i in range(len(self._sockets)):
            socket = {
                # sequentially numbered socket ID
                u'id': i,

                # physical socket ID
                u'physical_id': self._sockets[i][0],

                # CPU socket temperature
                u'temperature': None,

                # CPU cores on this socket
                u'cores': []
            }
            for j in range(len(self._sockets[i][1])):
                core = {
                    # sequentially numbered core ID
                    u'id': j,

                    # physical core ID on this socket
                    u'physical_id': self._sockets[i][1][j],

                    # CPU core load
                    u'user': None,
                    u'system': None,
                    u'nice': None,
                    u'idle': None,
                    u'iowait': None,
                    u'irq': None,
                    u'softirq': None,
                    u'steal': None,
                    u'total': None,

                    # CPU core frequency
                    u'frequency': None,

                    # CPU core temperature
                    u'temperature': None
                }
                socket[u'cores'].append(core)
            current[u'sockets'].append(socket)

        # get current CPU load (via psutil)
        #
        cpu_now = psutil.cpu_times(percpu=True)

        if not self._cpu_last:
            self._cpu_last = cpu_now
        else:
            for i in range(len(cpu_now)):

                socket_id, core_id = self._physid_to_id[self._processors[i]]

                core = current[u'sockets'][socket_id][u'cores'][core_id]

                digits = 8

                # CPU core load stats
                core[u'user'] = round(cpu_now[i].user - self._cpu_last[i].user, digits)
                core[u'system'] = round(cpu_now[i].system - self._cpu_last[i].system, digits)
                core[u'nice'] = round(cpu_now[i].nice - self._cpu_last[i].nice, digits)
                core[u'idle'] = round(cpu_now[i].idle - self._cpu_last[i].idle, digits)
                core[u'iowait'] = round(cpu_now[i].iowait - self._cpu_last[i].iowait, digits)
                core[u'irq'] = round(cpu_now[i].irq - self._cpu_last[i].irq, digits)
                core[u'softirq'] = round(cpu_now[i].softirq - self._cpu_last[i].softirq, digits)
                core[u'steal'] = round(cpu_now[i].steal - self._cpu_last[i].steal, digits)

                # total CPU core load (= user + nice + system)
                core[u'total'] = round(
                    (cpu_now[i].user + cpu_now[i].nice + cpu_now[i].system) -
                    (self._cpu_last[i].user + self._cpu_last[i].nice + self._cpu_last[i].system)
                , digits)

                # normalize with effective period
                diff = self._last_period or 1.
                for k in core:
                    if (k != 'id' and k != 'physical_id' and k != 'frequency' and k != 'temperature'):
                        core[k] = round(core[k] / diff, digits)

#.........这里部分代码省略.........
开发者ID:oberstet,项目名称:scratchbox,代码行数:103,代码来源:cpumonitor.py


注:本文中的monitor.Monitor.poll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。