Merge lp:~doctormo/processmonitor/project-fixes into lp:~tjk/processmonitor/trunk

Proposed by Martin Owens
Status: Merged
Merged at revision: 14
Proposed branch: lp:~doctormo/processmonitor/project-fixes
Merge into: lp:~tjk/processmonitor/trunk
Diff against target: 291 lines (+61/-153)
6 files modified
.bzrignore (+1/-0)
bin/iomonitor-daemon (+42/-9)
lib/IoIndicator/base.py (+0/-1)
lib/IoIndicator/daemon.py (+18/-6)
lib/IoIndicator/lib.py (+0/-111)
tests/execute_service.py (+0/-26)
To merge this branch: bzr merge lp:~doctormo/processmonitor/project-fixes
Reviewer Review Type Date Requested Status
Tim Konick Pending
Review via email: mp+144425@code.launchpad.net

Description of the change

Fixes for the project

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file '.bzrignore'
--- .bzrignore 1970-01-01 00:00:00 +0000
+++ .bzrignore 2013-01-23 02:40:26 +0000
@@ -0,0 +1,1 @@
1tests/service.log
02
=== renamed file 'bin/bin' => 'bin/iomonitor-daemon' (properties changed: -x to +x)
--- bin/bin 2013-01-16 01:28:11 +0000
+++ bin/iomonitor-daemon 2013-01-23 02:40:26 +0000
@@ -1,13 +1,46 @@
1#!/usr/bin/env python1#!/usr/bin/env python
22#
3import lib3# Copyright 2013 Martin Owens <doctormo@gmail.com>
44#
5def main():5# This program is free software: you can redistribute it and/or modify
6 iom = lib.IoMonitor6# it under the terms of the GNU General Public License as published by
7 iom()7# the Free Software Foundation, either version 3 of the License, or
8 gobject.MainLoop().run()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"""
19Daemon program to load io-indicator dbus service.
20"""
21
22import os
23import sys
24import logging
25
26if os.path.exists('lib/IoIndicator'):
27 sys.path.insert(1, 'lib')
28elif os.path.exists('../lib/IoIndicator'):
29 sys.path.insert(1, '../lib')
30
31from gi.repository import GObject
32from IoIndicator import __version__
33from IoIndicator.base import mainloop, PROJECT_NAME, SERVICE_ADDRESS
34from IoIndicator.daemon import IoMonitor
935
10if __name__ == '__main__':36if __name__ == '__main__':
11 with daemon.DaemonContext():37 logging.info("Loading %s (%s)" % (PROJECT_NAME, __version__))
12 main()38 try:
39 with IoMonitor():
40 logging.info("Started Service: %s" % SERVICE_ADDRESS)
41 GObject.MainLoop().run()
42 except KeyboardInterrupt:
43 logging.info("User Interputed")
44 logging.debug("Exiting %s" % PROJECT_NAME)
45
1346
1447
=== modified file 'lib/IoIndicator/base.py'
--- lib/IoIndicator/base.py 2012-12-15 23:00:23 +0000
+++ lib/IoIndicator/base.py 2013-01-23 02:40:26 +0000
@@ -27,7 +27,6 @@
27from IoIndicator import __stage__, __appname__, __testing__27from IoIndicator import __stage__, __appname__, __testing__
28from gi.repository import GObject28from gi.repository import GObject
2929
30
31PROJECT_NAME = "IO Indicator"30PROJECT_NAME = "IO Indicator"
32PROJECT_PKG = __appname__31PROJECT_PKG = __appname__
33PROJECT_TEST = __testing__32PROJECT_TEST = __testing__
3433
=== modified file 'lib/IoIndicator/daemon.py'
--- lib/IoIndicator/daemon.py 2013-01-16 20:41:55 +0000
+++ lib/IoIndicator/daemon.py 2013-01-23 02:40:26 +0000
@@ -1,5 +1,6 @@
1#1#
2# Copyright 2011 Martin Owens <doctormo@gmail.com>2# Copyright 2013 Timothy Konick <konick781@gmail.com>
3# Martin Owens <doctormo@gmail.com>
3#4#
4# This program is free software: you can redistribute it and/or modify5# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by6# it under the terms of the GNU General Public License as published by
@@ -14,10 +15,14 @@
14# You should have received a copy of the GNU General Public License15# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>16# along with this program. If not, see <http://www.gnu.org/licenses/>
16#17#
17"""Tim to write docs here"""18"""Daemon classes for running the dbus service.
19
20Used for tests and the real thing.
21"""
1822
19import os23import os
20import sys24import sys
25import socket
21import logging26import logging
2227
23from gi.repository import GObject28from gi.repository import GObject
@@ -25,8 +30,6 @@
25from IoIndicator import __testing__30from IoIndicator import __testing__
26from IoIndicator.base import *31from IoIndicator.base import *
2732
28from lib import *
29
30def claim_busname():33def claim_busname():
31 """Claim the STATUS_ADDRESS as it's own personal daemon provider."""34 """Claim the STATUS_ADDRESS as it's own personal daemon provider."""
32 # Must happen after DBusGMainLoop(...)35 # Must happen after DBusGMainLoop(...)
@@ -34,9 +37,10 @@
34 return BusName(SOA, SESSION_BUS)37 return BusName(SOA, SESSION_BUS)
3538
3639
37class Monitor(DBusObject):40class IoMonitor(DBusObject):
38 """Docs here"""41 """Input/Output monitor, providing data on dbus"""
39 def __init__(self):42 def __init__(self):
43 self.bus = claim_busname()
40 DBusObject.__init__(self, 'Monitor')44 DBusObject.__init__(self, 'Monitor')
41 self.conn = socket.socket(socket.AF_NETLINK, socket.SOCK_RAW, 16)45 self.conn = socket.socket(socket.AF_NETLINK, socket.SOCK_RAW, 16)
42 self.conn.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 65536)46 self.conn.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 65536)
@@ -44,6 +48,14 @@
44 self.conn.bind((0,0))48 self.conn.bind((0,0))
45 self.pid, self.grp = self.conn.getsockname()49 self.pid, self.grp = self.conn.getsockname()
4650
51 def __enter__(self):
52 """Any setup code here"""
53 pass
54
55 def __exit__(self, *args):
56 """Any cleanup code here"""
57 pass
58
47 @dbus_method(SOA, in_signature='', out_signature='s')59 @dbus_method(SOA, in_signature='', out_signature='s')
48 def TestMethod(self):60 def TestMethod(self):
49 return "Yes"61 return "Yes"
5062
=== removed file 'lib/IoIndicator/lib.py'
--- lib/IoIndicator/lib.py 2013-01-16 01:30:56 +0000
+++ lib/IoIndicator/lib.py 1970-01-01 00:00:00 +0000
@@ -1,111 +0,0 @@
1import os
2import dbus
3import struct
4import socket
5import daemon
6import psutil # maybe not...
7import gobject
8import dbus.service
9from dbus.mainloop.glib import DBusGMainLoop
10
11
12class IoMonitor(dbus.service.Object):
13
14 def __init__(self):
15 name = dbus.service.BusName('org.iomonitor', dbus.SystemBus(mainloop=DBusGMainLoop()))
16 dbus.service.Object.__init__(self, name, '/org/iomonitor')
17 self.conn = socket.socket(socket.AF_NETLINK, socket.SOCK_RAW, 16)
18 self.conn.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 65536)
19 self.conn.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 65536)
20 self.conn.bind((0,0))
21 self.pid, self.grp = self.conn.getsockname()
22
23 def grab_data(self):
24 aps = []
25 ps = [int(i) for i in os.listdir('/proc') if i.isdigit()]
26 for pid in ps:
27 front = struct.pack('HH', 1, 0)
28 back = struct.pack('I', pid)
29 back_hdr = struct.pack('HH', len(back) + 4, 1)
30 back = back_hdr + back
31 load = b''.join(front+back)
32 hdr = struct.pack('IHHII', len(load) + 16, 23, 1, 1, self.pid)
33 self.conn.send(hdr+load)
34 t, (x, y) = self.conn.recvfrom(16384)
35 t = t[20:]
36 a = {}
37 while 3 not in a.keys():
38 while len(t):
39 atl, aty = struct.unpack('HH', t[:4])
40 a[aty] = t[4:atl]
41 t = t[atl:]
42 t = a[aty]
43 try:
44 aps.append(['PID:', pid, 'READ:', struct.unpack('Q', t[248:256])[0],
45 'WRITE:', struct.unpack('Q', t[256:264])[0]])
46 except struct.error:
47 pass
48 return aps
49
50 @dbus.service.method('org.iomonitor', out_signature='as')
51 def process_list(self):
52 pidnamelst = []
53 prclst = [pid for pid in os.listdir('/proc') if pid.isdigit()]
54 for pid in prclst:
55 if os.path.isfile('/proc/%s/stat' % pid):
56 with open('/proc/%s/stat' % pid, 'r+') as f:
57 name = f.readline()
58 f.close()
59 name = [j for j in name.split(' ') if '(' in j]
60 pidnamelst.append(name[0][1:-1])
61 return pidnamelst
62
63 @dbus.service.method('org.iomonitor', out_signature='aas')
64 def allprocess_stats(self):
65 aps = self.grab_data()
66 return aps
67
68 @dbus.service.method('org.iomonitor', in_signature='s', out_signature='as')
69 def process_stats(self, pid):
70 aps = self.grab_data()
71 for i in aps:
72 if pid == str(i[1]):
73 return i
74 return ['No i/o']
75
76 @dbus.service.method('org.iomonitor', out_signature='as')
77 def process_swap(self, pid):
78 # check if this best place to monitor?
79 with open('/proc/swaps') as f:
80 data = f.readlines()
81 f.close()
82 if len(data) > 1:
83 return data
84 return ['No swap']
85
86 @dbus.service.method('org.iomonitor', out_signature='s')
87 def memory(self):
88 # work out psutil
89 return str(psutil.avail_phymem())
90
91 @dbus.service.method('org.iomonitor', in_signature='s', out_signature='as')
92 def diskstats(self, disk):
93 with open('/sys/block/sda/%s/stat' % disk, 'r') as f:
94 data = f.readlines()
95 f.close()
96 data = [i for i in data[0].split(' ') if len(i) > 0]
97 return ['read ' + data[0], 'write ' + data[4]]
98
99 @dbus.service.method('org.iomonitor', out_signature='as')
100 def disklist(self):
101 # /sys/block/dev/...just sda/hda -- or all partitions??
102 dl = os.listdir('/sys/block')
103 return dl
104
105 @dbus.service.method('org.iomonitor', out_signature='as')
106 def deviceinfo(self):
107 with open('/proc/scsi/scsi', 'r') as f:
108 devinfo = f.readlines()
109 f.close()
110 return devinfo
111
1120
=== added symlink 'tests/execute-script.py'
=== target is u'../bin/iomonitor-daemon'
=== removed file 'tests/execute_service.py'
--- tests/execute_service.py 2012-12-15 23:00:23 +0000
+++ tests/execute_service.py 1970-01-01 00:00:00 +0000
@@ -1,26 +0,0 @@
1#!/usr/bin/python
2
3import os, sys
4
5os.environ['test_suite'] = 'True'
6sys.path.insert(1, '../lib')
7sys.path.insert(1, 'lib')
8
9import dbus
10import logging
11
12from gi.repository import GObject
13from IoIndicator import daemon, __version__
14
15logging.debug("Starting IoIndicator Test Service, %s" % __version__)
16
17if __name__ == '__main__':
18 BUS_NAME = daemon.claim_busname()
19 mainloop = GObject.MainLoop()
20 try:
21 monitor = daemon.Monitor()
22 mainloop.run()
23 except KeyboardInterrupt:
24 logging.error("User Interputed")
25 logging.debug("Exiting Test Service Daemon")
26

Subscribers

People subscribed via source and target branches

to all changes: