예제 #1
0
    def display_separately(self, save=True) -> None:
        os.system('cls' if os.name == 'nt' else 'clear')
        ch = HorizontalBarChart()
        ch.options.graph_color = 'white'

        while True:
            cpu = psutil.cpu_freq(percpu=True)

            for n, i in enumerate(cpu, start=1):
                percent = round((i.current - self._min) / (self._max - self._min) * 100, 2)
                ch.chart(
                    title=f'CPU #{n}',
                    pre_graph_text=f'Current: {round(i.current, 1)}hz || Min: {self._min}hz || Max: {self._max}hz',
                    post_graph_text=tools.create_usage_warning(percent, 30, 15),
                    footer=None,
                    maximum=self._max - self._min,
                    current=i.current - self._min
                )

                if save:
                    cpu = {
                        'user': [getpass.getuser()],
                        'cpu': [n],
                        'time': [time.time()],
                        'current': [i.current],
                        'usage': [percent]
                    }

                    tools.save_to_csv(cpu, '~/cpus.csv')

                print()

            time.sleep(0.8)
            os.system('cls' if os.name == 'nt' else 'clear')
        tools.save_to_csv(cpu, '~/cpu.csv')
예제 #2
0
    def print_disk_chart(self, ch: Chart, partname: str, part: dict) -> None:
        """Prints the disk data as a chart
        
        Args:
            ch (Chart): to print
            partname (str): partition title
            part (dict): partition data to be visualized
        """
        pre_graph_text = self.create_stats(part)

        footer = None
        if self.details:
            footer = self.create_details_text(part)

        maximum = part["total"]
        current = part["used"]
        post_graph_text = create_usage_warning(part['percent'], 80, 60)

        ch.chart(
            post_graph_text=post_graph_text,
            title=partname,
            pre_graph_text=pre_graph_text,
            footer=footer,
            maximum=maximum,
            current=current,
        )
        print()
예제 #3
0
    def test_create_usage_warning(self):
        # Test blinking red warning
        compare_red = f"{stylize('39.5% used', attr('blink') + fg(9))}"
        self.assertEqual(create_usage_warning(39.5, 39.4, 39), compare_red)

        # Test orange medium level warning
        compare_orange = f"{stylize('0.1% used', fg(214))}"
        self.assertEqual(create_usage_warning(0.1, 0.2, 0.1), compare_orange)

        # Test green low-level warning
        compare_green = f"{stylize('99.5% used', fg(82))}"
        self.assertEqual(create_usage_warning(99.5, 99.9, 99.6), compare_green)

        # Test negative number
        compare_negative = f"{stylize('0% used', fg(82))}"
        self.assertEqual(create_usage_warning(-15.5, 1.1, 1.0),
                         compare_negative)

        # Test over 100% usage
        compare_over100 = f"{stylize('100% used', attr('blink') + fg(9))}"
        self.assertEqual(create_usage_warning(101.1, 99.9, 99.8),
                         compare_over100)
예제 #4
0
    def display_combined(self) -> None:
        os.system('cls' if os.name == 'nt' else 'clear')
        ch = HorizontalBarChart()
        ch.options.graph_color = 'white'
        while True:
            cpu = psutil.cpu_freq(percpu=False)
            ch.chart(
                title='CPU (ALL)',
                pre_graph_text=f'Current: {round(cpu.current, 1)}hz || Min: {self._min}hz || Max: {self._max}hz',
                post_graph_text=tools.create_usage_warning(
                    round((cpu.current - self._min) / (self._max - self._min) * 100, 2),
                    30, 15),
                footer=None,
                maximum=self._max - self._min,
                current=cpu.current - self._min
            )
            print()

            time.sleep(0.8)
            os.system('cls' if os.name == 'nt' else 'clear')
예제 #5
0
파일: disks.py 프로젝트: hugoahosta/vizex
    def print_disk_chart(self, chart: Chart, partname: str,
                         part: dict) -> None:
        ch = chart
        title = (partname, )
        pre_graph_text = self.create_stats(part)
        if self.details:
            footer = self.create_details_text(part)
        else:
            footer = None

        maximum = part["total"]
        current = part["used"]
        post_graph_text = tools.create_usage_warning(part['percent'], 80, 60)

        ch.chart(
            post_graph_text=post_graph_text,
            title=title[0],
            pre_graph_text=pre_graph_text,
            footer=footer,
            maximum=maximum,
            current=current,
        )
        print()
예제 #6
0
def main():
    self = DiskUsage()
    parts = self.grab_partitions(exclude=[], every=False)

    for partname, part in parts.items():
        ch = HorizontalBarChart()
        title = (partname,)
        pre_graph_text = self.create_stats(part)
        footer = self.create_details_text(part)
        maximum = part["total"]
        current = part["used"]
        post_graph_text = create_usage_warning(
            part['percent'], 80, 60)

        ch.chart(
            post_graph_text=post_graph_text,
            title=title[0],
            pre_graph_text=pre_graph_text,
            footer=footer,
            maximum=maximum,
            current=current,
        )
        print()
예제 #7
0
        elif file_type == 'json':
            save_to_json(data, filename)
        else:
            raise NameError("Not supported file type, please indicate " +
                            ".CSV or .JSON at the end of the filename")


if __name__ == "__main__":
    self = DiskUsage()
    parts = self.grab_partitions(exclude=[], every=False)

    for partname in parts:
        part = parts[partname]
        ch = HorizontalBarChart()
        title = (partname, )
        pre_graph_text = self.create_stats(part)
        footer = self.create_details_text(part)
        maximum = part["total"]
        current = part["used"]
        post_graph_text = create_usage_warning(part['percent'], 80, 60)

        ch.chart(
            post_graph_text=post_graph_text,
            title=title[0],
            pre_graph_text=pre_graph_text,
            footer=footer,
            maximum=maximum,
            current=current,
        )
        print()