示例#1
0
def disk_info(message):
    computer = Computer()
    cid = message.chat.id 
    for memory in computer.nonvolatile_memory:
        size = memory.total/1024/1024
        info = "File System {} \nMount {} \nSize {} \nMB Use {} %".format(memory.fstype,memory.device,int(size),memory.used_percent)
        bot.send_message(cid,info)
示例#2
0
def cpu_info(message):
    computer = Computer()
    cid = message.chat.id 
    cpu = Processor(monitoring_latency=1)
    with cpu:
     for i in range(cpu.count):
        print(cpu.load, cpu.temperature)
        info = "CPU{} \nUse {} % \nTemp {} C".format(i,cpu.load,cpu.temperature) 
        bot.send_message(cid,info)
        sleep(1.1)
示例#3
0
    def pullPCInfo(self):
        cpu = Cpu(monitoring_latency=1)
        comp = Computer()

        os = comp.os
        hostname = comp.hostname
        cpuName = cpu.name
        cpuCoreCount = cpu.count
        ip = self.findNetworkIP()
        mac = self.find_network_mac()

        return (hostname, os, cpuName, cpuCoreCount, ip, mac)
示例#4
0
            Format.byte_value(computer.virtual_memory.total),
            Format.percent(computer.virtual_memory.used_percent)
        ))
        print('')
        # Display nonvolatile memory info
        output_format1 = '{:_^16}{:_^16}{:_^16}{:_^16}{:_^16}'
        output_format2 = '{: ^16}{: ^16}{: ^16}{: ^16}{: ^16}'
        print(output_format1.format('Device', 'Total', 'Use', 'Type', 'Mount'))
        for dev in computer.nonvolatile_memory:
            output_text = output_format2.format(
                dev.device,
                Format.byte_value(dev.total),
                Format.percent(dev.used_percent),
                dev.fstype,
                dev.mountpoint
            )
            print(output_text)
        sleep(1)
    print_hr(space_before=True)
    print('Shutdown monitoring system...')


if __name__ == '__main__':
    # Initialize computer instance
    from pyspectator.computer import Computer
    curr_computer = Computer()
    # Start monitoring system
    with curr_computer:
        # Start console interface
        main(curr_computer)
示例#5
0
    def update(self):
        ram_info = psutil.virtual_memory()
        disk_info = psutil.disk_partitions()
        disk_memory_info = psutil.disk_usage(disk_info[0].mountpoint)
        gpu_info = GPUtil.getGPUs()[0]
        self.config.update({
            'processor': {
                'architecture': platform.processor(),
                'total_cores': psutil.cpu_count(logical=True),
                'max_frequency': f'{psutil.cpu_freq().max}Mhz',
                'current_frequency': f'{psutil.cpu_freq().current:.2f}Mhz',
                'loading': f'{psutil.cpu_percent()}%',
                'usage_per_core': self.get_cpu_per_core(),
            },
            'disk': {
                'file_system_type': disk_info[0].fstype,
                'total_memory': self.get_size(disk_memory_info.total),
                'available': self.get_size(disk_memory_info.free),
                'used': self.get_size(disk_memory_info.used),
                'used_in_percents': f'{disk_memory_info.percent}%',
            },
            'ram': {
                'total_memory': self.get_size(ram_info.total),
                'available': self.get_size(ram_info.available),
                'used': self.get_size(ram_info.used),
                'used_in_percents': f'{ram_info.percent}%',
            },
            'gpu': {
                'name':
                gpu_info.name,
                'temperature':
                f'{gpu_info.temperature}°C',
                'loading':
                f'{gpu_info.load}%',
                'total_memory':
                f'{gpu_info.memoryTotal}MB',
                'available':
                f'{gpu_info.memoryFree}MB',
                'used':
                f'{gpu_info.memoryUsed}MB',
                'used_in_percents':
                f'{gpu_info.memoryUsed / gpu_info.memoryTotal * 100:.2f}%'
            }
        })

        if self.system_name == OSName.LINUX.value:
            self.config['processor'].update({
                'name':
                Computer().processor.name,
                'architecture':
                platform.processor(),
                'temperature':
                f'{psutil.sensors_temperatures()["k10temp"][0].current}°C'
            })

        if self.system_name == OSName.WINDOWS.value:
            self.config['processor'].update({
                'name':
                self.get_processor_name(),
                'architecture':
                str(platform.architecture()[0]),
                'temperature':
                f'Unavailable for OS Windows'
            })
示例#6
0
    def __init__(self, token: str):

        os_info = platform.uname()

        self.system_name = os_info.system

        ram_info = psutil.virtual_memory()
        disk_info = psutil.disk_partitions()
        disk_memory_info = psutil.disk_usage(disk_info[0].mountpoint)
        gpu_info = GPUtil.getGPUs()[0]

        self.config = {
            'token': token,
            'os': {
                'name': self.system_name,
                'version': os_info.version,
            },
            'processor': {
                'total_cores': psutil.cpu_count(logical=True),
                'max_frequency': f'{psutil.cpu_freq().max}Mhz',
                'current_frequency': f'{psutil.cpu_freq().current:.2f}Mhz',
                'loading': f'{psutil.cpu_percent()}%',
                'usage_per_core': self.get_cpu_per_core(),
            },
            'socket_info': {
                'host':
                socket.gethostname(),
                'ip_address':
                socket.gethostbyname(socket.gethostname()),
                'mac_address':
                ':'.join(re.findall('..', '%012x' % uuid.getnode())),
            },
            'disk': {
                'file_system_type': disk_info[0].fstype,
                'total_memory': self.get_size(disk_memory_info.total),
                'available': self.get_size(disk_memory_info.free),
                'used': self.get_size(disk_memory_info.used),
                'used_in_percents': f'{disk_memory_info.percent}%',
            },
            'ram': {
                'total_memory': self.get_size(ram_info.total),
                'available': self.get_size(ram_info.available),
                'used': self.get_size(ram_info.used),
                'used_in_percents': f'{ram_info.percent}%',
            },
            'gpu': {
                'name':
                gpu_info.name,
                'temperature':
                f'{gpu_info.temperature}°C',
                'loading':
                f'{gpu_info.load}%',
                'total_memory':
                f'{gpu_info.memoryTotal}MB',
                'available':
                f'{gpu_info.memoryFree}MB',
                'used':
                f'{gpu_info.memoryUsed}MB',
                'used_in_percents':
                f'{gpu_info.memoryUsed / gpu_info.memoryTotal * 100:.2f}%'
            }
        }

        if self.system_name == OSName.LINUX.value:
            self.config['processor'].update({
                'name':
                Computer().processor.name,
                'architecture':
                platform.processor(),
                'temperature':
                f'{psutil.sensors_temperatures()["k10temp"][0].current}°C'
            })

        if self.system_name == OSName.WINDOWS.value:
            self.config['processor'].update({
                'name':
                self.get_processor_name(),
                'architecture':
                platform.architecture()[0],
                'temperature':
                'Unavailable for OS Windows'
            })
示例#7
0
 def __init__(self, mode=Mode.debug, address=None, port=None):
     self.address = address
     handlers = [
         (r'/', MonitorGeneralHandler),
         (r'/auth/login', AuthLoginHandler),
         (r'/user/profile/([a-zA-Z0-9_])+', UserProfileHandler),
         (r'/monitor/general', MonitorGeneralHandler),
         (r'/monitor/cpu', MonitorCpuHandler),
         (r'/monitor/memory', MonitorMemoryHandler),
         (r'/monitor/disk', MonitorDiskHandler),
         (r'/monitor/network', MonitorNetworkHandler),
         (r'/api/comp_info/cpu/load', ApiCpuLoad),
         (r'/api/comp_info/cpu/load_stats', ApiCpuLoadStats),
         (r'/api/comp_info/mem/available', ApiMemAvailable),
         (r'/api/comp_info/mem/used_percent', ApiMemUsedPercent),
         (r'/api/comp_info/mem/used_percent_stats', ApiMemUsedPercentStats),
         (r'/api/comp_info/disk', ApiDisk),
         (r'/api/comp_info/nif/bytes_sent', ApiNifBytesSent),
         (r'/api/comp_info/nif/bytes_recv', ApiNifBytesRecv),
         (r'/about', AboutPageHandler),
         (r'.*', PageNotFoundHandler),
     ]
     default_port = 8888
     settings = {
         # Path to templates
         'template_path':
         os.path.join(os.path.dirname(__file__), 'templates'),
         # Path to shared files
         'static_path':
         os.path.join(os.path.dirname(__file__), 'static'),
         # Users authorization page
         'login_url':
         '/auth/login',
         # Salt for encrypt secure cookies
         'cookie_secret':
         base64.b64encode('42: Answer to the Ultimate Question of Life, '
                          'the Universe, and Everything'.encode()),
         # The app will be watching for changes in source files and
         # reload itself on file change
         'autoreload':
         True,
         # Templates will not be cached
         'compiled_template_cache':
         False,
         # Static file will not be cached
         'static_hash_cache':
         False,
         # When raises some Exception an extended error page will be
         # generated
         'serve_traceback':
         True,
         # Disable cross-site request forgery protection
         'xsrf_cookies':
         False
     }
     if mode == Mode.release:
         default_port = 80
         settings.update({
             # Templates will be cached
             'compiled_template_cache': True,
             # Static file will be cached
             'static_hash_cache': True,
             # Don't show error page with stack trace
             # when raises some Exception
             'serve_traceback': False,
             # The app don't will watch for changes in its source files
             'autoreload': False,
             # Enable cross-site request forgery protection
             # 'xsrf_cookies': True
         })
     self.port = default_port if port is None else port
     self.comp_info = Computer()
     super().__init__(handlers, **settings)
示例#8
0
#warnings.filterwarnings("ignore") #ignora avisos

#importa bibilhotecas de data e hora
import time
from time import localtime, strftime
import datetime

#importa biblioteca para comunicação com o banco de dados
import mysql.connector
from mysql.connector import Error

#importa bibliotecas de captura de informações do sistema
import psutil  #sudo apt install python3-psutil
from pyspectator.computer import Computer

computer = Computer()
computer.os

sleep = 60  # Intervalo em segundos de cada postagem

# Tenta iniciar conexão com o banco de dados
try:
    connection = mysql.connector.connect(host='localhost',
                                         database='pivi',
                                         user='******',
                                         password='')

    if connection.is_connected():
        db_Info = connection.get_server_info()
        print("Conectado ao Servidor MySQL versão ", db_Info)
        cursor = connection.cursor()
示例#9
0
def memory(message):
    computer = Computer()
    cid = message.chat.id 
    info = "SIZE {} \nUSE {}%".format(computer.virtual_memory.total/1073741824,computer.virtual_memory.used_percent)
    bot.send_message(cid,info)
示例#10
0
def info(message):
    computer = Computer()
    cid = message.chat.id 
    info = "S.O {} {} \nIP {} \nPython {} \nCPU {}".format(computer.os,computer.architecture,computer.network_interface.ip_address,computer.python_version,computer.processor.name)
    bot.send_message(cid,info)
示例#11
0
            Format.byte_value(computer.network_interface.bytes_recv)))
        print('')
        # Display virtual memory info
        print('Virtual memory: use {} from {}, {}'.format(
            Format.byte_value(computer.virtual_memory.available),
            Format.byte_value(computer.virtual_memory.total),
            Format.percent(computer.virtual_memory.used_percent)))
        print('')
        # Display nonvolatile memory info
        output_format1 = '{:_^16}{:_^16}{:_^16}{:_^16}{:_^16}'
        output_format2 = '{: ^16}{: ^16}{: ^16}{: ^16}{: ^16}'
        print(output_format1.format('Device', 'Total', 'Use', 'Type', 'Mount'))
        for dev in computer.nonvolatile_memory:
            output_text = output_format2.format(
                dev.device, Format.byte_value(dev.total),
                Format.percent(dev.used_percent), dev.fstype, dev.mountpoint)
            print(output_text)
        sleep(1)
    print_hr(space_before=True)
    print('Shutdown monitoring system...')


if __name__ == '__main__':
    # Initialize computer instance
    from pyspectator.computer import Computer
    COMPUTER = Computer()
    # Start monitoring system
    with COMPUTER:
        # Start console interface
        main(COMPUTER)