modularize and make loading psutil dependant code check if psutil is tehre first. Add more license boilerplate
This commit is contained in:
parent
63c8706039
commit
523e57e238
14
monitor.py
14
monitor.py
|
@ -8,8 +8,7 @@
|
||||||
#
|
#
|
||||||
# System-Monitoring-Daemon is free software: you can redistribute it and/or modify
|
# System-Monitoring-Daemon is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
# the Free Software Foundation, version 3 of the License.
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
#
|
||||||
# System-Monitoring-Daemon is distributed in the hope that it will be useful,
|
# System-Monitoring-Daemon is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
@ -24,8 +23,9 @@ import threading
|
||||||
from socket import *
|
from socket import *
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from sensors.cpu import *
|
#from sensors.cpu import *
|
||||||
from sensors.memory import *
|
#from sensors.memory import *
|
||||||
|
import sensors
|
||||||
|
|
||||||
HOST = ''
|
HOST = ''
|
||||||
PORT = 6000
|
PORT = 6000
|
||||||
|
@ -39,9 +39,9 @@ class Stats():
|
||||||
self.read_lock = threading.Lock()
|
self.read_lock = threading.Lock()
|
||||||
self.write_lock = threading.Lock()
|
self.write_lock = threading.Lock()
|
||||||
|
|
||||||
self.sensors = []
|
self.sensors = sensors.sensors #[]
|
||||||
self.sensors.append(cpu_monitor())
|
#self.sensors.append(cpu_monitor())
|
||||||
self.sensors.append(mem_monitor())
|
#self.sensors.append(mem_monitor())
|
||||||
|
|
||||||
self.stop = threading.Event()
|
self.stop = threading.Event()
|
||||||
t = threading.Thread(target=self.update_loop, args=())
|
t = threading.Thread(target=self.update_loop, args=())
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
# Sensors Module
|
||||||
|
# Load appropriate sensor sub module to monitor system with
|
||||||
|
#
|
||||||
|
# Copyright 2012 Dan Ballard and Robert Hausch
|
||||||
|
#
|
||||||
|
## License:
|
||||||
|
#
|
||||||
|
# This file is part of System-Monitoring-Daemon.
|
||||||
|
#
|
||||||
|
# System-Monitoring-Daemon 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, version 3 of the License.
|
||||||
|
#
|
||||||
|
# System-Monitoring-Daemon 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 System-Monitoring-Daemon. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
##
|
||||||
|
|
||||||
|
|
||||||
|
# Load appropriate sensor code
|
||||||
|
|
||||||
|
has_psutil = False
|
||||||
|
try:
|
||||||
|
import psutil
|
||||||
|
has_psutil = True
|
||||||
|
except:
|
||||||
|
None
|
||||||
|
|
||||||
|
sensors = []
|
||||||
|
|
||||||
|
if has_psutil:
|
||||||
|
from psutil_sensors import *
|
||||||
|
sensors.append(cpu.cpu_monitor())
|
||||||
|
sensors.append(memory.mem_monitor())
|
|
@ -1,18 +0,0 @@
|
||||||
#!/usr/bin/python
|
|
||||||
|
|
||||||
import psutil
|
|
||||||
|
|
||||||
class mem_monitor:
|
|
||||||
def __init__(self):
|
|
||||||
self.mem_usage = ''
|
|
||||||
self.virt_mem_usage = ''
|
|
||||||
|
|
||||||
def update(self):
|
|
||||||
self.mem_usage = psutil.phymem_usage()
|
|
||||||
self.virt_mem_usage = psutil.virtmem_usage()
|
|
||||||
|
|
||||||
def getFormatedData(self):
|
|
||||||
message = '{"type": "Memory", "value": "%.1f", "data": [{"name": "Physical", "value": "%.1f"},{"name": "Virtual", "value": "%.1f"}]}' % (self.mem_usage.percent, self.mem_usage.percent, self.virt_mem_usage.percent)
|
|
||||||
return message
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,27 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
#
|
||||||
|
# CPU sensor ontop of psutil
|
||||||
|
#
|
||||||
|
# Copyright 2012 Dan Ballard and Robert Hausch
|
||||||
|
#
|
||||||
|
## License:
|
||||||
|
#
|
||||||
|
# This file is part of System-Monitoring-Daemon.
|
||||||
|
#
|
||||||
|
# System-Monitoring-Daemon 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, version 3 of the License.
|
||||||
|
#
|
||||||
|
# System-Monitoring-Daemon 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 System-Monitoring-Daemon. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
##
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import psutil
|
import psutil
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
#
|
||||||
|
# Memory monitor ontop of psutil
|
||||||
|
#
|
||||||
|
# Copyright 2012 Dan Ballard and Robert Hausch
|
||||||
|
#
|
||||||
|
## License:
|
||||||
|
#
|
||||||
|
# This file is part of System-Monitoring-Daemon.
|
||||||
|
#
|
||||||
|
# System-Monitoring-Daemon 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, version 3 of the License.
|
||||||
|
#
|
||||||
|
# System-Monitoring-Daemon 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 System-Monitoring-Daemon. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
##
|
||||||
|
|
||||||
|
|
||||||
|
import psutil
|
||||||
|
|
||||||
|
class mem_monitor:
|
||||||
|
def __init__(self):
|
||||||
|
self.mem_usage = ''
|
||||||
|
self.virt_mem_usage = ''
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
self.mem_usage = psutil.phymem_usage()
|
||||||
|
self.virt_mem_usage = psutil.virtmem_usage()
|
||||||
|
|
||||||
|
def getFormatedData(self):
|
||||||
|
message = '{"type": "Memory", "value": "%.1f", "data": [{"name": "Physical", "value": "%.1f"},{"name": "Virtual", "value": "%.1f"}]}' % (self.mem_usage.percent, self.mem_usage.percent, self.virt_mem_usage.percent)
|
||||||
|
return message
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue