Browse files

Playing about with supporting tabular data

But it's just too fucking complicated, given up for now
  • Loading branch information...
1 parent aa1f9cf commit 56d033961d00ce08eac493a9d382812fc354d33c Graham Tackley committed Apr 4, 2011
View
1 .gitignore
@@ -8,6 +8,7 @@ project/boot/
# my log directory
log/
+logs/
# don't commit the intellij stuff, run "sbt idea" to generate
*.ipr
View
9 sbt
@@ -5,9 +5,16 @@
# and
# http://code.google.com/p/simple-build-tool/wiki/GeneralizedLauncher#Configuration
java -Xmx512M -XX:MaxPermSize=250m \
- -Dhttp.proxyHost=devscreen.gudev.gnl -Dhttp.proxyPort=3128 \
+ -XX:+UseConcMarkSweepGC \
+ -XX:+CMSClassUnloadingEnabled \
+ -XX:+UseCompressedOops \
-Dzabbix.server=gnm40833.int.gnl \
-Dzabbix.server.port=10051 \
-Dzabbix.hostname=gnm40836 \
-Dzabbix.appname=sbt \
-jar `dirname $0`/sbt-launch-0.7.4.jar @sbt.scalasources.boot.properties "$@"
+
+
+# -XX:+PrintGCDetails \
+# -XX:+PrintGCDateStamps \
+
View
50 src/main/scala/zapush/MBean.scala
@@ -18,6 +18,26 @@ case class MBeanProperty(bean: MBean, propertyName: String, attributeType: Strin
def value = bean(propertyName)
}
+case class MBeanValue(rawValue: AnyRef) {
+ override def toString = rawValue match {
+ case a: Array[_] => a.mkString(", ")
+ case t: TabularData => "[tabular data not yet supported by zapush]"
+ case m: Map[_, _] => m.mkString("map: ", ", ", "end")
+ case other => other.toString
+ }
+
+ def child(childName: String): MBeanValue = {
+ rawValue match {
+ case c: CompositeData => MBeanValue(c.get(childName))
+ case t: TabularData => error("tabular data not yet supported by zapush")
+// t.values
+// .collect { case cd: CompositeData if cd.get("key") == childName => MBeanValue(cd.get("value")) }
+// .headOption.getOrElse(error("failed to parse tabular data for " + childName + " from " + rawValue))
+ case _ => error("could not find child named " + childName + " from " + rawValue)
+ }
+ }
+}
+
class MBean(val name: ObjectName) {
lazy val mbeanServer = ManagementFactory.getPlatformMBeanServer
@@ -56,30 +76,24 @@ class MBean(val name: ObjectName) {
def apply(attributeName: String) = {
- def getValue(attributeName: String): Any =
- attributeName.split('.').toList match {
- case Nil => error("bad attibute name: " + attributeName)
- case value :: Nil =>
- mbeanServer.getAttribute(name, value)
- case compositeName :: rest =>
- parseComposite(rest, mbeanServer.getAttribute(name, compositeName).asInstanceOf[CompositeData])
+ def parseComposite(path: List[String], data: MBeanValue): MBeanValue =
+ path match {
+ case Nil => error("erm something went wong")
+ case key :: Nil => data.child(key)
+ case key :: rest => parseComposite(rest, data.child(key))
}
- def parseComposite(path: List[String], data: CompositeData): Any = path match {
- case Nil => error("erm something went wong")
- case key :: Nil => data.get(key)
- case key :: rest => parseComposite(rest, data.get(key).asInstanceOf[CompositeData])
- }
-
- getValue(attributeName) match {
- case a: Array[_] => a.mkString(", ")
- case m: Map[_, _] => m.mkString("map: ", ", ", "end")
- case m: java.util.Map[_, _] => m.mkString("java map: ", ", ", "end")
- case other => other.toString
+ attributeName.split('.').toList match {
+ case Nil => error("bad attibute name: " + attributeName)
+ case value :: Nil =>
+ MBeanValue(mbeanServer.getAttribute(name, value))
+ case compositeName :: rest =>
+ parseComposite(rest, MBeanValue(mbeanServer.getAttribute(name, compositeName)))
}
}
+
}
View
2 src/main/scala/zapush/Sender.scala
@@ -48,7 +48,7 @@ object Sender extends Loggable {
property <- mbean.properties
value <- tryo { mbean(property.propertyName) }
} yield {
- Data(Config.zabbixHostname, property.zabbixName, value)
+ Data(Config.zabbixHostname, property.zabbixName, value.toString)
}
}
View
2 src/main/scala/zapush/snippet/ShowMBeans.scala
@@ -8,6 +8,6 @@ class ShowMBeans {
def render = "li" #> MBeans.all.flatMap(_.properties).sortBy(_.zabbixName).map { prop =>
".prop-name *" #> prop.zabbixName &
".prop-type" #> prop.attributeType &
- ".prop-value" #> tryo { Text(prop.value) }.openOr(<strong>error!</strong>)
+ ".prop-value" #> tryo { Text(prop.value.toString) }.openOr(<strong>error!</strong>)
}
}
View
23 src/test/scala/zapush/MBeanTest.scala
@@ -9,7 +9,7 @@ import javax.management.openmbean._
class MBeanTest extends FlatSpec with ShouldMatchers {
val mbeanServer = ManagementFactory.getPlatformMBeanServer
- val testObject = new ObjectName("java.lang:type=MemoryPool,name=PS Perm Gen")
+ val testObject = new ObjectName("java.lang:type=MemoryPool,name=CMS Perm Gen")
val bean = new MBean(testObject)
"mbean wrapper" should "read composite properties" in {
@@ -22,4 +22,25 @@ class MBeanTest extends FlatSpec with ShouldMatchers {
println("bean usage max = " + bean("Usage.max"))
}
+// it should "be able to read some crazy properties" in {
+// val gc = new ObjectName("java.lang:type=GarbageCollector,name=ConcurrentMarkSweep")
+// val gcBean = new MBean(gc)
+//
+// val actualValue = gcBean("LastGcInfo.memoryUsageAfterGc.CMS Old Gen.init")
+// println("actual value = " + actualValue.toString)
+//
+// }
+//
+//
+// it should "return crazy properties in the list of properties" in {
+// val gc = new ObjectName("java.lang:type=GarbageCollector,name=ConcurrentMarkSweep")
+// val gcBean = new MBean(gc)
+//
+// (gcBean.properties).find(_.propertyName == "LastGcInfo.memoryUsageAfterGc.CMS Old Gen.init") should be ('defined)
+//
+//
+// }
+
+
+
}

0 comments on commit 56d0339

Please sign in to comment.