Class ResultNameStrategy

java.lang.Object
org.jmxtrans.embedded.ResultNameStrategy

public class ResultNameStrategy
extends Object
Build a QueryResult.name from a collected metric (QueryAttribute, 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() TODO
#reversed_hostname# reversed localhost - hostname InetAddress.getHostName()
#escaped_hostname# localhost - hostname InetAddress.getHostName() with '.' replaced by '_' TODO
#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() TODO
#escaped_hostname# localhost - hostaddress InetAddress.getHostAddress() with '.' replaced by '_' TODO
Author:
Cyrille Le Clerc
  • Field Details

  • Constructor Details

    • ResultNameStrategy

      public ResultNameStrategy()
  • Method Details

    • getResultName

      public String getResultName​(Query query, ObjectName objectName, QueryAttribute queryAttribute)
    • getResultName

      public String getResultName​(Query query, ObjectName objectName, QueryAttribute queryAttribute, String key)
    • _getResultName

      protected StringBuilder _getResultName​(Query query, ObjectName objectName, QueryAttribute queryAttribute)
    • resolveExpression

      public String resolveExpression​(String expression)
      Replace all the '#' based keywords (e.g. #hostname#) by their value.
      Parameters:
      expression - the expression to resolve (e.g. "servers.#hostname#.")
      Returns:
      the resolved expression (e.g. "servers.tomcat5")
    • resolveExpression

      protected String resolveExpression​(String expression, ObjectName exactObjectName)
    • escapeObjectName

      protected String escapeObjectName​(ObjectName objectName)
      Transforms an ObjectName into a plain String only composed of (a-z, A-Z, '_'). '_' is the escape char for not compliant chars.
    • registerExpressionEvaluator

      public void registerExpressionEvaluator​(String expression, Callable<String> evaluator)
      Registers an expression evaluator with a static value.
    • registerExpressionEvaluator

      public void registerExpressionEvaluator​(String expression, String value)
      Registers an expression evaluator with a static value.
    • getExpressionEvaluators

      @Nonnull public Map<String,​Callable<String>> getExpressionEvaluators()
    • builder

      public static ResultNameStrategy.Builder builder()