示例#1
0
文件: network.py 项目: fberg/pysysmon
    def execute(self):
        interfaces = self.get_interface_list()

        try:
            current_data = time.time(), self.get_transferred_data(interfaces)
        except NetworkInterfaceDoesntExistError as e:
            print("Interface " + e.iface + " disappeared...")
            del interfaces[e.iface]

        if len(interfaces) == 0:
            return None

        info = {
            'DataDownloaded': current_data[1][0],
            'DataUploaded': current_data[1][1],
            'DownloadRate': (current_data[1][0] - self.previous_data[1][0]) / \
                                (current_data[0] - self.previous_data[0]),
            'UploadRate': (current_data[1][1] - self.previous_data[1][1]) / \
                                (current_data[0] - self.previous_data[0])
        }

        #rate = (current_data[1] - self.previous_data[1]) / \
        #(current_data[0] - self.previous_data[0])

        self.previous_data = current_data

        for key, value in info.items():
            info[key] = Util.format_output(value, self._format,
                                           self._show_units, self._short_units)

        return self._layout % info
示例#2
0
    def execute(self):
        mount_file = open('/proc/mounts')

        for line in mount_file:
            if line.split()[1] == self._mount_point:
                break
        else:
            return None

        info = get_mount_point_statistics(self._mount_point)

        for key, value in info.items():
            if key != 'UsePercent':
                info[key] = Util.format_output(value, self._format,
                                               self._show_units,
                                               self._short_units)

        if self._show_units:
            info['UsePercent'] = str(info['UsePercent']) + '%'

        return self._layout % info