summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip Knirsch <pknirsch@hamburg.stuttgart.redhat.com>2009-02-02 12:33:41 +0100
committerPhilip Knirsch <pknirsch@hamburg.stuttgart.redhat.com>2009-02-02 12:33:41 +0100
commit796739577264cd143b50dc7cd5302cd8ab49ca08 (patch)
tree04e4d293faa45c88fe4a88e8717ff160574b43c0
downloadtuned-796739577264cd143b50dc7cd5302cd8ab49ca08.zip
tuned-796739577264cd143b50dc7cd5302cd8ab49ca08.tar.gz
tuned-796739577264cd143b50dc7cd5302cd8ab49ca08.tar.xz
- Initial stuff
-rw-r--r--git-daemon-export-ok0
-rw-r--r--monitorplugins/__init__.py0
-rw-r--r--monitorplugins/disk.py52
-rw-r--r--monitorplugins/network.py52
-rwxr-xr-xtuned7
-rw-r--r--tuned.py38
-rw-r--r--tuningplugins/.disk.py.swpbin0 -> 12288 bytes
-rw-r--r--tuningplugins/__init__.py0
-rw-r--r--tuningplugins/disk.py28
9 files changed, 177 insertions, 0 deletions
diff --git a/git-daemon-export-ok b/git-daemon-export-ok
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/git-daemon-export-ok
diff --git a/monitorplugins/__init__.py b/monitorplugins/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/monitorplugins/__init__.py
diff --git a/monitorplugins/disk.py b/monitorplugins/disk.py
new file mode 100644
index 0000000..cde18d1
--- /dev/null
+++ b/monitorplugins/disk.py
@@ -0,0 +1,52 @@
+import os
+
+class DiskMonitor:
+ def __init__(self):
+ self.devices = {}
+ dnames = os.listdir("/sys/block/")
+ for d in dnames:
+ try:
+ v = open("/sys/block/"+d+"/device/vendor").read().strip()
+ except:
+ v = None
+ if v != "ATA" and v != "SCSI":
+ continue
+ self.devices[d] = {}
+ self.devices[d]["new"] = ['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
+ 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
+
+
+ def __calcdiff__(self, dev):
+ l = []
+ for i in xrange(len(self.devices[dev]["old"])):
+ l.append(int(self.devices[dev]["new"][i]) - int(self.devices[dev]["old"][i]))
+ return l
+
+ def __updateStat__(self, dev):
+ l = open("/sys/block/"+dev+"/stat", "r").read()
+ self.devices[dev]["old"] = self.devices[dev]["new"]
+ self.devices[dev]["new"] = l.split()
+ l = self.__calcdiff__(dev)
+ for i in xrange(len(l)):
+ if l[i] > self.devices[dev]["max"][i]:
+ self.devices[dev]["max"][i] = l[i]
+
+ def __update__(self):
+ for dev in self.devices.keys():
+ self.__updateStat__(dev)
+ self.devices[dev]["diff"] = self.__calcdiff__(dev)
+
+ def getLoad(self):
+ self.__update__()
+ ret = {}
+ ret["DISK"] = {}
+ for dev in self.devices.keys():
+ ret["DISK"][dev] = {}
+ ret["DISK"][dev]["READ"] = float(self.devices[dev]["diff"][1]) / float(self.devices[dev]["max"][1])
+ ret["DISK"][dev]["WRITE"] = float(self.devices[dev]["diff"][5]) / float(self.devices[dev]["max"][5])
+ return ret
+
+_plugin = DiskMonitor()
diff --git a/monitorplugins/network.py b/monitorplugins/network.py
new file mode 100644
index 0000000..cde18d1
--- /dev/null
+++ b/monitorplugins/network.py
@@ -0,0 +1,52 @@
+import os
+
+class DiskMonitor:
+ def __init__(self):
+ self.devices = {}
+ dnames = os.listdir("/sys/block/")
+ for d in dnames:
+ try:
+ v = open("/sys/block/"+d+"/device/vendor").read().strip()
+ except:
+ v = None
+ if v != "ATA" and v != "SCSI":
+ continue
+ self.devices[d] = {}
+ self.devices[d]["new"] = ['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
+ 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
+
+
+ def __calcdiff__(self, dev):
+ l = []
+ for i in xrange(len(self.devices[dev]["old"])):
+ l.append(int(self.devices[dev]["new"][i]) - int(self.devices[dev]["old"][i]))
+ return l
+
+ def __updateStat__(self, dev):
+ l = open("/sys/block/"+dev+"/stat", "r").read()
+ self.devices[dev]["old"] = self.devices[dev]["new"]
+ self.devices[dev]["new"] = l.split()
+ l = self.__calcdiff__(dev)
+ for i in xrange(len(l)):
+ if l[i] > self.devices[dev]["max"][i]:
+ self.devices[dev]["max"][i] = l[i]
+
+ def __update__(self):
+ for dev in self.devices.keys():
+ self.__updateStat__(dev)
+ self.devices[dev]["diff"] = self.__calcdiff__(dev)
+
+ def getLoad(self):
+ self.__update__()
+ ret = {}
+ ret["DISK"] = {}
+ for dev in self.devices.keys():
+ ret["DISK"][dev] = {}
+ ret["DISK"][dev]["READ"] = float(self.devices[dev]["diff"][1]) / float(self.devices[dev]["max"][1])
+ ret["DISK"][dev]["WRITE"] = float(self.devices[dev]["diff"][5]) / float(self.devices[dev]["max"][5])
+ return ret
+
+_plugin = DiskMonitor()
diff --git a/tuned b/tuned
new file mode 100755
index 0000000..190b8e8
--- /dev/null
+++ b/tuned
@@ -0,0 +1,7 @@
+#!/usr/bin/python
+
+from tuned import tuned
+
+tuned.init(".")
+tuned.run()
+tuned.cleanup()
diff --git a/tuned.py b/tuned.py
new file mode 100644
index 0000000..35604c5
--- /dev/null
+++ b/tuned.py
@@ -0,0 +1,38 @@
+import time,os,locale
+
+class Tuned:
+ def __init__(self):
+ self.mp = []
+ self.tp = []
+
+ def __initplugins__(self, path, module, store):
+ _files = map(lambda v: v[:-3], filter(lambda v: v[-3:] == ".py" and \
+ v != "__init__.py" and \
+ v[0] != '.', \
+ os.listdir(path+"/"+module)))
+ locale.setlocale(locale.LC_ALL, "C")
+ _files.sort()
+ locale.setlocale(locale.LC_ALL, "")
+ for _i in _files:
+ _cmd = "from %s.%s import _plugin" % (module, _i)
+ exec _cmd
+ store.append(_plugin)
+
+ def init(self, path):
+ self.__initplugins__(path, "monitorplugins", self.mp)
+ self.__initplugins__(path, "tuningplugins", self.tp)
+
+ def run(self):
+ 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)
+
+ def cleanup(self):
+ print("Cleanup...")
+
+tuned = Tuned()
diff --git a/tuningplugins/.disk.py.swp b/tuningplugins/.disk.py.swp
new file mode 100644
index 0000000..1e7ee23
--- /dev/null
+++ b/tuningplugins/.disk.py.swp
Binary files differ
diff --git a/tuningplugins/__init__.py b/tuningplugins/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tuningplugins/__init__.py
diff --git a/tuningplugins/disk.py b/tuningplugins/disk.py
new file mode 100644
index 0000000..32f6256
--- /dev/null
+++ b/tuningplugins/disk.py
@@ -0,0 +1,28 @@
+import os
+
+class DiskTuning:
+ def __init__(self):
+ self.devidle = {}
+
+ def __updateIdle__(self, dev, devload):
+ for type in ("READ", "WRITE"):
+ if devload[type] == 0.0:
+ idle = self.devidle.setdefault(dev, {})
+ idle.setdefault(type, 0)
+ idle[type] += 1
+ else:
+ idle = self.devidle.setdefault(dev, {})
+ idle.setdefault(type, 0)
+ idle[type] = 0
+
+ def setTuning(self, load):
+ disks = load.setdefault("DISK", {})
+ for dev in disks.keys():
+ devload = disks[dev]
+ self.__updateIdle__(dev, devload)
+ if self.devidle[dev]["READ"] == 30 and self.devidle[dev]["WRITE"] == 30:
+ os.system("hdparm -S5 /dev/"+dev)
+ os.system("hdparm -B1 /dev/"+dev)
+ print(load, self.devidle)
+
+_plugin = DiskTuning()