Class: Resque::CloudWatch::Metrics::Metric

Inherits:
Object
  • Object
show all
Defined in:
lib/resque/cloudwatch/metrics/metric.rb

Constant Summary collapse

@@mutex =
Mutex.new

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(time, namespace, info, queue_sizes, previous_processed) ⇒ Metric



44
45
46
47
48
49
50
# File 'lib/resque/cloudwatch/metrics/metric.rb', line 44

def initialize(time, namespace, info, queue_sizes, previous_processed)
  @time = time
  @namespace = namespace
  @info = info
  @queue_sizes = queue_sizes
  @previous_processed = previous_processed
end

Class Method Details

.create(namespace) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/resque/cloudwatch/metrics/metric.rb', line 12

def create(namespace)
  @@mutex.synchronize do
    Resque.redis.namespace = namespace
    new(
      Time.now,
      namespace,
      Resque.info,
      current_queue_sizes,
      get_previous_processed(namespace),
    ).tap do |metric|
      set_previous_processed(namespace, metric.processed)
    end
  end
end

Instance Method Details

#failedObject



54
# File 'lib/resque/cloudwatch/metrics/metric.rb', line 54

def failed;    @info[:failed];    end

#pendingObject



52
# File 'lib/resque/cloudwatch/metrics/metric.rb', line 52

def pending;   @info[:pending];   end

#processedObject



53
# File 'lib/resque/cloudwatch/metrics/metric.rb', line 53

def processed; @info[:processed]; end

#processingObject



59
60
61
# File 'lib/resque/cloudwatch/metrics/metric.rb', line 59

def processing
  incremental_size_of_processed + working
end

#queuesObject



55
# File 'lib/resque/cloudwatch/metrics/metric.rb', line 55

def queues;    @info[:queues];    end

#to_cloudwatch_metric_dataObject



63
64
65
66
67
68
69
70
71
72
# File 'lib/resque/cloudwatch/metrics/metric.rb', line 63

def to_cloudwatch_metric_data
  dimensions = [{ name: 'namespace', value: @namespace.to_s }]

  i(pending processed failed queues workers working processing).map do |key|
    build_cloudwatch_metric_datum(key.to_s.capitalize, public_send(key))
  end +
  @queue_sizes.map do |name, size|
    build_cloudwatch_metric_datum('Pending', size, queue: name)
  end
end

#workersObject



56
# File 'lib/resque/cloudwatch/metrics/metric.rb', line 56

def workers;   @info[:workers];   end

#workingObject



57
# File 'lib/resque/cloudwatch/metrics/metric.rb', line 57

def working;   @info[:working];   end