Interface RuleStatisticsService

All Known Implementing Classes:
RuleStatisticsServiceImpl

public interface RuleStatisticsService
Service for accessing rule execution statistics from the last x hours.
  • Field Details

    • MAX_HISTORY_HOURS

      static final int MAX_HISTORY_HOURS
      Controls how much history we keep in hours, should provide buffer for re-calculating previous rule_stat daily rollup (>= 25 hours)
      See Also:
  • Method Details

    • expireOldEntries

      void expireOldEntries(Environment env)
      Called regularly to keep this table small.
      Parameters:
      env - the db environment
    • getExecutionTenantCount

      long getExecutionTenantCount(TenantContext context, long millisAgo)
      Returns the number of times rules executed in timeframe specified on this tenant..
      Parameters:
      context - the tenant database context
      millisAgo - how long ago to look for executions in milliseconds
      Returns:
      total count of rule executions
    • getExecutionTenantCountCurrentMonth

      int getExecutionTenantCountCurrentMonth(TenantContext context)
      Returns the number of times rules executed in the current calendar month for a particular tenant.
      Parameters:
      context - the tenant database context
      Returns:
      total count of rule executions
    • getTotalExecutionDuration

      long getTotalExecutionDuration(TenantContext context, long millisAgo, long ruleId)
      Return the total duration this rule spent processing since the created OffsetTime.
      Parameters:
      context - the tenant database context
      millisAgo - how long ago to look for executions in milliseconds
      ruleId - the id of the rule to check
      Returns:
      total execution time in milli seconds since the created offset
    • getLastRuleExecutionStates

      Set<LastRuleExecutionState> getLastRuleExecutionStates(TenantContext context, Set<Long> ruleIds)
      Retrieves the most recent rule execution states for the given rule ids. This can be used to figure out if a rule currently has an error.
      Parameters:
      context - the tenant database context
      ruleIds - The rule ids to lookup audit items for.
      Returns:
      set of matching rule execution states.
    • getPreviousRuleExecutionStartTime

      Optional<Instant> getPreviousRuleExecutionStartTime(TenantContext context, long ruleId)
      Returns the previous execution time prior the one with the provided audit log id.
      Parameters:
      context - the tenant database context
      ruleId - The rule id to lookup the start time for
      Returns:
      the start time or empty if the rule didn't execute yet.
    • getCurrentRuleExecutionStartTime

      Optional<Instant> getCurrentRuleExecutionStartTime(TenantContext context, long ruleId)
      Returns the current execution time prior the one with the provided audit log id.
      Parameters:
      context - the tenant database context
      ruleId - The rule id to lookup the start time for
      Returns:
      the start time or empty if the rule didn't execute yet.
    • isPreviousExecutionSuccessful

      boolean isPreviousExecutionSuccessful(TenantContext context, long ruleId)
      Checks if the execution just prior to the one with the provided audit log id was successful. Only returns false, if a previous execution was found that in an error state defined by State.isErrorState(String). If there was no prior execution this method returns true.
      Parameters:
      context - the tenant database context
      ruleId - The rule id to lookup the previous execution for
    • hasAlreadyBegun

      boolean hasAlreadyBegun(TenantContext context, AutomationEvent event, com.codebarrel.automation.api.config.RuleConfigBean rule)
      A check if the rule has already begun for this particular event? This will be accurate within the last MAX_HISTORY_HOURS hours.
    • getQueuedItemCount

      int getQueuedItemCount(TenantContext context, long ruleId, long auditItemId)
    • getRuleStatistics

      RuleStatistics getRuleStatistics(Environment environment, Instant sinceTimeAgo)
      Returns stats about rule executions since the time provided.
      Parameters:
      sinceTimeAgo - duration for which to collect status
      Returns:
      rule executions.
    • getQueuedItemCount

      long getQueuedItemCount(TenantContext context, Instant sinceTimeAgo)
      Get total queued items for tenant.
      Parameters:
      context - the tenant
      sinceTimeAgo - period for which to look up queued items
      Returns:
      count of items
    • getActiveTenantCount

      long getActiveTenantCount(Environment env, Instant sinceTimeAgo)
      Returns count of tenants that executed a rule in the time period provided.
      Parameters:
      env - The tenant environment.
      sinceTimeAgo - period for which to look up active tenants (max 3 days).
      Returns:
      count of active tenants.
    • updateStaleStatisticsEntries

      void updateStaleStatisticsEntries(TenantContext context, Set<Long> staleAuditItemIds)
      Updates the stale statistics entries for the given audit item ids.
      Parameters:
      context - the tenant database context
      staleAuditItemIds - the set of stale audit item ids