Problem:
You would like to use Custom Format Masks in JMX for output formatting
Possible solution(s):
You can reformat the output value from Mbeans in JMX by way of the Custom Format Masks. This option leverages on Java's built-in string manipulation and functions. You will need to build a Java code and compile it before it becomes useful in JMX.
Documentation Link: Custom Format Masks
Here's an example to render numerical field values into a floating point and output the value with two decimal places. Here's how to do it:
You will need to build this Java program on your system, so having a Java SDK package is necessary. Copy the following code and save it as "geneosFormat.java" on your system:
package com.itrsgroup.jmx.masks;
public class geneosFormat implements Mask
{
public String get(Object data, String[] args) throws MaskException {
String r;
try {
r = String.format(args[0], Float.parseFloat((String) data));
} catch (Exception e) {
throw new MaskException("Error!");
}
return r;
}
}
Once saved as a java file, you will need to compile it using the java compiler (from the Java SDK) and use the following command:
javac -d . -classpath ../geneos-plugins.jar geneosFormat.java*kindly ensure the directory structures and location of the geneos-plugins.jar from where you execute this command; the geneos-plugins.jar is bundled with the Netprobe.
Once compiled, it will create a hierarchy in the current direct, e.g. com/itrsgroup/jmx/masks, and generate a 'geneosFormat.class' file in there. Now build a .jar file using
jar cvf custom-masks.jar com/you can delete the com/ directory once you have the jar file.
rm -r com/You can now place the 'custom-masks.jar' in the same directory as the geneos-plugins.jar file (usually in the netprobe binaries home directory). Restart your netprobe once you've done this.
You can now use the custom mask you've created on your JMX plugin. You can use the format mask "geneosFormat(%.2fMB)" in order to convert the output value with only 2 floating point positions.
The sample XML for the plugin is as follows:
<sampler name="JMX Sampler">
<plugin>
<jmx-server>
<connection>
<generic>
<serviceURL>
<data>service:jmx:rmi:///jndi/rmi://</data>
<var ref="JMX"></var>
<data>/jmxrmi</data>
</serviceURL>
</generic>
</connection>
<aliases>
<alias>
<name>$1</name>
<value>
<data>java.lang:type=Memory</data>
</value>
<attributePath>
<data>HeapMemoryUsage</data>
</attributePath>
</alias>
</aliases>
<columns>
<column>
<label>Committed in MB</label>
<rowTemplate>
<data>$1.committed / 1000000</data>
</rowTemplate>
<mask>
<data>geneosFormat(%.2fMB)</data>
</mask>
</column>
<column>
<label>Used in MB</label>
<rowTemplate>
<data>$1.used / 1000000</data>
</rowTemplate>
<mask>
<data>geneosFormat(%.2fMB)</data>
</mask>
</column>
<column>
<label>% Used</label>
<rowTemplate>
<data> 100 * $1.used / $1.committed</data>
</rowTemplate>
<mask>
<data>geneosFormat(%.2f'%')</data>
</mask>
</column>
</columns>
<idAttributes></idAttributes>
</jmx-server>
</plugin>
</sampler>
If you need further help:
-
Please contact our support team via the chat service box on any of our websites or raise a support request.
-
Make sure you provide us with:
- Background of the issue or request.
- Use cases, requirements, business impact, etc.
- Encountered error messages.
- Log files or diagnostic files.
- Screenshots.
- And other important information relevant to your inquiry.
Comments
0 comments
Please sign in to leave a comment.