Home | Trees | Indices | Help |
---|
|
1 ######################################################################### 2 # YASMon - Yet Another System Monitor # 3 # Copyright (C) 2010 Scott Lawrence # 4 # # 5 # This program is free software: you can redistribute it and/or modify # 6 # it under the terms of the GNU General Public License as published by # 7 # the Free Software Foundation, either version 3 of the License, or # 8 # (at your option) any later version. # 9 # # 10 # This program is distributed in the hope that it will be useful, # 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of # 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 13 # GNU General Public License for more details. # 14 # # 15 # You should have received a copy of the GNU General Public License # 16 # along with this program. If not, see <http://www.gnu.org/licenses/>. # 17 ######################################################################### 18 19 """Collect data from remote systems. 20 21 """ 22 23 import cPickle,re,socket,thread 24 from system import * 2527 """Returns an object representing a remote system. 28 """ 29 contact=RemoteContact(addr,port) 30 system=RemoteSystem(contact) 31 return system3234 """Communicates with a remote machine. 35 36 Objects of this class may be used for communication with the 37 remote machine. The necessary locking is handled automatically, so 38 this class is thread-safe. 39 """108 10941 """Connects to the remote machine. 42 """ 43 #connect 44 sock=socket.socket(socket.AF_INET, socket.SOCK_STREAM) 45 sock.connect((addr,port)) 46 self._socket=sock 47 self._lock=thread.allocate_lock() 48 self._addr=addr 49 self._port=port5052 """Queries the remote machine. 53 54 This method automatically handles the necessary locking to be 55 thread-safe. Do NOT acquire this object's lock before calling 56 this method - the method will block and never return. 57 """ 58 with self.lock(): 59 #get the file 60 f=self.socket().makefile() 61 #send the query 62 f.write("%s\n" % query) 63 f.flush() 64 info="" 65 #read until final token 66 for line in f: 67 #get rid of excess newline 68 line=re.sub("\n","",line) 69 if line=='*DONE': 70 #it's over 71 break 72 #append the line 73 info+="%s\n" % line 74 return info7577 """Returns the backing socket. 78 79 Because using this socket erases the thread safety, this 80 method should never be used. 81 """ 82 return self._socket83 88 93 98 103111 """Represents a remote system. 112 """147 148114 """Creates an empty remote system. 115 116 This constructor DOES initialize the remote system, using the 117 RemoteContact passed to it (generally by get_remote). 118 """ 119 #initialize stuff 120 addr=contact.addr() 121 System.__init__(self,addr) 122 self._contact=contact 123 #assume certain things - we have uptime, memory, etc... 124 self.set_uptime(RemoteUptime(contact)) 125 self.set_memory(RemoteMemory(contact)) 126 self.set_processlist(RemoteProcessList(contact)) 127 #get information from the contact 128 info=contact.query('overview') 129 lines=re.split("\n",info) 130 for line in lines: 131 #processor? 132 match=re.match("^processor ([a-z0-9]+)",line) 133 if match: 134 #create the processor and add it to the system 135 self.add_processor(RemoteProcessor(match.group(1),contact)) 136 #filesystem? 137 match=re.match("^filesystem ([a-z0-9]+)",line) 138 if match: 139 #create the filesystem and add it to the system 140 print match.group(1)141 142150 """Represents the uptime of a remote system. 151 """172 173153 """Creates a RemoteUptime instance based on the given 154 RemoteContact. 155 """ 156 Uptime.__init__(self) 157 self._contact=contact 158 self._uptime=0159 162164 info=self._contact.query('uptime') 165 self._uptime=int(info) 166 self.callback().call("uptime.updated",self)167175 """Represents a processor on a remote system. 176 """196 197178 """Creates a remote processor. 179 """ 180 Processor.__init__(self) 181 self._name=name 182 self._dict=dict() 183 self._contact=contact184 187189 info=self._contact.query("processor %s" % self.name()) 190 #load as pickle'd from the string 191 self._dict=cPickle.loads(info) 192 self.callback().call("processor.%s.updated" % self.name(),self)193199 """Represents the physical memory (RAM) of a remote system. 200 """222 223202 """Creates a RemoteMemory instance based on the given 203 RemoteContact. 204 """ 205 Memory.__init__(self) 206 self._dict=dict() 207 self._contact=contact208210 info=self._contact.query('memory') 211 #load as pickle'd from the string 212 self._dict=cPickle.loads(info) 213 self.callback().call("memory.updated",self)214 217225 """Represents the ProcessList of a remote system. 226 """238228 """Creates a RemoteProcessList instance based on the given 229 RemoteContact. 230 """ 231 ProcessList.__init__(self) 232 self._contact=contact233
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Sun May 23 16:15:42 2010 | http://epydoc.sourceforge.net |