1
0
Fork 0

- Add init() methods to each plugin

- Call plugin init() methods during tuned's init()
- Add support for command line parameters
  o -c conffile|--config==conffile to specify the location of the config file
  o -d to start tuned as a daemon (instead of as normal app)
- Readded the debug output in case tuned isn't started as as daemon
- Fixed initialization of max transfer values for net tuning plugin
This commit is contained in:
Philip Knirsch 2009-02-25 11:28:06 +01:00
parent e393e728bc
commit 1fa5722844
7 changed files with 68 additions and 19 deletions

View file

@ -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 = {}

View file

@ -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 = {}

34
tuned
View file

@ -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()

View file

@ -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

View file

@ -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()

View file

@ -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()

View file

@ -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()