From 35b7bccdc0100d924d08c864a20a2d374b0984d0 Mon Sep 17 00:00:00 2001 From: Akashdeep Dhar Date: Jun 25 2022 16:03:00 +0000 Subject: Remove older metrics and statistics readers Signed-off-by: Akashdeep Dhar --- diff --git a/obserware/sources/readers/mainwind/__init__.py b/obserware/sources/readers/mainwind/__init__.py deleted file mode 100644 index 0c5eff8..0000000 --- a/obserware/sources/readers/mainwind/__init__.py +++ /dev/null @@ -1,17 +0,0 @@ -""" -Obserware -Copyright (C) 2021-2022 Akashdeep Dhar - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -""" diff --git a/obserware/sources/readers/mainwind/tab_information.py b/obserware/sources/readers/mainwind/tab_information.py deleted file mode 100644 index fede778..0000000 --- a/obserware/sources/readers/mainwind/tab_information.py +++ /dev/null @@ -1,59 +0,0 @@ -""" -Obserware -Copyright (C) 2021-2022 Akashdeep Dhar - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -""" - - -from datetime import datetime -from os import uname -from sys import version as pythvers - -import distro -import psutil -from cpuinfo import CPUINFO_VERSION_STRING as cpuivers -from distro import __version__ as distvers -from psutil import __version__ as psutvers -from PyQt5.QtCore import qVersion as pyqtvers - -from obserware import __version__ as obsrvers - - -def return_software_information(): - retndata = { - "name": distro.name(), - "version": distro.version(), - "hostname": uname().nodename, - "release": uname().release, - "rendition": uname().version, - "boottime": datetime.fromtimestamp(psutil.boot_time()).strftime("%Y-%m-%d, %H:%M:%S"), - } - return retndata - - -def return_obserware_information(): - retndata = { - "obsrvers": obsrvers, - "pythvers": pythvers, - "pyqtvers": pyqtvers(), - "psutvers": psutvers, - "cpuivers": cpuivers, - "distvers": distvers, - } - return retndata - - -def is_distributed_via_flatpak(): - return distro.name() == "KDE Flatpak runtime" diff --git a/obserware/sources/readers/mainwind/tab_network.py b/obserware/sources/readers/mainwind/tab_network.py deleted file mode 100644 index 66aed65..0000000 --- a/obserware/sources/readers/mainwind/tab_network.py +++ /dev/null @@ -1,108 +0,0 @@ -""" -Obserware -Copyright (C) 2021-2022 Akashdeep Dhar - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -""" - -import logging -import time - -import psutil - -from obserware.sources.readers import memory - -logging.basicConfig( - level=logging.WARNING, - format="%(asctime)s %(message)s", - datefmt="[%H:%M:%S] [%d %b %Y]", -) - -mmrysize = memory() - - -def return_global_network_rate(): - pvntiocf = psutil.net_io_counters(pernic=False) - time.sleep(1) - nxntiocf = psutil.net_io_counters(pernic=False) - retndata = { - "bytes": { - "recv": "%s/s" % mmrysize.format(nxntiocf.bytes_recv - pvntiocf.bytes_recv), - "sent": "%s/s" % mmrysize.format(nxntiocf.bytes_sent - pvntiocf.bytes_sent), - }, - "packets": { - "recv": "%dPk/s" % (nxntiocf.packets_recv - pvntiocf.packets_recv), - "sent": "%dPk/s" % (nxntiocf.packets_sent - pvntiocf.packets_sent), - }, - } - return retndata - - -def return_pernic_threaded_statistics(): - pvntioct = psutil.net_io_counters(pernic=True) - time.sleep(1) - nxntioct = psutil.net_io_counters(pernic=True) - retndata, netifsat = ( - [], - psutil.net_if_stats(), - ) - for indx in nxntioct.keys(): - try: - retndata.append( - ( - indx, - netifsat[indx].isup, - "%s/s" % mmrysize.format(nxntioct[indx].bytes_recv - pvntioct[indx].bytes_recv), - "%s/s" % mmrysize.format(nxntioct[indx].bytes_sent - pvntioct[indx].bytes_sent), - "%dPk/s" % int(nxntioct[indx].packets_recv - pvntioct[indx].packets_recv), - "%dPk/s" % int(nxntioct[indx].packets_sent - pvntioct[indx].packets_sent), - "%s" % mmrysize.format(nxntioct[indx].bytes_recv), - "%s" % mmrysize.format(nxntioct[indx].bytes_sent), - "%ldPk(s)" % nxntioct[indx].packets_recv, - "%ldPk(s)" % nxntioct[indx].packets_sent, - "%ld error(s)" % nxntioct[indx].errin, - "%ld error(s)" % nxntioct[indx].errout, - "%ldPk(s)" % nxntioct[indx].dropin, - "%ldPk(s)" % nxntioct[indx].dropout, - ) - ) - except KeyError: - logging.warning( - "Statistics for the network device '%s' could not be retrieved" % str(indx) - ) - logging.warning("Please click on the REFRESH button to obtain an updated list") - return retndata - - -def return_mainscreen_threaded_statistics(): - netiocnf = psutil.net_io_counters(pernic=False) - retndata = { - "bytes": { - "recv": "%s" % mmrysize.format(netiocnf.bytes_recv), - "sent": "%s" % mmrysize.format(netiocnf.bytes_sent), - }, - "packets": { - "recv": "%ldPk(s)" % netiocnf.packets_recv, - "sent": "%ldPk(s)" % netiocnf.packets_sent, - }, - "errors": { - "recv": "%ld error(s)" % netiocnf.errin, - "sent": "%ld error(s)" % netiocnf.errout, - }, - "dropped": { - "recv": "%ldPk(s)" % netiocnf.dropin, - "sent": "%ldPk(s)" % netiocnf.dropout, - }, - } - return retndata diff --git a/obserware/sources/readers/mainwind/tab_partitions.py b/obserware/sources/readers/mainwind/tab_partitions.py deleted file mode 100644 index 89ea572..0000000 --- a/obserware/sources/readers/mainwind/tab_partitions.py +++ /dev/null @@ -1,105 +0,0 @@ -""" -Obserware -Copyright (C) 2021-2022 Akashdeep Dhar - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -""" - - -import psutil - -from obserware.sources.readers import memory, time - -mmrysize = memory() -timevalu = time() - - -def return_storage_counters(): - diskioqt, partlist = psutil.disk_io_counters(), psutil.disk_partitions(all=True) - retndata = { - "loadqant": diskioqt.read_count, - "saveqant": diskioqt.write_count, - "loadbyte": mmrysize.format(diskioqt.read_bytes), - "savebyte": mmrysize.format(diskioqt.write_bytes), - "loadtime": timevalu.format(diskioqt.read_time), - "savetime": timevalu.format(diskioqt.write_time), - "loadmgqt": diskioqt.read_merged_count, - "savemgqt": diskioqt.write_merged_count, - "partqant": len(partlist), - } - return retndata - - -def return_logical_partition_statistics(): - retnlist, partlist, partqant = ( - [], - [ - indx - for indx in psutil.disk_partitions(all=True) - if indx not in psutil.disk_partitions(all=False) - ], - 0, - ) - for indx in partlist: - partqant += 1 - try: - partdiuj = psutil.disk_usage(indx.mountpoint) - partfree, partused, partcomp, partperc = ( - partdiuj.free, - partdiuj.used, - partdiuj.total, - partdiuj.percent, - ) - except Exception: - partfree, partused, partcomp, partperc = 0, 0, 0, 0 - partdict = { - "lgptdevc": indx.device, - "lgptfutl": { - "free": mmrysize.format(partfree), - "used": mmrysize.format(partused), - "comp": mmrysize.format(partcomp), - "perc": partperc, - }, - "lgptfsys": {"mtpt": indx.mountpoint, "fsys": indx.fstype}, - } - retnlist.append(partdict) - return retnlist - - -def return_physical_partition_statistics(): - retnlist, partlist, partqant = [], psutil.disk_partitions(all=False), 0 - for indx in partlist: - partqant += 1 - try: - partdiuj = psutil.disk_usage(indx.mountpoint) - partfree, partused, partcomp, partperc = ( - partdiuj.free, - partdiuj.used, - partdiuj.total, - partdiuj.percent, - ) - except Exception: - partfree, partused, partcomp, partperc = 0, 0, 0, 0 - partdict = { - "phptdevc": indx.device, - "phptfutl": { - "free": mmrysize.format(partfree), - "used": mmrysize.format(partused), - "comp": mmrysize.format(partcomp), - "perc": partperc, - }, - "phptfsys": {"mtpt": indx.mountpoint, "fsys": indx.fstype}, - } - retnlist.append(partdict) - return retnlist diff --git a/obserware/sources/readers/mainwind/tab_performance.py b/obserware/sources/readers/mainwind/tab_performance.py deleted file mode 100644 index 24af383..0000000 --- a/obserware/sources/readers/mainwind/tab_performance.py +++ /dev/null @@ -1,96 +0,0 @@ -""" -Obserware -Copyright (C) 2021-2022 Akashdeep Dhar - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -""" - - -import psutil -from cpuinfo import get_cpu_info - -from obserware.sources.readers import frequency, time - -freqvalu = frequency() -timevalu = time() - - -def return_mainscreen_threaded_statistics(): - retndata = {} - cputsecs, cputperc, cputqant = ( - psutil.cpu_times(percpu=True), - psutil.cpu_times_percent(percpu=True), - psutil.cpu_count(), - ) - cpudfreq, cpudperc = (psutil.cpu_freq(percpu=True), psutil.cpu_percent(percpu=True)) - for indx in range(cputqant): - retndata[indx] = { - "cpuclock": { - "usejperc": int(cpudperc[indx]), - "cpudhrtz": { - "cpumaxhz": freqvalu.format(cpudfreq[indx].max), - "cpuminhz": freqvalu.format(cpudfreq[indx].min), - "cpucurhz": freqvalu.format(cpudfreq[indx].current), - }, - }, - "cputimes": { - "time": { - "cputusnm": timevalu.format(cputsecs[indx].user), - "cputuspr": timevalu.format(cputsecs[indx].nice), - "cputkrnm": timevalu.format(cputsecs[indx].system), - "cputnull": timevalu.format(cputsecs[indx].idle), - "cputiowt": timevalu.format(cputsecs[indx].iowait), - "cputhirq": timevalu.format(cputsecs[indx].irq), - "cputsirq": timevalu.format(cputsecs[indx].softirq), - "cputvirt": timevalu.format(cputsecs[indx].steal), - "cputgest": timevalu.format(cputsecs[indx].guest), - "cputgtnc": timevalu.format(cputsecs[indx].guest_nice), - }, - "perc": { - "cputusnm": cputperc[indx].user, - "cputuspr": cputperc[indx].nice, - "cputkrnm": cputperc[indx].system, - "cputnull": cputperc[indx].idle, - "cputiowt": cputperc[indx].iowait, - "cputhirq": cputperc[indx].irq, - "cputsirq": cputperc[indx].softirq, - "cputvirt": cputperc[indx].steal, - "cputgest": cputperc[indx].guest, - "cputgtnc": cputperc[indx].guest_nice, - }, - }, - } - return retndata - - -def return_cpu_specifications_information(): - retndata = { - "name": get_cpu_info().get("brand_raw"), - "vendor": get_cpu_info().get("vendor_id_raw"), - "frequency": get_cpu_info().get("hz_advertised_friendly"), - "count": get_cpu_info().get("count"), - "bits": get_cpu_info().get("bits"), - "arch": get_cpu_info().get("arch"), - "stepping": get_cpu_info().get("stepping"), - "model": get_cpu_info().get("model"), - "family": get_cpu_info().get("family"), - } - return retndata - - -def return_feature_flags_information(): - retndata = {"featflag": []} - if get_cpu_info().get("flags"): - retndata["featflag"] = get_cpu_info().get("flags") - return retndata diff --git a/obserware/sources/readers/mainwind/tab_processes.py b/obserware/sources/readers/mainwind/tab_processes.py deleted file mode 100644 index 2472217..0000000 --- a/obserware/sources/readers/mainwind/tab_processes.py +++ /dev/null @@ -1,51 +0,0 @@ -""" -Obserware -Copyright (C) 2021-2022 Akashdeep Dhar - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -""" - - -import psutil - -statistics_columns = [ - "pid", - "name", - "terminal", - "username", - "status", - "cpu_percent", - "memory_percent", - "num_threads", -] - - -def return_processes_list(): - proclist, procqant = [], 0 - for proc in psutil.process_iter(statistics_columns): - proclist.append( - ( - str(proc.info["pid"]), - str(proc.info["name"]), - str(proc.info["terminal"]), - str(proc.info["username"]), - str(proc.info["status"]), - "%2.1f" % proc.info["cpu_percent"], - "%2.1f" % proc.info["memory_percent"], - str(proc.info["num_threads"]), - ) - ) - procqant += 1 - retndata = {"process_list": proclist, "process_count": procqant} - return retndata diff --git a/obserware/sources/readers/mainwind/tab_resources.py b/obserware/sources/readers/mainwind/tab_resources.py deleted file mode 100644 index 5a8b710..0000000 --- a/obserware/sources/readers/mainwind/tab_resources.py +++ /dev/null @@ -1,99 +0,0 @@ -""" -Obserware -Copyright (C) 2021-2022 Akashdeep Dhar - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -""" - - -import getpass -from os import uname - -import psutil - -from obserware.sources.readers import memory - -mmrysize = memory() - - -def return_bottombar_threaded_statistics(): - retndata = { - "cpud_percent": psutil.cpu_percent(), - "memo_percent": psutil.virtual_memory().percent, - "swap_percent": psutil.swap_memory().percent, - "disk_percent": psutil.disk_usage("/").percent, - } - return retndata - - -def return_bottombar_onetimed_statistics(): - retndata = { - "username": getpass.getuser(), - "hostname": uname().nodename, - "systname": uname().sysname, - "rlsename": uname().release, - } - return retndata - - -def return_mainscreen_threaded_statistics(): - retndata = { - "memo": { - "percentage": { - "used": psutil.virtual_memory().used * 100 / psutil.virtual_memory().total, - "cached": psutil.virtual_memory().cached * 100 / psutil.virtual_memory().total, - "free": psutil.virtual_memory().free * 100 / psutil.virtual_memory().total, - }, - "absolute": { - "used": mmrysize.format(psutil.virtual_memory().used), - "cached": mmrysize.format(psutil.virtual_memory().cached), - "free": mmrysize.format(psutil.virtual_memory().free), - "total": mmrysize.format(psutil.virtual_memory().total), - "active": mmrysize.format(psutil.virtual_memory().active), - "buffers": mmrysize.format(psutil.virtual_memory().buffers), - "shared": mmrysize.format(psutil.virtual_memory().shared), - "slab": mmrysize.format(psutil.virtual_memory().slab), - }, - }, - "swap": { - "percentage": { - "used": (psutil.swap_memory().used * 100 / psutil.swap_memory().total) - if psutil.swap_memory().total > 0 - else 0, - "free": (psutil.swap_memory().free * 100 / psutil.swap_memory().total) - if psutil.swap_memory().total > 0 - else 100, - }, - "absolute": { - "used": mmrysize.format(psutil.swap_memory().used), - "free": mmrysize.format(psutil.swap_memory().free), - "total": mmrysize.format(psutil.swap_memory().total), - "sin": mmrysize.format(psutil.swap_memory().sin), - "sout": mmrysize.format(psutil.swap_memory().sout), - }, - }, - "cpud": { - "percentage": { - "used": psutil.cpu_percent(), - "free": 100 - psutil.cpu_percent(), - }, - "absolute": { - "ctx_switches": psutil.cpu_stats().ctx_switches, - "interrupts": psutil.cpu_stats().interrupts, - "soft_interrupts": psutil.cpu_stats().soft_interrupts, - "sys_calls": psutil.cpu_stats().syscalls, - }, - }, - } - return retndata diff --git a/obserware/sources/readers/procwind/__init__.py b/obserware/sources/readers/procwind/__init__.py deleted file mode 100644 index 0c5eff8..0000000 --- a/obserware/sources/readers/procwind/__init__.py +++ /dev/null @@ -1,17 +0,0 @@ -""" -Obserware -Copyright (C) 2021-2022 Akashdeep Dhar - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -""" diff --git a/obserware/sources/readers/procwind/controller.py b/obserware/sources/readers/procwind/controller.py deleted file mode 100644 index 3ffcaf7..0000000 --- a/obserware/sources/readers/procwind/controller.py +++ /dev/null @@ -1,83 +0,0 @@ -""" -Obserware -Copyright (C) 2021-2022 Akashdeep Dhar - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -""" - - -import logging - -import psutil - -logging.basicConfig( - level=logging.WARNING, - format="%(asctime)s %(message)s", - datefmt="[%H:%M:%S] [%d %b %Y]", -) - - -def log_process_interaction(logecode, prociden, taskverb): - if logecode == 0: - logetext = "PID %d was %s successfully" % (prociden, taskverb) - elif logecode == 1: - logetext = "PID %d could not be %s as it does not exist" % (prociden, taskverb) - else: - logetext = "PID %d could not be %s due to improper privileges" % (prociden, taskverb) - logging.warning(logetext) - return logetext - - -def kill_process(prociden): - taskverb = "killed" - try: - psutil.Process(prociden).kill() - return log_process_interaction(0, prociden, taskverb) - except psutil.NoSuchProcess: - return log_process_interaction(1, prociden, taskverb) - except psutil.AccessDenied: - return log_process_interaction(2, prociden, taskverb) - - -def terminate_process(prociden): - taskverb = "terminated" - try: - psutil.Process(prociden).terminate() - return log_process_interaction(0, prociden, taskverb) - except psutil.NoSuchProcess: - return log_process_interaction(1, prociden, taskverb) - except psutil.AccessDenied: - return log_process_interaction(2, prociden, taskverb) - - -def resume_process(prociden): - taskverb = "resumed" - try: - psutil.Process(prociden).resume() - return log_process_interaction(0, prociden, taskverb) - except psutil.NoSuchProcess: - return log_process_interaction(1, prociden, taskverb) - except psutil.AccessDenied: - return log_process_interaction(2, prociden, taskverb) - - -def suspend_process(prociden): - taskverb = "suspended" - try: - psutil.Process(prociden).suspend() - return log_process_interaction(0, prociden, taskverb) - except psutil.NoSuchProcess: - return log_process_interaction(1, prociden, taskverb) - except psutil.AccessDenied: - return log_process_interaction(2, prociden, taskverb) diff --git a/obserware/sources/readers/procwind/provider.py b/obserware/sources/readers/procwind/provider.py deleted file mode 100644 index 1880716..0000000 --- a/obserware/sources/readers/procwind/provider.py +++ /dev/null @@ -1,58 +0,0 @@ -""" -Obserware -Copyright (C) 2021-2022 Akashdeep Dhar - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -""" - - -import time -from datetime import datetime - -import psutil - - -def check_process_existence(prociden): - try: - psutil.Process(prociden) - return True - except psutil.NoSuchProcess: - return False - - -def return_mainscreen_onetimed_statistics(prociden): - procobjc = psutil.Process(prociden) - retndata = { - "prociden": procobjc.pid, - "procname": procobjc.name(), - "cpu_percent": procobjc.cpu_percent(), - "memory_percent": procobjc.memory_percent(), - "cpu_num": procobjc.cpu_num(), - "num_threads": procobjc.num_threads(), - "username": procobjc.username(), - "terminal": procobjc.terminal(), - "nice": procobjc.nice(), - "ionice": procobjc.ionice().value, - "num_ctx_switches": { - "voluntary": procobjc.num_ctx_switches().voluntary, - "involuntary": procobjc.num_ctx_switches().involuntary, - }, - "ppid": procobjc.ppid(), - "status": procobjc.status().title(), - "create_time": datetime.fromtimestamp(procobjc.create_time()).strftime( - "%Y-%m-%d, %H:%M:%S" - ), - "acquired_on": datetime.fromtimestamp(time.time()).strftime("%Y-%m-%d, %H:%M:%S"), - } - return retndata