Class ResultNameStrategyImpl

java.lang.Object
org.jmxtrans.agent.ResultNameStrategyImpl
All Implemented Interfaces:
ResultNameStrategy

public class ResultNameStrategyImpl
extends java.lang.Object
implements ResultNameStrategy
Build a QueryResult.name from a collected metric (Query). Build name must be escaped to be compatible with all OutputWriter. The approach is to escape non alpha-numeric chars. Expressions support '#' based keywords (e.g. #hostname#) and with '%' based variables mapped to objectname properties. Supported '#' based 'functions':
Function Description Sample
#hostname# localhost - hostname InetAddress.getHostName()
#reversed_hostname# reversed localhost - hostname InetAddress.getHostName()
#escaped_hostname# localhost - hostname InetAddress.getHostName() with '.' replaced by '_'
#canonical_hostname# localhost - canonical hostname InetAddress.getCanonicalHostName() server1.ecommerce.mycompany.com
#reversed_canonical_hostname# reversed localhost - canonical hostname InetAddress.getCanonicalHostName() com.mycompany.ecommerce.server1
#escaped_canonical_hostname# localhost - canonical hostname InetAddress.getCanonicalHostName() with '.' replaced by '_' server1_ecommerce_mycompany_com
#hostaddress# localhost - hostaddress InetAddress.getHostAddress()
#escaped_hostname# localhost - hostaddress InetAddress.getHostAddress() with '.' replaced by '_'
Author:
Cyrille Le Clerc
  • Field Details

    • logger

      protected final Logger logger
  • Constructor Details

    • ResultNameStrategyImpl

      public ResultNameStrategyImpl()
      Create with default expression language engine.
    • ResultNameStrategyImpl

      public ResultNameStrategyImpl​(ExpressionLanguageEngine expressionLanguageEngine)
  • Method Details

    • getResultName

      @Nonnull public java.lang.String getResultName​(@Nonnull Query query, @Nonnull javax.management.ObjectName objectName, @Nonnull java.lang.String attribute, @Nullable java.lang.String compositeDataKey, @Nullable java.lang.Integer position)
      Specified by:
      getResultName in interface ResultNameStrategy
    • escapeObjectName

      protected java.lang.String escapeObjectName​(@Nonnull javax.management.ObjectName objectName)
      Transforms an ObjectName into a plain String only composed of ('a' to 'Z', 'A' to 'Z', '_'). '_' is the escape char for not compliant chars.
    • getExpressionLanguageEngine

      public ExpressionLanguageEngine getExpressionLanguageEngine()
    • setExpressionLanguageEngine

      public void setExpressionLanguageEngine​(ExpressionLanguageEngine expressionLanguageEngine)
    • postConstruct

      public void postConstruct​(@Nonnull java.util.Map<java.lang.String,​java.lang.String> settings)
      Specified by:
      postConstruct in interface ResultNameStrategy