Merge lp:~jinfo/powernap/trunk into lp:powernap

Proposed by Andres Rodriguez
Status: Merged
Merged at revision: 229
Proposed branch: lp:~jinfo/powernap/trunk
Merge into: lp:powernap
Diff against target: 127 lines (+89/-1)
3 files modified
config (+17/-0)
powernap/monitors/DiskMonitor.py (+67/-0)
powernap/powernap.py (+5/-1)
To merge this branch: bzr merge lp:~jinfo/powernap/trunk
Reviewer Review Type Date Requested Status
Andres Rodriguez Pending
Review via email: mp+58372@code.launchpad.net
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
1=== modified file 'config'
2--- config 2011-01-31 23:24:48 +0000
3+++ config 2011-04-19 18:22:24 +0000
4@@ -165,3 +165,20 @@
5 [InputMonitor]
6 keyboard = y
7 mouse = y
8+
9+# The [DiskMonitor] section lists the disk devices for which to track
10+# standby/sleep status. If any of the devices are active/idle the
11+# system will be deemed 'active' and will not powernap. Generally useful
12+# for monitoring data drives (e.g. NAS), but will not typically work to
13+# monitor the root drive. Note also that this plugin only reacts to the
14+# state of the drive and does not modify the behavior of the drive
15+# directly. Therefore it only makes sense to monitor a drive that has
16+# already been configured to standby or sleep.
17+# To disable checking specific drives, set them to "n" or "no",
18+# or simply comment them.
19+# Examples:
20+# sda = y
21+# sdb = n
22+[DiskMonitor]
23+#sda = y
24+
25
26=== added file 'powernap/monitors/DiskMonitor.py'
27--- powernap/monitors/DiskMonitor.py 1970-01-01 00:00:00 +0000
28+++ powernap/monitors/DiskMonitor.py 2011-04-19 18:22:24 +0000
29@@ -0,0 +1,67 @@
30+# powernapd plugin - Monitors disk power state
31+#
32+# Copyright (C) 2010, 2011 Canonical Ltd.
33+#
34+# Authors: Jim Heck <pinball.rules@gmail.com>
35+#
36+# This program is free software: you can redistribute it and/or modify
37+# it under the terms of the GNU General Public License as published by
38+# the Free Software Foundation, version 3 of the License.
39+#
40+# This program is distributed in the hope that it will be useful,
41+# but WITHOUT ANY WARRANTY; without even the implied warranty of
42+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43+# GNU General Public License for more details.
44+#
45+# You should have received a copy of the GNU General Public License
46+# along with this program. If not, see <http://www.gnu.org/licenses/>.
47+import re, commands
48+from logging import error, debug, info, warn
49+
50+# Monitor plugin
51+# looks for disks that are active/idle. Useful for sleeping only when
52+# specified disks are in standby
53+
54+class DiskMonitor ():
55+
56+ # Initialise
57+ def __init__(self, config):
58+ self._type = config['monitor']
59+ self._name = config['name']
60+ self._regex_state = re.compile(r"^\s+drive\s+state\s+is:\s+(\S+)")
61+ self._regex_not_found = re.compile(r"^.*No\s+such\s+file")
62+ self._absent_seconds = 0
63+
64+ def start(self):
65+ pass
66+
67+ def active(self):
68+ if self.is_disk_active():
69+ return True
70+ return False
71+
72+ # Check for inactive drive by looking explicitly for drive state of
73+ # 'standby' or 'sleeping'. Assume 'active/idle', except in case
74+ # where fuction returns 'No such file' error (e.g. unknown drive)
75+ def is_disk_active(self):
76+ hdparm = commands.getoutput("hdparm -C /dev/%s" % self._name).splitlines()
77+ is_active = True
78+ for line in hdparm:
79+ if self._regex_not_found.match(line):
80+ #warn(" Disk monitor: disk %s not found, ignoring" % self._name)
81+ return False
82+ if self._regex_state.match(line):
83+ state = self._regex_state.search(line).group(1)
84+ #debug(" Disk monitor: disk %s in state %s" % (self._name, state))
85+ if state == 'standby' or state == 'sleeping':
86+ is_active = False
87+ if is_active:
88+ return True
89+ return False
90+
91+
92+# ###########################################################################
93+# Editor directives
94+# ###########################################################################
95+
96+# vim:sts=4:ts=4:sw=4:et
97
98=== modified file 'powernap/powernap.py'
99--- powernap/powernap.py 2011-03-14 21:24:39 +0000
100+++ powernap/powernap.py 2011-04-19 18:22:24 +0000
101@@ -19,7 +19,7 @@
102 # along with this program. If not, see <http://www.gnu.org/licenses/>.
103
104 import ConfigParser, sys, re, os
105-from monitors import ProcessMonitor, LoadMonitor, InputMonitor, TCPMonitor, UDPMonitor, IOMonitor, WoLMonitor, ConsoleMonitor
106+from monitors import ProcessMonitor, LoadMonitor, InputMonitor, TCPMonitor, UDPMonitor, IOMonitor, WoLMonitor, ConsoleMonitor, DiskMonitor
107
108
109 class PowerNap:
110@@ -133,6 +133,8 @@
111 self.MONITORS.append({"monitor":monitor, "name":items[0], "port":eval(items[1]), "absent":self.ABSENT_SECONDS})
112 if monitor == "WoLMonitor":
113 self.MONITORS.append({"monitor":monitor, "name":items[0], "port":eval(items[1]), "absent":self.ABSENT_SECONDS})
114+ if monitor == "DiskMonitor" and (items[1] == "y" or items[1] == "yes"):
115+ self.MONITORS.append({"monitor":monitor, "name":items[0], "absent":self.ABSENT_SECONDS})
116
117 def get_monitors(self):
118 monitor = []
119@@ -153,6 +155,8 @@
120 p = IOMonitor.IOMonitor(config)
121 if config["monitor"] == "TCPMonitor":
122 p = TCPMonitor.TCPMonitor(config)
123+ if config["monitor"] == "DiskMonitor":
124+ p = DiskMonitor.DiskMonitor(config)
125 monitor.append(p)
126
127 return monitor

Subscribers

People subscribed via source and target branches