Class SensorKey

java.lang.Object
io.strimzi.kafka.oauth.metrics.SensorKey

public class SensorKey extends Object
The SensorKey represents and uniquely identifies the Kafka Metrics API Sensor, which represents a set of metrics that are updated at the same time.

These metrics are:
  • count
  • totalTimeMs
  • minTimeMs
  • maxTimeMs
  • avgTimeMs
The SensorKey is composed of the name and the attributes.

The following attributes are required: "context", "kind", "host", "path".

As a convention, only use alphanumeric characters and an underscore (_) in the name and the attribute keys. Note, that names and attributes become part of the JMX ObjectName when metrics are plugged into the JMX MBeanServer. Attribute values containing some other characters (like ':', or '/') will become quoted when converted to JMX ObjectNames.

Kafka Sensors are created on demand and cached by the value of the id, which is a string representation of this SensorKey. Each Sensor is exported as a single managed bean with a unique JMX ObjectName.

Some examples of SensorKeys and how they map to JMX ObjectNames:
  • Name: http_requests
  • Attributes: context=PUBLIC, kind=jwks, host=localhost:443, path=/certs, outcome=success, status=200
  • JMX ObjectName: strimzi.oauth:type=http_requests,context=PUBLIC,kind=jwks,host="localhost:443",path="/certs",outcome=success,status=200
  • Name: validation_requests
  • Attributes: context=e8af84dd, kind=introspect, host=localhost:443, path=/introspect, mechanism=PLAIN, outcome=error, error_type=other
  • JMX ObjectName: strimzi.oauth:type=validation_requests,context=e8af84dd,kind=introspect,host="localhost:443",path="/introspect",mechanism=PLAIN,outcome=error,error_type=other
  • Method Details

    • of

      public static SensorKey of(String name, Map<String,String> attributes)
      Create a new instance of SensorKey from name and a map of attributes
      Parameters:
      name - The metric name
      attributes - The map of attributes
      Returns:
      The new instance of SensorKey
    • of

      public static SensorKey of(String name, String... attributes)
      Create a new instance of SensorKey from name and attributes
      Parameters:
      name - The metric name
      attributes - The varargs list of attributes as name1, value1 ... nameN, valueN
      Returns:
      The new instance of SensorKey
    • getId

      public String getId()
      Get a String representation of this SensorKey that uniquely identifies it. This is simply a concatenation of the name and the string value of the attributes map.
      Returns:
      A sensor id
    • getName

      public String getName()
      Get the name of this SensorKey
      Returns:
      The name as a String
    • getAttributes

      public Map<String,String> getAttributes()
      Get the attributes of this SensorKey as a Map
      Returns:
      The attributes as a Map
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object