summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 658b873)
raw | patch | inline | side by side (parent: 658b873)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sun, 2 Aug 2009 15:26:05 +0000 (17:26 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sun, 2 Aug 2009 15:26:05 +0000 (17:26 +0200) |
This can be used to specify so called "properties" to include in the
plugin instance.
plugin instance.
bindings/java/org/collectd/java/GenericJMXConfMBean.java | patch | blob | history |
diff --git a/bindings/java/org/collectd/java/GenericJMXConfMBean.java b/bindings/java/org/collectd/java/GenericJMXConfMBean.java
index 1b4d9ccf99086f825726fa8478d78338ae1fab55..27e9e329891bd1bb02e76624aad064edbf90a6e5 100644 (file)
{
private String _name; /* name by which this mapping is referenced */
private ObjectName _obj_name;
{
private String _name; /* name by which this mapping is referenced */
private ObjectName _obj_name;
- private String _instance;
+ private String _instance_prefix;
+ private List<String> _instance_from;
private List<GenericJMXConfValue> _values;
private String getConfigString (OConfigItem ci) /* {{{ */
private List<GenericJMXConfValue> _values;
private String getConfigString (OConfigItem ci) /* {{{ */
return (v.getString ());
} /* }}} String getConfigString */
return (v.getString ());
} /* }}} String getConfigString */
+ private String join (String separator, List<String> list) /* {{{ */
+ {
+ StringBuffer sb;
+
+ sb = new StringBuffer ();
+
+ for (int i = 0; i < list.size (); i++)
+ {
+ if (i > 0)
+ sb.append ("-");
+ sb.append (list.get (i));
+ }
+
+ return (sb.toString ());
+ } /* }}} String join */
+
/*
* <MBean "alias name">
/*
* <MBean "alias name">
- * Instance "foobar"
* ObjectName "object name"
* ObjectName "object name"
+ * InstancePrefix "foobar"
+ * InstanceFrom "name"
* <Value />
* <Value />
* :
* <Value />
* <Value />
* :
+ "MBean blocks need exactly one string argument."));
this._obj_name = null;
+ "MBean blocks need exactly one string argument."));
this._obj_name = null;
+ this._instance_prefix = null;
+ this._instance_from = new ArrayList<String> ();
this._values = new ArrayList<GenericJMXConfValue> ();
children = ci.getChildren ();
this._values = new ArrayList<GenericJMXConfValue> ();
children = ci.getChildren ();
Collectd.logDebug ("GenericJMXConfMBean: child.getKey () = "
+ child.getKey ());
Collectd.logDebug ("GenericJMXConfMBean: child.getKey () = "
+ child.getKey ());
- if (child.getKey ().equalsIgnoreCase ("Instance"))
- {
- String tmp = getConfigString (child);
- if (tmp != null)
- this._instance = tmp;
- }
- else if (child.getKey ().equalsIgnoreCase ("ObjectName"))
+ if (child.getKey ().equalsIgnoreCase ("ObjectName"))
{
String tmp = getConfigString (child);
if (tmp == null)
{
String tmp = getConfigString (child);
if (tmp == null)
+ tmp, e));
}
}
+ tmp, e));
}
}
+ else if (child.getKey ().equalsIgnoreCase ("InstancePrefix"))
+ {
+ String tmp = getConfigString (child);
+ if (tmp != null)
+ this._instance_prefix = tmp;
+ }
+ else if (child.getKey ().equalsIgnoreCase ("InstanceFrom"))
+ {
+ String tmp = getConfigString (child);
+ if (tmp != null)
+ this._instance_from.add (tmp);
+ }
else if (child.getKey ().equalsIgnoreCase ("Value"))
{
GenericJMXConfValue cv;
else if (child.getKey ().equalsIgnoreCase ("Value"))
{
GenericJMXConfValue cv;
iter = names.iterator ();
while (iter.hasNext ())
{
iter = names.iterator ();
while (iter.hasNext ())
{
- ObjectName objName;
- PluginData pd_tmp;
+ ObjectName objName;
+ PluginData pd_tmp;
+ List<String> instanceList;
+ String instance;
- objName = iter.next ();
- pd_tmp = new PluginData (pd);
+ objName = iter.next ();
+ pd_tmp = new PluginData (pd);
+ instanceList = new ArrayList<String> ();
Collectd.logDebug ("GenericJMXConfMBean: objName = "
+ objName.toString ());
Collectd.logDebug ("GenericJMXConfMBean: objName = "
+ objName.toString ());
- pd_tmp.setPluginInstance ((this._instance != null) ? this._instance : "");
+ for (int i = 0; i < this._instance_from.size (); i++)
+ {
+ String propertyName;
+ String propertyValue;
+
+ propertyName = this._instance_from.get (i);
+ propertyValue = objName.getKeyProperty (propertyName);
+ if (propertyValue == null)
+ {
+ Collectd.logError ("GenericJMXConfMBean: "
+ + "No such property in object name: " + propertyName);
+ }
+ else
+ {
+ instanceList.add (propertyValue);
+ }
+ }
+
+ if (this._instance_prefix != null)
+ instance = new String (this._instance_prefix
+ + join ("-", instanceList));
+ else
+ instance = join ("-", instanceList);
+ pd_tmp.setPluginInstance (instance);
+
+ Collectd.logDebug ("GenericJMXConfMBean: instance = " + instance);
for (int i = 0; i < this._values.size (); i++)
this._values.get (i).query (conn, objName, pd_tmp);
for (int i = 0; i < this._values.size (); i++)
this._values.get (i).query (conn, objName, pd_tmp);