Class: Hooks::Core::Stats

Inherits:
Object
  • Object
show all
Defined in:
lib/hooks/core/stats.rb

Overview

Global stats component for metrics reporting

This is a stub implementation that does nothing by default. Users can replace this with their own implementation for services like DataDog, New Relic, etc.

Instance Method Summary collapse

Instance Method Details

#increment(metric_name, tags = {}) ⇒ void

This method returns an undefined value.

Increment a counter

Parameters:

  • metric_name (String)

    Name of the counter

  • tags (Hash) (defaults to: {})

    Optional tags/labels for the metric



26
27
28
# File 'lib/hooks/core/stats.rb', line 26

def increment(metric_name, tags = {})
  # Override in subclass for actual metrics reporting
end

#measure(metric_name, tags = {}) ⇒ Object

Measure execution time of a block

Parameters:

  • metric_name (String)

    Name of the timing metric

  • tags (Hash) (defaults to: {})

    Optional tags/labels for the metric

Returns:

  • (Object)

    Return value of the block



45
46
47
48
49
50
51
# File 'lib/hooks/core/stats.rb', line 45

def measure(metric_name, tags = {})
  start_time = Time.now.utc
  result = yield
  duration = Time.now.utc - start_time
  timing(metric_name, duration, tags)
  result
end

#record(metric_name, value, tags = {}) ⇒ void

This method returns an undefined value.

Record a metric

Parameters:

  • metric_name (String)

    Name of the metric

  • value (Numeric)

    Value to record

  • tags (Hash) (defaults to: {})

    Optional tags/labels for the metric



17
18
19
# File 'lib/hooks/core/stats.rb', line 17

def record(metric_name, value, tags = {})
  # Override in subclass for actual metrics reporting
end

#timing(metric_name, duration, tags = {}) ⇒ void

This method returns an undefined value.

Record a timing metric

Parameters:

  • metric_name (String)

    Name of the timing metric

  • duration (Numeric)

    Duration in seconds

  • tags (Hash) (defaults to: {})

    Optional tags/labels for the metric



36
37
38
# File 'lib/hooks/core/stats.rb', line 36

def timing(metric_name, duration, tags = {})
  # Override in subclass for actual metrics reporting
end