Module aeonics.core

Class Monitor

  • All Implemented Interfaces:
    Exportable, Snapshotable

    public abstract class Monitor
    extends Manager.Type
    This manager can be used to record monitoring information.

    It allows to accumulate values over time, based on a four-level deep hyerarchy. Every time a metric is updated, an individual counter is also incremented. This means that you have two values available: the accumulated total and the count.

    The hyerarchy is usually composed by Entity.category() > Object.getClass() > Entity.id() > metric in order to group the different metrics in a structured fashion. Meanwhile, all hyerarchy levels are plain string and allows for custom values.

    Implementations may choose to have a time window system or else. Implementations should make sure that it can be used in a thread safe way unless it is designed otherwise voluntarily.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String UNSPECIFIED  
    • Constructor Summary

      Constructors 
      Constructor Description
      Monitor()  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract void add​(java.lang.String level1, java.lang.String level2, java.lang.String level3, java.lang.String level4, long value)
      Increments the counter of the provied entity by 1 and the accumulated value by the specified amount.
      void count​(Entity entity)
      Increments the counter of the provided entity by 1.
      void count​(Entity entity, long value)
      Increments the counter of the provided entity by 1 and the accumulated value by the specified amount.
      void count​(Entity entity, java.lang.String metric, long value)
      Increments the counter of the provided entity by 1 and the accumulated value by the specified amount.
      <T extends Entity>
      void
      count​(T entity, java.lang.Class<? super T> groupBy)
      Increments the counter of the provied entity by 1.
      <T extends Entity>
      void
      count​(T entity, java.lang.Class<? super T> groupBy, long value)
      Increments the counter of the provied entity by 1 and the accumulated value by the specified amount.
      <T extends Entity>
      void
      count​(T entity, java.lang.Class<? super T> groupBy, java.lang.String metric, long value)
      Increments the counter of the provied entity by 1 and the accumulated value by the specified amount.
      void countFor​(Entity entity, Entity related)
      Increments the counter of the provied entity by 1 with the last level being the id of the related entity.
      void countFor​(Entity entity, Entity related, long value)
      Increments the counter of the provied entity by 1 and the accumulated value by the specified amount with the last level being the id of the related entity.
      <T extends Entity>
      void
      countFor​(T entity, Entity related, java.lang.Class<? super T> groupBy)
      Increments the counter of the provied entity by 1 with the last level being the id of the related entity.
      <T extends Entity>
      void
      countFor​(T entity, Entity related, java.lang.Class<? super T> groupBy, long value)
      Increments the counter of the provied entity by 1 and the accumulated value by the specified amount with the last level being the id of the related entity.
      static Monitor get()
      Returns the current active instance of this manager type.
      java.lang.Class<? extends Manager.Type> manager()
      Hardcoded manager type
      <T extends Entity>
      Monitor.MonitorTimer
      ms​(T entity)
      Increments the counter of the provied entity by 1 and the accumulated value by the number of elapsed milliseconds.
      <T extends Entity>
      Monitor.MonitorTimer
      ms​(T entity, java.lang.Class<? super T> groupBy)
      Increments the counter of the provied entity by 1 and the accumulated value by the number of elapsed milliseconds.
      <T extends Entity>
      Monitor.MonitorTimer
      ms​(T entity, java.lang.Class<? super T> groupBy, java.lang.String metric)
      Increments the counter of the provied entity by 1 and the accumulated value by the number of elapsed milliseconds.
      <T extends Entity>
      Monitor.MonitorTimer
      ms​(T entity, java.lang.String metric)
      Increments the counter of the provied entity by 1 and the accumulated value by the number of elapsed milliseconds.
      <T extends Entity>
      Monitor.MonitorTimer
      ms​(T entity, java.lang.String groupBy, java.lang.String metric)
      Increments the counter of the provied entity by 1 and the accumulated value by the number of elapsed milliseconds.
      <T extends Entity>
      Monitor.MonitorTimer
      ns​(T entity)
      Increments the counter of the provied entity by 1 and the accumulated value by the number of elapsed nanoseconds.
      <T extends Entity>
      Monitor.MonitorTimer
      ns​(T entity, java.lang.Class<? super T> groupBy)
      Increments the counter of the provied entity by 1 and the accumulated value by the number of elapsed nanoseconds.
      <T extends Entity>
      Monitor.MonitorTimer
      ns​(T entity, java.lang.Class<? super T> groupBy, java.lang.String metric)
      Increments the counter of the provied entity by 1 and the accumulated value by the number of elapsed nanoseconds.
      <T extends Entity>
      Monitor.MonitorTimer
      ns​(T entity, java.lang.String metric)
      Increments the counter of the provied entity by 1 and the accumulated value by the number of elapsed nanoseconds.
      <T extends Entity>
      Monitor.MonitorTimer
      ns​(T entity, java.lang.String groupBy, java.lang.String metric)
      Increments the counter of the provied entity by 1 and the accumulated value by the number of elapsed nanoseconds.
      Data report()
      Returns all counters and accumulated values.
      Data report​(Entity entity)
      Returns counters and accumulated values for all metrics of the given entity.
      abstract Data report​(java.lang.String level1, java.lang.String level2, java.lang.String level3, java.lang.String level4)
      Returns the counter and accumulated value of the specified metric.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Monitor

        public Monitor()
    • Method Detail

      • manager

        public final java.lang.Class<? extends Manager.Type> manager()
        Hardcoded manager type
        Specified by:
        manager in class Manager.Type
        Returns:
        the type of manager
      • get

        public static Monitor get()
        Returns the current active instance of this manager type.
        Returns:
        the current active instance of this manager type
      • count

        public void count​(Entity entity)
        Increments the counter of the provided entity by 1.
        1. Level 1: entity category
        2. Level 2: entity class name
        3. Level 3: entity id
        4. Level 4: "hit"
        • Counter value: +1
        • Accumulated value: 0
        Parameters:
        entity - the target entity
        See Also:
        add(String, String, String, String, long)
      • count

        public void count​(Entity entity,
                          long value)
        Increments the counter of the provided entity by 1 and the accumulated value by the specified amount.
        1. Level 1: entity category
        2. Level 2: entity class name
        3. Level 3: entity id
        4. Level 4: "hit"
        • Counter value: +1
        • Accumulated value: the provided value
        Parameters:
        entity - the target entity
        value - the accumulated value
        See Also:
        add(String, String, String, String, long)
      • count

        public void count​(Entity entity,
                          java.lang.String metric,
                          long value)
        Increments the counter of the provided entity by 1 and the accumulated value by the specified amount.
        1. Level 1: entity category
        2. Level 2: entity class name
        3. Level 3: entity id
        4. Level 4: the specified metric
        • Counter value: +1
        • Accumulated value: the provided value
        Parameters:
        entity - the target entity
        metric - the metric name
        value - the accumulated value
        See Also:
        add(String, String, String, String, long)
      • count

        public <T extends Entity> void count​(T entity,
                                             java.lang.Class<? super T> groupBy)
        Increments the counter of the provied entity by 1.
        1. Level 1: entity category
        2. Level 2: the group by type
        3. Level 3: entity id
        4. Level 4: "hit"
        • Counter value: +1
        • Accumulated value: 0
        Type Parameters:
        T - the entity class type
        Parameters:
        entity - the target entity
        groupBy - a superclass of the entity to group metrics together
        See Also:
        add(String, String, String, String, long)
      • count

        public <T extends Entity> void count​(T entity,
                                             java.lang.Class<? super T> groupBy,
                                             long value)
        Increments the counter of the provied entity by 1 and the accumulated value by the specified amount.
        1. Level 1: entity category
        2. Level 2: the group by type
        3. Level 3: entity id
        4. Level 4: "hit"
        • Counter value: +1
        • Accumulated value: the provided value
        Type Parameters:
        T - the entity class type
        Parameters:
        entity - the target entity
        groupBy - a superclass of the entity to group metrics together
        value - the accumulated value
        See Also:
        add(String, String, String, String, long)
      • count

        public <T extends Entity> void count​(T entity,
                                             java.lang.Class<? super T> groupBy,
                                             java.lang.String metric,
                                             long value)
        Increments the counter of the provied entity by 1 and the accumulated value by the specified amount.
        1. Level 1: entity category
        2. Level 2: the group by type
        3. Level 3: entity id
        4. Level 4: the specified metric
        • Counter value: +1
        • Accumulated value: the provided value
        Type Parameters:
        T - the entity class type
        Parameters:
        entity - the target entity
        groupBy - a superclass of the entity to group metrics together
        metric - the metric name
        value - the accumulated value
        See Also:
        add(String, String, String, String, long)
      • ms

        public <T extends EntityMonitor.MonitorTimer ms​(T entity)
        Increments the counter of the provied entity by 1 and the accumulated value by the number of elapsed milliseconds.

        This method should be used in a try...with statement: try( MonitorTimer ms = Monitor.ms(...) ) { ... }

        1. Level 1: entity category
        2. Level 2: entity class name
        3. Level 3: entity id
        4. Level 4: "ms"
        • Counter value: +1
        • Accumulated value: elapsed milliseconds
        Type Parameters:
        T - the entity type
        Parameters:
        entity - the target entity
        Returns:
        an auto closeable object to be used in a try...with statement
      • ms

        public <T extends EntityMonitor.MonitorTimer ms​(T entity,
                                                          java.lang.String metric)
        Increments the counter of the provied entity by 1 and the accumulated value by the number of elapsed milliseconds.

        This method should be used in a try...with statement: try( MonitorTimer ms = Monitor.ms(...) ) { ... }

        1. Level 1: entity category
        2. Level 2: entity class name
        3. Level 3: entity id
        4. Level 4: the provided metric
        • Counter value: +1
        • Accumulated value: elapsed milliseconds
        Type Parameters:
        T - the entity type
        Parameters:
        entity - the target entity
        metric - the target metric
        Returns:
        an auto closeable object to be used in a try...with statement
      • ms

        public <T extends EntityMonitor.MonitorTimer ms​(T entity,
                                                          java.lang.Class<? super T> groupBy)
        Increments the counter of the provied entity by 1 and the accumulated value by the number of elapsed milliseconds.

        This method should be used in a try...with statement: try( MonitorTimer ms = Monitor.ms(...) ) { ... }

        1. Level 1: entity category
        2. Level 2: the group by type
        3. Level 3: entity id
        4. Level 4: "ms"
        • Counter value: +1
        • Accumulated value: elapsed milliseconds
        Type Parameters:
        T - the entity type
        Parameters:
        entity - the target entity
        groupBy - the group by type
        Returns:
        an auto closeable object to be used in a try...with statement
      • ms

        public <T extends EntityMonitor.MonitorTimer ms​(T entity,
                                                          java.lang.Class<? super T> groupBy,
                                                          java.lang.String metric)
        Increments the counter of the provied entity by 1 and the accumulated value by the number of elapsed milliseconds.

        This method should be used in a try...with statement: try( MonitorTimer ms = Monitor.ms(...) ) { ... }

        1. Level 1: entity category
        2. Level 2: the group by type
        3. Level 3: entity id
        4. Level 4: the provided metric
        • Counter value: +1
        • Accumulated value: elapsed milliseconds
        Type Parameters:
        T - the entity type
        Parameters:
        entity - the target entity
        groupBy - the group by type
        metric - the target metric
        Returns:
        an auto closeable object to be used in a try...with statement
      • ms

        public <T extends EntityMonitor.MonitorTimer ms​(T entity,
                                                          java.lang.String groupBy,
                                                          java.lang.String metric)
        Increments the counter of the provied entity by 1 and the accumulated value by the number of elapsed milliseconds.

        This method should be used in a try...with statement: try( MonitorTimer ms = Monitor.ms(...) ) { ... }

        1. Level 1: entity category
        2. Level 2: the group by string
        3. Level 3: entity id
        4. Level 4: the provided metric
        • Counter value: +1
        • Accumulated value: elapsed milliseconds
        Type Parameters:
        T - the entity type
        Parameters:
        entity - the target entity
        groupBy - the group by string
        metric - the target metric
        Returns:
        an auto closeable object to be used in a try...with statement
      • ns

        public <T extends EntityMonitor.MonitorTimer ns​(T entity)
        Increments the counter of the provied entity by 1 and the accumulated value by the number of elapsed nanoseconds.

        This method should be used in a try...with statement: try( MonitorTimer ns = Monitor.ns(...) ) { ... }

        1. Level 1: entity category
        2. Level 2: entity class name
        3. Level 3: entity id
        4. Level 4: "ns"
        • Counter value: +1
        • Accumulated value: elapsed nanoseconds
        Type Parameters:
        T - the entity type
        Parameters:
        entity - the target entity
        Returns:
        an auto closeable object to be used in a try...with statement
      • ns

        public <T extends EntityMonitor.MonitorTimer ns​(T entity,
                                                          java.lang.String metric)
        Increments the counter of the provied entity by 1 and the accumulated value by the number of elapsed nanoseconds.

        This method should be used in a try...with statement: try( MonitorTimer ns = Monitor.ns(...) ) { ... }

        1. Level 1: entity category
        2. Level 2: entity class name
        3. Level 3: entity id
        4. Level 4: the provided metric
        • Counter value: +1
        • Accumulated value: elapsed nanoseconds
        Type Parameters:
        T - the entity type
        Parameters:
        entity - the target entity
        metric - the target metric
        Returns:
        an auto closeable object to be used in a try...with statement
      • ns

        public <T extends EntityMonitor.MonitorTimer ns​(T entity,
                                                          java.lang.Class<? super T> groupBy)
        Increments the counter of the provied entity by 1 and the accumulated value by the number of elapsed nanoseconds.

        This method should be used in a try...with statement: try( MonitorTimer ns = Monitor.ns(...) ) { ... }

        1. Level 1: entity category
        2. Level 2: the group by type
        3. Level 3: entity id
        4. Level 4: "ns"
        • Counter value: +1
        • Accumulated value: elapsed nanoseconds
        Type Parameters:
        T - the entity type
        Parameters:
        entity - the target entity
        groupBy - the group by type
        Returns:
        an auto closeable object to be used in a try...with statement
      • ns

        public <T extends EntityMonitor.MonitorTimer ns​(T entity,
                                                          java.lang.Class<? super T> groupBy,
                                                          java.lang.String metric)
        Increments the counter of the provied entity by 1 and the accumulated value by the number of elapsed nanoseconds.

        This method should be used in a try...with statement: try( MonitorTimer ns = Monitor.ns(...) ) { ... }

        1. Level 1: entity category
        2. Level 2: the group by type
        3. Level 3: entity id
        4. Level 4: the provided metric
        • Counter value: +1
        • Accumulated value: elapsed nanoseconds
        Type Parameters:
        T - the entity type
        Parameters:
        entity - the target entity
        groupBy - the group by type
        metric - the target metric
        Returns:
        an auto closeable object to be used in a try...with statement
      • ns

        public <T extends EntityMonitor.MonitorTimer ns​(T entity,
                                                          java.lang.String groupBy,
                                                          java.lang.String metric)
        Increments the counter of the provied entity by 1 and the accumulated value by the number of elapsed nanoseconds.

        This method should be used in a try...with statement: try( MonitorTimer ns = Monitor.ns(...) ) { ... }

        1. Level 1: entity category
        2. Level 2: the group by string
        3. Level 3: entity id
        4. Level 4: the provided metric
        • Counter value: +1
        • Accumulated value: elapsed nanoseconds
        Type Parameters:
        T - the entity type
        Parameters:
        entity - the target entity
        groupBy - the group by string
        metric - the target metric
        Returns:
        an auto closeable object to be used in a try...with statement
      • countFor

        public void countFor​(Entity entity,
                             Entity related)
        Increments the counter of the provied entity by 1 with the last level being the id of the related entity. This is useful to track back usage. Example: how many times did a "Fisher" entity interact with a "Lake" entity.
        1. Level 1: entity category
        2. Level 2: entity class name
        3. Level 3: entity id
        4. Level 4: related entity id
        • Counter value: +1
        • Accumulated value: 0
        Parameters:
        entity - the target entity
        related - the related entity
        See Also:
        add(String, String, String, String, long)
      • countFor

        public void countFor​(Entity entity,
                             Entity related,
                             long value)
        Increments the counter of the provied entity by 1 and the accumulated value by the specified amount with the last level being the id of the related entity. This is useful to track back usage. Example: how many fish did a "Fisher" entity capture in a "Lake" entity.
        1. Level 1: entity category
        2. Level 2: entity class name
        3. Level 3: entity id
        4. Level 4: related entity id
        • Counter value: +1
        • Accumulated value: the provided value
        Parameters:
        entity - the target entity
        related - the related entity
        value - the accumulated value
        See Also:
        add(String, String, String, String, long)
      • countFor

        public <T extends Entity> void countFor​(T entity,
                                                Entity related,
                                                java.lang.Class<? super T> groupBy)
        Increments the counter of the provied entity by 1 with the last level being the id of the related entity. This is useful to track back usage. Example: how many times did a "Fisher" entity interact with a "Lake" entity.
        1. Level 1: entity category
        2. Level 2: the group by type
        3. Level 3: entity id
        4. Level 4: related entity id
        • Counter value: +1
        • Accumulated value: 0
        Type Parameters:
        T - the entity class type
        Parameters:
        entity - the target entity
        related - the related entity
        groupBy - a superclass of the entity to group metrics together
        See Also:
        add(String, String, String, String, long)
      • countFor

        public <T extends Entity> void countFor​(T entity,
                                                Entity related,
                                                java.lang.Class<? super T> groupBy,
                                                long value)
        Increments the counter of the provied entity by 1 and the accumulated value by the specified amount with the last level being the id of the related entity. This is useful to track back usage. Example: how many fish did a "Fisher" entity capture in a "Lake" entity.
        1. Level 1: entity category
        2. Level 2: the group by type
        3. Level 3: entity id
        4. Level 4: related entity id
        • Counter value: +1
        • Accumulated value: the provided value
        Type Parameters:
        T - the entity class type
        Parameters:
        entity - the target entity
        related - the related entity
        groupBy - a superclass of the entity to group metrics together
        value - the accumulated value
        See Also:
        add(String, String, String, String, long)
      • add

        public abstract void add​(java.lang.String level1,
                                 java.lang.String level2,
                                 java.lang.String level3,
                                 java.lang.String level4,
                                 long value)
        Increments the counter of the provied entity by 1 and the accumulated value by the specified amount. Levels might be UNSPECIFIED to target a higher group by level, but must not be null.

        Levels should ideally always be alphanumeric lower case to account for case invariant or other remote monitoring systems

        • Counter value: +1
        • Accumulated value: the provided value
        Parameters:
        level1 - the first hyerarchy level (usually an entity category)
        level2 - the second hyerarchy level (usually the entity class name)
        level3 - the third hyerarchy level (usually the entity id)
        level4 - the fourth hyerarchy level (usually a specific metric name)
        value - the accumulated value
      • report

        public Data report()
        Returns all counters and accumulated values.
        1. Level 1: null
        2. Level 2: null
        3. Level 3: null
        4. Level 4: null
        Returns:
        all counters and accumulated values
      • report

        public Data report​(Entity entity)
        Returns counters and accumulated values for all metrics of the given entity.
        1. Level 1: entity category
        2. Level 2: entity class name
        3. Level 3: entity id
        4. Level 4: null
        Parameters:
        entity - the target entity
        Returns:
        counters and accumulated values for all metrics of the given entity
      • report

        public abstract Data report​(java.lang.String level1,
                                    java.lang.String level2,
                                    java.lang.String level3,
                                    java.lang.String level4)
        Returns the counter and accumulated value of the specified metric. Levels may be null to specify a wildcard value for that level (meaning all).

        Levels should ideally always be alphanumeric lower case to account for case invariant or other remote monitoring systems

        Parameters:
        level1 - the first hyerarchy level (usually an entity category)
        level2 - the second hyerarchy level (usually the entity class name)
        level3 - the third hyerarchy level (usually the entity id)
        level4 - the fourth hyerarchy level (usually a specific metric name)
        Returns:
        the counter and accumulated value of the specified metric