summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--monitorplugins/disk.py7
-rw-r--r--monitorplugins/net.py12
-rwxr-xr-xtuned34
-rwxr-xr-xtuned.initscript2
-rw-r--r--tuned.py22
-rw-r--r--tuningplugins/disk.py5
-rw-r--r--tuningplugins/net.py5
7 files changed, 68 insertions, 19 deletions
diff --git a/monitorplugins/disk.py b/monitorplugins/disk.py
index f2844e8..16262ab 100644
--- a/monitorplugins/disk.py
+++ b/monitorplugins/disk.py
@@ -34,7 +34,7 @@ class DiskMonitor:
self.devices[d]["max"] = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
self.__updateStat__(d)
self.devices[d]["max"] = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
- #print self.devices
+ print self.devices
def __calcdiff__(self, dev):
@@ -56,7 +56,10 @@ class DiskMonitor:
for dev in self.devices.keys():
self.__updateStat__(dev)
self.devices[dev]["diff"] = self.__calcdiff__(dev)
-
+
+ def init(self, config):
+ self.config = config
+
def getLoad(self):
self.__update__()
ret = {}
diff --git a/monitorplugins/net.py b/monitorplugins/net.py
index 32042d8..caf8307 100644
--- a/monitorplugins/net.py
+++ b/monitorplugins/net.py
@@ -30,10 +30,11 @@ class NetMonitor:
continue
self.devices[d] = {}
self.devices[d]["new"] = ['0', '0', '0', '0']
+ # Assume 1gbit interfaces for now. FIXME: Need clean way to figure out max interface speed
self.devices[d]["max"] = [70*1024*1024, 1, 70*1024*1024, 1]
self.__updateStat__(d)
self.devices[d]["max"] = [70*1024*1024, 1, 70*1024*1024, 1]
- #print self.devices
+ print self.devices
def __calcdiff__(self, dev):
l = []
@@ -60,7 +61,14 @@ class NetMonitor:
for dev in self.devices.keys():
self.__updateStat__(dev)
self.devices[dev]["diff"] = self.__calcdiff__(dev)
-
+
+ def init(self, config):
+ self.config = config
+ interval = self.config.getint("main", "interval")
+ # Assume 1gbit interfaces for now. FIXME: Need clean way to figure out max interface speed
+ for d in self.devices.keys():
+ self.devices[d]["max"] = [70*1024*1024*interval, 1, 70*1024*1024*interval, 1]
+
def getLoad(self):
self.__update__()
ret = {}
diff --git a/tuned b/tuned
index a1b6cab..126200c 100755
--- a/tuned
+++ b/tuned
@@ -20,9 +20,12 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
-import sys, os.path
+import sys, os.path, getopt
-if __name__ == "__main__":
+def usage():
+ print "Usage: tuned [-d|--daemon] [-c conffile|--config=conffile]"
+
+def daemonize():
try:
pid = os.fork()
if pid > 0:
@@ -42,12 +45,37 @@ if __name__ == "__main__":
sys.exit(1)
sys.stdout = sys.stderr = open("/dev/null", 'a+')
+
+if __name__ == "__main__":
+ try:
+ opts, args = getopt.getopt(sys.argv[1:], "dc:", ["daemon", "config="])
+ except getopt.error, e:
+ print >>sys.stderr, ("Error parsing command-line arguments: %s", e)
+ usage()
+ sys.exit(1)
+
+ if len(args) > 0:
+ print >>sys.stderr, ("Too many arguments.")
+ usage()
+ sys.exit(1)
+
+ daemon = False
+ cfgfile = "/etc/tuned.conf"
+ for (opt, val) in opts:
+ if opt in ['-d', "--daemon"]:
+ daemon = True
+ elif opt in ['-c', "--config"]:
+ cfgfile = val
+
+ if daemon:
+ daemonize()
+
TUNEDDIR="/usr/share/tuned"
if not TUNEDDIR in sys.path:
sys.path.append(TUNEDDIR)
from tuned import tuned
- tuned.init(TUNEDDIR)
+ tuned.init(TUNEDDIR, cfgfile)
tuned.run()
tuned.cleanup()
diff --git a/tuned.initscript b/tuned.initscript
index dad1405..5465a0d 100755
--- a/tuned.initscript
+++ b/tuned.initscript
@@ -32,7 +32,7 @@ start () {
[ -x $exec ] || exit 5
[ -f $config ] || exit 6
echo -n $"Starting $prog: "
- daemon $exec
+ daemon $exec -d -c $config
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
diff --git a/tuned.py b/tuned.py
index 6328aa3..9d56f85 100644
--- a/tuned.py
+++ b/tuned.py
@@ -2,10 +2,9 @@ import time,os,locale,ConfigParser
class Tuned:
def __init__(self):
+ self.interval = 10
self.mp = []
self.tp = []
- self.config = ConfigParser.ConfigParser()
- self.config.read('/etc/tuned.conf')
def __initplugins__(self, path, module, store):
_files = map(lambda v: v[:-3], filter(lambda v: v[-3:] == ".py" and \
@@ -20,26 +19,31 @@ class Tuned:
exec _cmd
store.append(_plugin)
- def init(self, path):
+ def init(self, path, cfgfile):
+ self.config = ConfigParser.ConfigParser()
+ self.config.read(cfgfile)
+ if config.has_option("main", "interval"):
+ self.interval = config.getint("main", "interval")
+ else:
+ config.set("main", "interval", self.interval)
self.__initplugins__(path, "monitorplugins", self.mp)
self.__initplugins__(path, "tuningplugins", self.tp)
for p in self.mp:
- p.config = self.config
+ p.init(self.config)
for p in self.tp:
- p.config = self.config
+ p.init(self.config)
def run(self):
- #print("Running...")
+ print("Running...")
while True:
lh = {}
for p in self.mp:
lh.update(p.getLoad())
for p in self.tp:
p.setTuning(lh)
- time.sleep(10)
+ time.sleep(self.interval)
def cleanup(self):
- pass
- #print("Cleanup...")
+ print("Cleanup...")
tuned = Tuned()
diff --git a/tuningplugins/disk.py b/tuningplugins/disk.py
index 9d7d848..6624890 100644
--- a/tuningplugins/disk.py
+++ b/tuningplugins/disk.py
@@ -33,6 +33,9 @@ class DiskTuning:
idle.setdefault(type, 0)
idle[type] = 0
+ def init(self, config):
+ self.config = config
+
def setTuning(self, load):
disks = load.setdefault("DISK", {})
for dev in disks.keys():
@@ -44,6 +47,6 @@ class DiskTuning:
if self.devidle[dev]["LEVEL"] > 0 and (self.devidle[dev]["READ"] == 0 or self.devidle[dev]["WRITE"] == 0):
self.devidle[dev]["LEVEL"] = 0
os.system("hdparm -S255 -B127 /dev/"+dev)
- #print(load, self.devidle)
+ print(load, self.devidle)
_plugin = DiskTuning()
diff --git a/tuningplugins/net.py b/tuningplugins/net.py
index 3983b8d..687d306 100644
--- a/tuningplugins/net.py
+++ b/tuningplugins/net.py
@@ -33,6 +33,9 @@ class NetTuning:
idle.setdefault(type, 0)
idle[type] = 0
+ def init(self, config):
+ self.config = config
+
def setTuning(self, load):
disks = load.setdefault("NET", {})
for dev in disks.keys():
@@ -44,6 +47,6 @@ class NetTuning:
if self.devidle[dev]["LEVEL"] > 0 and (self.devidle[dev]["READ"] == 0 or self.devidle[dev]["WRITE"] == 0):
self.devidle[dev]["LEVEL"] = 0
os.system("ethtool -s "+dev+" advertise 0x03F")
- #print(load, self.devidle)
+ print(load, self.devidle)
_plugin = NetTuning()