Skip to content

Commit

Permalink
Integrate network module into "Computer" class and console application.
Browse files Browse the repository at this point in the history
  • Loading branch information
eterey committed Jun 9, 2014
1 parent cd746ac commit 94f0234
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
22 changes: 19 additions & 3 deletions console.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ def start(computer):
for _ in range(16):
clear()
# Display general information about computer
print('Hostname: ' + str(computer.hostname))
print('OS: ' + str(computer.os))
print('Boot time: ' + str(computer.boot_time))
print('Uptime: ' + str(computer.uptime))
print('Boot time: {0}; Uptime: {1}'.format(computer.boot_time, computer.uptime))
print('')
# Display CPU info
print('CPU name: ' + str(computer.processor.name))
print('Amount of CPU cores: ' + str(computer.processor.count))
Expand All @@ -55,12 +54,29 @@ def start(computer):
if computer.processor.temperature is not None:
cpu_temperature = Format.temperature(computer.processor.temperature)
print('CPU temperature: ' + cpu_temperature)
print('')
# Display network info
print('Hostname: ' + str(computer.hostname))
print('Network interface: ' + str(computer.network_interface.name))
print('MAC address: ' + str(computer.network_interface.hardware_address))
print('IP: {0}; Mask: {2}; Gateway: {3}'.format(
computer.network_interface.ip_address,
computer.network_interface.broadcast_address,
computer.network_interface.subnet_mask,
computer.network_interface.default_route
))
print('Sent data: {0}; Received data: {1}'.format(
Format.byte_value(computer.network_interface.bytes_sent),
Format.byte_value(computer.network_interface.bytes_recv)
))
print('')
# Display virtual memory info
print('Virtual memory: use {0} from {1}, {2}'.format(
Format.byte_value(computer.virtual_memory.available),
Format.byte_value(computer.virtual_memory.total),
Format.percent(computer.virtual_memory.percent)
))
print('')
# Display nonvolatile memory info
output_format1 = '{0:_^16}{1:_^16}{2:_^16}{3:_^16}{4:_^16}'
output_format2 = '{0: ^16}{1: ^16}{2: ^16}{3: ^16}{4: ^16}'
Expand Down
8 changes: 7 additions & 1 deletion pyspectator/computer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import psutil
import platform
from datetime import datetime
from pyspectator.monitoring import AbcMonitor
from pyspectator.memory import NonvolatileMemory, VirtualMemory, SwapMemory
from pyspectator.processor import Processor
from pyspectator.monitoring import AbcMonitor
from pyspectator.network import NetworkInterface


class Computer(AbcMonitor):
Expand All @@ -22,6 +23,7 @@ def __init__(self):
self.__nonvolatile_memory_devices = set([dev_info.device for dev_info in self.__nonvolatile_memory])
self.__virtual_memory = VirtualMemory(monitoring_latency=1)
self.__swap_memory = SwapMemory(monitoring_latency=1)
self.__network_interface = NetworkInterface(monitoring_latency=3)
super().__init__(monitoring_latency=3)

# endregion
Expand Down Expand Up @@ -72,6 +74,10 @@ def virtual_memory(self):
def swap_memory(self):
return self.__swap_memory

@property
def network_interface(self):
return self.__network_interface

# endregion

def _monitoring_action(self):
Expand Down
7 changes: 5 additions & 2 deletions start.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
from console import start as start_console
from pyspectator.computer import Computer

# Initialize computer instance
computer = Computer()
try:
# Initialize computer instance
computer = Computer()
# Start monitoring
computer.start_monitoring()
computer.processor.start_monitoring()
for mem in computer.nonvolatile_memory:
mem.start_monitoring()
computer.virtual_memory.start_monitoring()
computer.network_interface.start_monitoring()

# Start console interface
start_console(computer)
Expand All @@ -21,5 +23,6 @@
for mem in computer.nonvolatile_memory:
mem.stop_monitoring()
computer.virtual_memory.stop_monitoring()
computer.network_interface.stop_monitoring()
computer.stop_monitoring()
sleep(1)

0 comments on commit 94f0234

Please sign in to comment.