Skip to content

Expression Language

Philipp Knobel edited this page Mar 17, 2017 · 5 revisions

EmbeddedJmxTrans 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

EmbeddedJmxTrans 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.

Environment variables are looked-up in the following order:

  1. JVM system properties (System.getProperty("graphite.host"))
  2. JVM environment variables (System.getenv("graphite.host"))
  3. 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 EmbeddedJmxTrans resolved value (e.g. if "mydatasource" -> mydatasource).
  • Non alpha-numeric letters are replaced by underscore: '_' (e.g. jdbc/my-datasource -> jdbc_my_datasource).
  • It is possible to not escape dots '.' in ObjectNames by configuring resultNameStrategy to not escape dots

Sample of ObjectName property usage in query resultAlias

Configuration:

{
   "objectName": "Catalina:type=Resource,resourcetype=Context,path=/,host=localhost,class=javax.sql.DataSource,name=*",
   "resultAlias": "tomcat.datasource.%host%.%path%.%name%",
   "attribute": "numActive"
}

Will match ObjectName:

Catalina:type=Resource,resourcetype=Context,path=/,host=localhost,class=javax.sql.DataSource,name="jdbc/my-datasource"

And resultAlias will be:

tomcat.datasource.localhost._.jdbc_my_datasource

Example configuration having dots in ObjectNames not replaced

{
      "objectName": "org:name=org.jmxtrans.embedded.*",
      "resultAlias": "%name%",
      "attribute": "Value",
      "resultNameStrategy": {
        "replaceDotsInObjectName": true
      }
}

This will match all Objects with ObjectName starting with org.jmxtrans.embedded.

An example resultAlias will look like:

org.jmxtrans.embedded.nested.metric

While in the past it would have been:

org_jmxtrans_embedded_nested_metric

Functions

EmbeddedJmxTrans 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 "_"