irfsdash 0.1.3 → 0.1.5

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.
data/README.md CHANGED
@@ -16,6 +16,16 @@ Or install it yourself as:
16
16
 
17
17
  $ gem install irfsdash
18
18
 
19
+ ## Requirements
20
+
21
+ *You cannot run IRFSDash without an AMQP server and a statsd/graphite server*. There is a production server, which is the default, but this is only accessible within the IRFS gateway.
22
+
23
+ You can set the AMQP/Statsd hosts as follows:
24
+
25
+ # must be called BEFORE any other methods, ie in an initializer
26
+ IRFSDash.statsd_host(hostname)
27
+ IRFSDash.amqp_host(hostname)
28
+
19
29
  ## Usage
20
30
 
21
31
  In an initializer:
@@ -43,6 +53,14 @@ Publish a widget:
43
53
  IRFSDash.widget(content: '<strong>Hello</strong> world')
44
54
  IRFSDash.widget(url: 'http://some-url')
45
55
 
56
+ Increment/decrement a counter:
57
+
58
+ IRFSDash.increment("clips-made")
59
+ IRFSDash.decrement("clips-made")
60
+
61
+ Record the time taken for an event (time in milliseconds):
62
+
63
+ IRFSDash.timing("clip-creation", 500)
46
64
 
47
65
  ## Contributing
48
66
 
@@ -51,3 +69,4 @@ Publish a widget:
51
69
  3. Commit your changes (`git commit -am 'Add some feature'`)
52
70
  4. Push to the branch (`git push origin my-new-feature`)
53
71
  5. Create new Pull Request
72
+
@@ -19,4 +19,5 @@ Gem::Specification.new do |gem|
19
19
  gem.add_dependency('bunny', '>= 0.8.0')
20
20
  gem.add_dependency('json', '>= 1.7.5')
21
21
  gem.add_dependency('trollop', '>= 2.0.0')
22
+ gem.add_dependency('statsd-ruby', '>= 1.0.0')
22
23
  end
@@ -1,14 +1,29 @@
1
1
  require "irfsdash/version"
2
2
  require "bunny"
3
3
  require "json"
4
+ require "statsd"
4
5
  module IRFSDash
6
+ # Set the Statsd hostname
7
+ def self.statsd_host(host='10.10.12.156')
8
+ @statsd_host ||= host
9
+ end
10
+ # Set the AMQP host
11
+ def self.amqp_host(host='10.10.12.156')
12
+ @amqp_host ||= host
13
+ end
5
14
  # Returns an AMQP channel
6
15
  def self.amqp
7
16
  return @b if @b
8
- @b = Bunny.new(host: 'localhost')
17
+ @b = Bunny.new(host: self.amqp_host)
9
18
  @b.start
10
19
  return @b
11
20
  end
21
+ def self.statsd
22
+ return @statsd if @statsd
23
+ @statsd = Statsd.new(self.statsd_host, 8125)
24
+ @statsd.namespace('irfsdash')
25
+ return @statsd
26
+ end
12
27
  # Setup the library's defaults
13
28
  def self.setup(opts={})
14
29
  @defaults = opts
@@ -48,5 +63,20 @@ module IRFSDash
48
63
  raise ArgumentError, "No content or URL specified" unless msg[:url] or msg[:content]
49
64
  self.amqp.exchange("irfs-dashboard.widgets", type: :fanout).publish(JSON.dump(msg))
50
65
  end
66
+ # Increment a counter in statsd.
67
+ # Arguments: Counter name to increment, optional sample rate
68
+ def self.increment(*args)
69
+ self.statsd.increment(*args)
70
+ end
71
+ # Decrement a counter in statsd.
72
+ # Arguments: Counter name to decrement, optional sample rate
73
+ def self.decrement(*args)
74
+ self.statsd.decrement(*args)
75
+ end
76
+ # Report a task time in statsd
77
+ # Arguments: Task name, time in milliseconds, optional sample rate
78
+ def self.timing(*args)
79
+ self.statsd.timing(*args)
80
+ end
51
81
 
52
82
  end
@@ -1,3 +1,3 @@
1
1
  module IRFSDash
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: irfsdash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-25 00:00:00.000000000 Z
12
+ date: 2012-11-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bunny
@@ -59,6 +59,22 @@ dependencies:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: 2.0.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: statsd-ruby
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: 1.0.0
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 1.0.0
62
78
  description: Interface gem for the BBC Research and Development IRFS Dashboard
63
79
  email:
64
80
  - james.harrison2@bbc.co.uk