Author: justi9
Date: 2007-10-30 13:57:35 -0400 (Tue, 30 Oct 2007)
New Revision: 1184
Added:
mgmt/mint/bin/
mgmt/mint/bin/mint-test
mgmt/mint/python/
mgmt/mint/python/mint/
mgmt/mint/python/mint/__init__.py
mgmt/mint/python/mint/schema.py
mgmt/mint/python/mint/updater.py
Modified:
mgmt/cumin/python/cumin/charts.py
mgmt/cumin/python/cumin/model.py
mgmt/cumin/python/cumin/page.strings
mgmt/cumin/python/cumin/queue.py
mgmt/cumin/python/cumin/queue.strings
mgmt/etc/devel.profile
mgmt/misc/mint-test.py
Log:
Adds a mint-test command, adapted from nuno's management client
script, that updates a model.
Improves the devel environment's support for multiple modules.
Makes the charts use mint model data.
A slight styling fix to radiotabs.
Modified: mgmt/cumin/python/cumin/charts.py
===================================================================
--- mgmt/cumin/python/cumin/charts.py 2007-10-29 21:57:49 UTC (rev 1183)
+++ mgmt/cumin/python/cumin/charts.py 2007-10-30 17:57:35 UTC (rev 1184)
@@ -86,11 +86,13 @@
measures = [queue.get_measurement(x) \
for x in self.measurements.get(session)]
- # XXX only get the max of the values we're going to display
+ values = dict()
+ for m in measures:
+ values[m] = m.get_values(250)
max_value = 0
for m in measures:
- max_value = max(max(m.values), max_value)
+ max_value = max(max(values[m]), max_value)
max_value = max_value * 1.1
max_value = max_value + (100 - max_value % 100)
chart.set_max_value(int(max_value))
@@ -101,7 +103,7 @@
colors = ((1,0,0), (0,0,1), (0,1,0))
for m, c in zip(measures, colors):
- chart.plot_values(m.values, color=c)
+ chart.plot_values(values[m], color=c)
chart.plot_frame()
Modified: mgmt/cumin/python/cumin/model.py
===================================================================
--- mgmt/cumin/python/cumin/model.py 2007-10-29 21:57:49 UTC (rev 1183)
+++ mgmt/cumin/python/cumin/model.py 2007-10-30 17:57:35 UTC (rev 1184)
@@ -316,7 +316,7 @@
self.categories = ()
self.title = None
self.__value = None
- self.values = list()
+ self.__values = list()
self.class_ = class_
self.highlow = False
@@ -328,10 +328,10 @@
def add_value(self, value):
self.__value = value
- self.values.append(value)
+ self.__values.append(value)
- if len(self.values) > 1000:
- del self.values[0]
+ if len(self.__values) > 1000:
+ del self.__values[0]
if self.highlow:
if self.__high == None or self.__low == None:
@@ -346,11 +346,21 @@
def get_value(self):
if self.class_:
- stats = self.class_.select()[1]
- return getattr(stats, self.name, None)
+ try:
+ stats = self.class_.select().orderBy("recTime").reversed()[0]
+ return getattr(stats, self.name, None)
+ except IndexError:
+ pass
else:
return self.__value
+ def get_values(self, limit=100):
+ if self.class_:
+ stats = self.class_.select().orderBy("recTime").reversed()
+ return [getattr(x, self.name) for x in stats[:limit + 1]]
+ else:
+ return self.__values
+
def get_high(self):
return self.__high
Modified: mgmt/cumin/python/cumin/page.strings
===================================================================
--- mgmt/cumin/python/cumin/page.strings 2007-10-29 21:57:49 UTC (rev 1183)
+++ mgmt/cumin/python/cumin/page.strings 2007-10-30 17:57:35 UTC (rev 1184)
@@ -360,7 +360,7 @@
ul.radiotabs {
list-style: none;
- margin: 0.25em 0 1em 0;
+ margin: 0 0 1em 0;
padding: 0;
}
Modified: mgmt/cumin/python/cumin/queue.py
===================================================================
--- mgmt/cumin/python/cumin/queue.py 2007-10-29 21:57:49 UTC (rev 1183)
+++ mgmt/cumin/python/cumin/queue.py 2007-10-30 17:57:35 UTC (rev 1184)
@@ -355,10 +355,6 @@
self.add_tab(self.StatisticsCurrent(app, "current"))
self.add_tab(self.StatisticsHistory(app, "history"))
- def render_something(self, session, queue):
- statses = MgmtQueueStats.select()
- stats = statses[0]
-
def render_title(self, session, queue):
return "Statistics"
Modified: mgmt/cumin/python/cumin/queue.strings
===================================================================
--- mgmt/cumin/python/cumin/queue.strings 2007-10-29 21:57:49 UTC (rev 1183)
+++ mgmt/cumin/python/cumin/queue.strings 2007-10-30 17:57:35 UTC (rev 1184)
@@ -185,7 +185,6 @@
</script>
[QueueStatistics.html]
-<p>{something}</p>
<ul class="radiotabs tabs">{tabs}</ul>
<div class="radiotabs mode">{mode}</div>
Modified: mgmt/etc/devel.profile
===================================================================
--- mgmt/etc/devel.profile 2007-10-29 21:57:49 UTC (rev 1183)
+++ mgmt/etc/devel.profile 2007-10-30 17:57:35 UTC (rev 1184)
@@ -2,10 +2,21 @@
export DEVEL_HOME="$PWD"
fi
-export CUMIN_HOME="$DEVEL_HOME"/cumin-test-0
+export DEVEL_MODULES="mint cumin"
export DEVEL_ORIGINAL_PYTHONPATH="$PYTHONPATH"
-export
PYTHONPATH="$CUMIN_HOME"/lib/python:"$DEVEL_HOME"/lib/python:"$HOME"/lib/python:"$PYTHONPATH"
+PYTHONPATH="$DEVEL_HOME"/lib/python:"$HOME"/lib/python:"$DEVEL_ORIGINAL_PYTHONPATH"
+for module in $DEVEL_MODULES; do
+
PYTHONPATH="$DEVEL_HOME"/"$module"/python:"$PYTHONPATH"
+done
+export PYTHONPATH
export DEVEL_ORIGINAL_PATH="$PATH"
-export PATH="$CUMIN_HOME"/bin:"$DEVEL_HOME"/bin:"$PATH"
+PATH="$DEVEL_ORIGINAL_PATH"
+for module in $DEVEL_MODULES; do
+ PATH="$DEVEL_HOME"/"$module"/bin:"$PATH"
+done
+export PATH
+
+# cumin test instance
+export CUMIN_HOME="$DEVEL_HOME"/cumin-test-0
Added: mgmt/mint/bin/mint-test
===================================================================
--- mgmt/mint/bin/mint-test (rev 0)
+++ mgmt/mint/bin/mint-test 2007-10-30 17:57:35 UTC (rev 1184)
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+
+import sys
+
+def usage():
+ print "Usage: mint-test DATABASE-URI BROKER-ADDRESS"
+ print "Example: mint-test postgresql://who@where/dbname example.com:10001"
+ sys.exit(1)
+
+from sqlobject import *
+
+try:
+ connuri = sys.argv[1]
+ conn = connectionForURI(connuri)
+ sqlhub.processConnection = conn
+except IndexError:
+ usage()
+
+from mint import *
+from mint.updater import *
+from qpid.management import ManagedBroker
+
+def do_main(dburi, brokerhost, brokerport):
+ model = MintModel(dburi)
+ model.init()
+
+ broker = ManagedBroker(host=brokerhost, port=brokerport)
+
+ updater = MintUpdater(model, broker)
+ updater.start()
+
+def main():
+ if len(sys.argv) != 3:
+ usage()
+
+ dburi, brokeraddr = sys.argv[1:]
+ brokerhost, brokerport = brokeraddr.split(":")
+
+ try:
+ do_main(dburi, brokerhost, int(brokerport))
+ except KeyboardInterrupt:
+ pass
+
+if __name__ == "__main__":
+ main()
Property changes on: mgmt/mint/bin/mint-test
___________________________________________________________________
Name: svn:executable
+ *
Added: mgmt/mint/python/mint/__init__.py
===================================================================
--- mgmt/mint/python/mint/__init__.py (rev 0)
+++ mgmt/mint/python/mint/__init__.py 2007-10-30 17:57:35 UTC (rev 1184)
@@ -0,0 +1,10 @@
+from sqlobject import *
+
+from schema import *
+
+class MintModel(object):
+ def __init__(self, dburi):
+ self.dburi = dburi
+
+ def init(self):
+ pass
Added: mgmt/mint/python/mint/schema.py
===================================================================
--- mgmt/mint/python/mint/schema.py (rev 0)
+++ mgmt/mint/python/mint/schema.py 2007-10-30 17:57:35 UTC (rev 1184)
@@ -0,0 +1,127 @@
+from sqlobject import *
+
+class MgmtServer(SQLObject):
+ class sqlmeta:
+ fromDatabase = True
+ def joinCluster():
+ pass
+
+ def leaveCluster():
+ pass
+
+
+class MgmtServerStats(SQLObject):
+ class sqlmeta:
+ fromDatabase = True
+
+class MgmtVhost(SQLObject):
+ class sqlmeta:
+ fromDatabase = True
+
+class MgmtVhostStats(SQLObject):
+ class sqlmeta:
+ fromDatabase = True
+
+class MgmtQueue(SQLObject):
+ class sqlmeta:
+ fromDatabase = True
+ def purge():
+ """Discard all messages on queue"""
+ pass
+
+ def increaseDiskSize():
+ """Increase number of disk pages allocated for this
queue"""
+ pass
+
+
+class MgmtQueueStats(SQLObject):
+ class sqlmeta:
+ fromDatabase = True
+
+class MgmtExchange(SQLObject):
+ class sqlmeta:
+ fromDatabase = True
+
+class MgmtExchangeStats(SQLObject):
+ class sqlmeta:
+ fromDatabase = True
+
+class MgmtBinding(SQLObject):
+ class sqlmeta:
+ fromDatabase = True
+
+class MgmtBindingStats(SQLObject):
+ class sqlmeta:
+ fromDatabase = True
+
+class MgmtClient(SQLObject):
+ class sqlmeta:
+ fromDatabase = True
+ def close():
+ pass
+
+ def detach():
+ pass
+
+
+class MgmtClientStats(SQLObject):
+ class sqlmeta:
+ fromDatabase = True
+
+class MgmtSession(SQLObject):
+ class sqlmeta:
+ fromDatabase = True
+ def solicitAck():
+ pass
+
+ def detach():
+ pass
+
+ def resetLifespan():
+ pass
+
+ def close():
+ pass
+
+
+class MgmtSessionStats(SQLObject):
+ class sqlmeta:
+ fromDatabase = True
+
+class MgmtDestination(SQLObject):
+ class sqlmeta:
+ fromDatabase = True
+ def throttle():
+ """Apply extra rate limiting to destination: 0 = Normal, 10 =
Maximum"""
+ pass
+
+ def stop():
+ pass
+
+ def start():
+ pass
+
+
+class MgmtDestinationStats(SQLObject):
+ class sqlmeta:
+ fromDatabase = True
+
+class MgmtProducer(SQLObject):
+ class sqlmeta:
+ fromDatabase = True
+
+class MgmtProducerStats(SQLObject):
+ class sqlmeta:
+ fromDatabase = True
+
+class MgmtConsumer(SQLObject):
+ class sqlmeta:
+ fromDatabase = True
+ def close():
+ pass
+
+
+class MgmtConsumerStats(SQLObject):
+ class sqlmeta:
+ fromDatabase = True
+
Added: mgmt/mint/python/mint/updater.py
===================================================================
--- mgmt/mint/python/mint/updater.py (rev 0)
+++ mgmt/mint/python/mint/updater.py 2007-10-30 17:57:35 UTC (rev 1184)
@@ -0,0 +1,57 @@
+from time import sleep
+from datetime import datetime
+
+from schema import *
+
+class MintUpdater(object):
+ def __init__(self, model, broker):
+ self.model = model
+ self.broker = broker
+
+ self.broker.configListener("XXXcontext", configCallback)
+ self.broker.instrumentationListener("XXXcontext", instCallback)
+
+ def start(self):
+ self.broker.start()
+
+ while True:
+ sleep(1)
+
+def getQueueByName(name, create=False):
+ try:
+ queues = MgmtQueue.selectBy(name=name)[:1]
+ queue = queues[0]
+ except IndexError:
+ if (create): queue = MgmtQueue()
+ return queue
+
+def configCallback(broker, oid, list, timestamps):
+ print "broker=" + broker
+ if oid == 4:
+ print list
+ d = dict(list)
+ queue = getQueueByName(d["name"], True)
+ queue.set(**d)
+ recOn = datetime.fromtimestamp(timestamps[0]/1000000000)
+ createdOn = datetime.fromtimestamp(timestamps[1]/1000000000)
+ queue.set(recTime=recOn,creationTime=createdOn)
+ print queue.id
+ print " -> " + d["name"]
+ return queue
+
+def instCallback(broker, oid, list, timestamps):
+ print "broker=" + broker
+ if oid == 4:
+ print list
+ d = dict(list)
+ queue = getQueueByName(d.pop("name"))
+ d["mgmtQueue"] = queue.id
+ recOn = datetime.fromtimestamp(timestamps[0]/1000000000)
+ queueStats = MgmtQueueStats()
+ queueStats.set(recTime=recOn)
+ queueStats.set(**d)
+ if (timestamps[2] != 0):
+ deletedOn = datetime.fromtimestamp(timestamps[2]/1000000000)
+ queue.set(deletionTime=deletedOn)
+ print queue.id
+ return queueStats
Modified: mgmt/misc/mint-test.py
===================================================================
--- mgmt/misc/mint-test.py 2007-10-29 21:57:49 UTC (rev 1183)
+++ mgmt/misc/mint-test.py 2007-10-30 17:57:35 UTC (rev 1184)
@@ -1,33 +1,44 @@
#!/usr/bin/env python
from qpid.management import ManagedBroker
+from schema import *
from time import sleep
-from schema import *
from datetime import *
from sqlobject import *
-conn = connectionForURI("postgresql://jross@localhost/mint")
+conn_uri = "postgresql://jross@localhost/mint"
+conn = connectionForURI(conn_uri)
sqlhub.processConnection = conn
-def configElement(broker, oid, list, timestamps):
+broker_address = "dhcp83-108.boston.redhat.com:10001"
+
+def getQueueByName(name, create=False):
+ try:
+ queues = MgmtQueue.selectBy(name=name)[:1]
+ queue = queues[0]
+ except IndexError:
+ if (create): queue = MgmtQueue()
+ return queue
+
+def configCallback(broker, oid, list, timestamps):
+ print "broker=" + broker
if oid == 4:
print list
-
- queue = MgmtQueue()
d = dict(list)
+ queue = getQueueByName(d["name"], True)
queue.set(**d)
recOn = datetime.fromtimestamp(timestamps[0]/1000000000)
createdOn = datetime.fromtimestamp(timestamps[1]/1000000000)
queue.set(recTime=recOn,creationTime=createdOn)
print queue.id
print " -> " + d["name"]
+ return queue
-def instElement(broker, oid, list, timestamps):
+def instCallback(broker, oid, list, timestamps):
+ print "broker=" + broker
if oid == 4:
print list
d = dict(list)
- queues = MgmtQueue.selectBy(name=d["name"])[:1]
- del d["name"]
- queue = queues[0]
+ queue = getQueueByName(d.pop("name"))
d["mgmtQueue"] = queue.id
recOn = datetime.fromtimestamp(timestamps[0]/1000000000)
queueStats = MgmtQueueStats()
@@ -37,16 +48,15 @@
deletedOn = datetime.fromtimestamp(timestamps[2]/1000000000)
queue.set(deletionTime=deletedOn)
print queue.id
-# print " -> " + d["name"]
+ return queueStats
-target1 = ManagedBroker (host="dhcp83-108.boston.redhat.com", port=10001)
-target1.configListener("172.16.83.108:10001", configElement)
-target1.instrumentationListener ("172.16.83.108:10001", instElement)
+host, port = broker_address.split(":")
+target1 = ManagedBroker(host=host, port=int(port))
+target1.configListener(broker_address, configCallback)
+target1.instrumentationListener(broker_address, instCallback)
target1.start ()
while 1:
sleep (1)
-
-