Beispiel #1
0
def main(argv):

	try:
		opts, args = getopt.getopt(argv[1:], "hf:m:d:n:s:u:p:", ["help", "frequency=","monitor-ip=","port=","hostname=","sensorname=","username="******"password="******"SystemInfo" and argv[0] != "NetworkInfo" and argv[0] != "SystemLoad"):	
		print("Sensor type not recognized")
		sys.exit()
		

		
	# Load config file
	if len(args) == 1:
		options = load(args[0])

	# Set sensor type
	options.sensortype = argv[0]
		
	# Parse options
	for o,value in opts:
		if o in ("-h", "--help"):
			usage()
			sys.exit()
		elif o in ("-f", "--frequency"):
			options.frequency = value
		elif o in ("-m", "--monitor-ip"):
			options.monitorIP = value
		elif o in ("-d", "--port"):
			options.port = value
		elif o in ("-n", "--hostname"):
			options.hostname = value
		elif o in ("-s", "--sensorname"):
			options.sensorname = value
		elif o in ("-u", "--username"):
			options.username = value
		elif o in ("-p", "--password"):
			options.password = value
		else:	
			print("Unhandled option")
			sys.exit(2)	
			
	# Frequency validation
	
	try:
		if float(options.frequency) <= 0:
			raise ValueError
	except ValueError:
		print("Frequency must be positive float")
		sys.exit(2)
		
	options.frequency = float(options.frequency)
	
	# Port validation
	
	try:
		if int(options.port) <= 0:
			raise ValueError
	except ValueError:
		print("Port must be positive integer")
		sys.exit(2)
		
	options.port = int(options.port)
	
	# Monitor IP validation
	
	try:
		socket.inet_aton(options.monitorIP)
	except socket.error:
		print("Invalid monitor IP")
		sys.exit(2)

	# Run sensor

	sensor = None
	
	if options.sensortype == "SystemInfo":
		sensor = SensorSystemInfo(options)
	if options.sensortype == "SystemLoad":
		sensor = SensorSystemLoad(options)
	if options.sensortype == "NetworkInfo":
		sensor = SensorNetworkInfo(options)
	
	try:
		sensor.run()
	except:
		sensor.stop()
		print("Unexpected error:", sys.exc_info())
		print("Closing...")
Beispiel #2
0
from internal.SensorSystemInfo import *
from internal.SensorSystemLoad import *
from internal.SensorNetworkInfo import *
from internal.Options import *
import time
import os

clear = lambda: os.system('clear')


options = Options()
options.frequency = 1.0
networkInfo = SensorNetworkInfo(options)
systemInfo = SensorSystemInfo(options)
systemLoad = SensorSystemLoad(options)

try:
	while True:

		clear()

		print("========= SystemInfo =========")
		print("System name:\t\t%s" % systemInfo.name())
		print("Architecture:\t\t%s" % systemInfo.architecture())
		print("CPU name:\t\t%s" % systemInfo.CPU())
		print("Total RAM:\t\t%f GB" % (systemInfo.totalRAM() / 1024.0 / 1024.0 / 1024.0) )
		print("Total disk space:\t%f GB" % (systemInfo.totalDiskSpace() / 1024.0 / 1024.0 / 1024.0) )
		#print("Host IP:\t\t%s" % systemInfo.IP())
		print("")
		print("========= SystemLoad =========")
		print("Free memory:\t\t%f MB" % (systemLoad.freeMemory() / 1024.0 / 1024.0) )