hipstascale 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -30,9 +30,12 @@ module HipstaScale
30
30
  private
31
31
 
32
32
  def params
33
+ end_time = Time.now
34
+ begin_time = end_time - (app.interval < 60 ? 60 : app.interval)
35
+
33
36
  ''.tap do |params|
34
- params << 'begin=' << (Time.now - (app.interval * 60)).strftime('%Y-%m-%dT%H:%M:%S%z')
35
- params << '&end=' << Time.now.strftime('%Y-%m-%dT%H:%M:%S%z')
37
+ params << 'begin=' << begin_time.strftime('%Y-%m-%dT%H:%M:%S%z')
38
+ params << '&end=' << end_time.strftime('%Y-%m-%dT%H:%M:%S%z')
36
39
  params << '&field=' << 'busy_percent'
37
40
  params << '&metrics[]=' << 'Instance/Busy'
38
41
  end
@@ -3,33 +3,45 @@ require 'eventmachine'
3
3
  module HipstaScale
4
4
  class Process
5
5
 
6
+ attr_reader :app
7
+
6
8
  def self.run!
7
9
  EventMachine.run do
10
+ HipstaScale.logger.info "HipstaScale is watching #{HipstaScale.apps.size} #{HipstaScale.apps.size == 1 ? 'application' : 'applications'}"
8
11
  HipstaScale.apps.each do |app|
9
12
  Process.new(app)
10
- # Simple way to make sure all of our external calls don't happen all
11
- # at once.
12
- sleep(10)
13
13
  end
14
14
  end
15
15
  end
16
16
 
17
17
  def initialize(app)
18
- logger.info "Check usage for #{app.name} every #{app.interval * 60} seconds"
19
- EventMachine.add_periodic_timer(app.interval * 60) do
20
- app.tick do
21
- logger.info "[#{app.name.upcase}] Instance usage: %.2f%%" % (app.current_load * 100.0)
22
- logger.info "[#{app.name.upcase}] Amount of processes needed to reach the %.2f%% of target load: #{app.processes_needed}" % (app.load_limit * 100)
23
-
24
- if app.processes_needed != app.processes_running
25
- logger.info "[#{app.name.upcase}] Scaling processes from #{app.processes_running} to #{app.processes_needed}"
26
- app.scale!
27
- end
18
+ @app = app
19
+
20
+ time_slot = Random.rand(1..(app.interval / 2))
21
+
22
+ logger.info "Checking usage for '#{app.name}' every #{app.interval} #{app.interval == 1 ? 'second' : 'seconds'}"
23
+ logger.info "Will start in #{time_slot} #{time_slot == 1 ? 'second' : 'seconds'}..."
24
+
25
+ # Simple way of spacing out the timers so they don't all run at once.
26
+ EventMachine::add_timer(time_slot) do
27
+ EventMachine.add_periodic_timer(app.interval) { self.check }
28
+ self.check
29
+ end
30
+ end
31
+
32
+ def check
33
+ app.tick do
34
+ logger.info "[#{app.name.upcase}] Instance usage: %.2f%%" % (app.current_load * 100.0)
35
+ logger.info "[#{app.name.upcase}] Amount of processes needed to reach the %.2f%% of target load: #{app.processes_needed}" % (app.load_limit * 100)
36
+
37
+ if app.processes_needed != app.processes_running
38
+ logger.info "[#{app.name.upcase}] Scaling processes from #{app.processes_running} to #{app.processes_needed}"
39
+ app.scale!
28
40
  end
29
41
  end
30
42
  end
31
43
 
32
- private
44
+ private
33
45
 
34
46
  def logger
35
47
  HipstaScale.logger
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hipstascale
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-05-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine
16
- requirement: &70236309054120 !ruby/object:Gem::Requirement
16
+ requirement: &70107264395760 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.12.10
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70236309054120
24
+ version_requirements: *70107264395760
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &70236309053360 !ruby/object:Gem::Requirement
27
+ requirement: &70107264395200 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.7.3
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70236309053360
35
+ version_requirements: *70107264395200
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rest-client
38
- requirement: &70236309052380 !ruby/object:Gem::Requirement
38
+ requirement: &70107264394380 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: 1.6.7
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70236309052380
46
+ version_requirements: *70107264394380
47
47
  description: HipstaScale helps create long-running processes that use NewRelic RPM
48
48
  information to scale your Heroku instances before you need it.
49
49
  email: jeremy@jeremyboles.com