Skip to content

Expression Language

Kristoffer Erlandsson edited this page Feb 25, 2016 · 3 revisions

jmxtrans-agent uses an expression language based on property placeholders (e.g. "${graphite.host:2003}", ObjectName properties (e.g. "%name%") and basic functions (e.g. "#canonical_hostname#").

Property placeholders

jmxtrans-agent supports property placeholders with the ${prop-name[:default-value]} syntax.

The default-value is optional. An exception is raised if no default value is defined and the property placeholder is not found.

Properties are looked-up in the following order:

  1. If specified by the system property -Djmxtrans.agent.properties.file=<fileOrUrl>, properties are looked up in the specified properties file. The properties file follows the format of files that java.util.Properties can load. (supported from version 1.2.3)
  2. JVM system properties (System.getProperty("graphite.host"))
  3. JVM environment variables (System.getenv("graphite.host"))
  4. JVM environment variables after a "to-upper-case + dot-to-underscore" transformation (System.getenv("GRAPHITE_HOST"))

JMX ObjectName properties based variables

Query resultAlias support usage of ObjectName properties with the %myproperty% syntax.

ObjectName property values are escaped with the following rules:

  • If a value of a property is escaped with double quotes (see ObjectName.quote(value)), the double quotes are removed from the jmxtrans-agent resolved value (e.g. if "mydatasource" -> mydatasource).
  • Non alpha-numeric letters are replaced by underscore: '_' (e.g. jdbc/my-datasource -> jdbc_my_datasource).

Sample of ObjectName property usage in query resultAlias

Configuration:

<query objectName="Catalina:type=DataSource,context=/,host=localhost,class=javax.sql.DataSource,name=*" 
   attribute="numActive" resultAlias="tomcat.datasource.%name%.numActive" />

Will match ObjectName:

Catalina:type=DataSource,context=/,host=localhost,class=javax.sql.DataSource,name="jdbc/my-datasource"

And resultAlias will be:

tomcat.datasource.jdbc_my_datasource.numActive

Functions

jmxtrans-agent supports basic functions with "#" based expressions like "#my_function#".

List of out-of-the-box functions:

Function Description
#hostname# Value of InetAddress.getLocalHost().getHostName()
#reversed_hostname# Same as #hostname# in the reverse order (e.g. server1.mycompany.com -> com.mycompany.server1)
#escaped_hostname# same as #hostname# with "." replaced by "_" (e.g. server1.mycompany.com -> server1_mycompany_com)
#canonical_hostname# Value of InetAddress.getLocalHost().getCanonicalHostName()
#reversed_canonical_hostname# same as #canonical_hostname# in the reverse order (e.g. server1.mycompany.com -> com.mycompany.server1)
#escaped_canonical_hostname# same as #canonical_hostname# with "." replaced by "_" (e.g. server1.mycompany.com -> server1_mycompany_com)
#hostaddress# Value of InetAddress.getLocalHost().getHostAddress()
#escaped_hostaddress# same as #hostaddress# with "." replaced by "_"