riemann-dash 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/riemann/dash.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'rubygems'
1
2
  require 'riemann/client'
2
3
  require 'sinatra/base'
3
4
 
@@ -12,17 +13,17 @@ module Riemann
12
13
 
13
14
  def self.config
14
15
  @config ||= {
15
- client: {},
16
- age_scale: 60 * 30,
17
- state_order: {
16
+ :client => {},
17
+ :age_scale => 60 * 30,
18
+ :state_order => {
18
19
  'critical' => 3,
19
20
  'warning' => 2,
20
21
  'ok' => 1
21
22
  },
22
- strftime: '%H:%M:%S',
23
- controllers: [File.join(File.dirname(__FILE__), 'dash', 'controller')],
24
- helpers: [File.join(File.dirname(__FILE__), 'dash', 'helper')],
25
- views: File.join(File.dirname(__FILE__), 'dash', 'views')
23
+ :strftime => '%H:%M:%S',
24
+ :controllers => [File.join(File.dirname(__FILE__), 'dash', 'controller')],
25
+ :helpers => [File.join(File.dirname(__FILE__), 'dash', 'helper')],
26
+ :views => File.join(File.dirname(__FILE__), 'dash', 'views')
26
27
  }
27
28
  end
28
29
 
@@ -47,7 +47,7 @@ module Riemann
47
47
  table(
48
48
  *Event.partition(states, :host).map do |host, states|
49
49
  tr(
50
- th(host, class: 'host'),
50
+ th(host, :class => 'host'),
51
51
  *Event.sort(states, :service).map do |state|
52
52
  state_short state
53
53
  end
@@ -59,7 +59,7 @@ module Riemann
59
59
  # Renders a state as the given HTML tag with a % width corresponding to
60
60
  # metric / max.
61
61
  def state_bar(s, opts = {})
62
- opts = {tag: 'div', max: 1}.merge opts
62
+ opts = {:tag => 'div', :max => 1}.merge opts
63
63
 
64
64
  return '' unless s
65
65
  x = s.metric
@@ -71,21 +71,30 @@ module Riemann
71
71
  when Integer
72
72
  x.to_s
73
73
  else
74
- '?'
74
+ s.state || '?'
75
75
  end
76
76
 
77
77
  # Size
78
- size = begin
79
- (x || 0) * 100 / opts[:max]
80
- rescue ZeroDivisionError
81
- 0
82
- end
78
+ size = case x
79
+ when 0
80
+ 0
81
+ when nil
82
+ 100
83
+ else
84
+ begin
85
+ x * 100 / opts[:max]
86
+ rescue ZeroDivisionError
87
+ 0
88
+ end
89
+ end
83
90
  size = "%.2f" % size
84
91
 
92
+ time = Time.at(s.time).strftime(Dash.config[:strftime])
93
+
85
94
  tag opts[:tag], h(text),
86
95
  :class => "state #{s.state}",
87
- style: "opacity: #{age_fraction s.time}; width: #{size}%",
88
- title: s.description
96
+ :style => "opacity: #{age_fraction s.time}; width: #{size}%",
97
+ :title => "#{s.state}\n#{s.description}\n\n(at #{time})"
89
98
  end
90
99
 
91
100
  # Renders a set of states in a chart. Each row is a given host, each
@@ -179,12 +188,11 @@ module Riemann
179
188
  *hosts.map do |host|
180
189
  s = by[[host, service]]
181
190
  td(
182
- s ? state_bar(s, max: maxima[service]) : nil
191
+ s ? state_bar(s, :max => maxima[service]) : nil
183
192
  )
184
193
  end
185
194
  )
186
- end,
187
- :class => 'chart'
195
+ end << {:class => 'chart'} # ruby 1.8.7 this is your fault
188
196
  )
189
197
  else
190
198
  h2(title) +
@@ -201,18 +209,18 @@ module Riemann
201
209
  *services.map do |service|
202
210
  s = by[[host, service]]
203
211
  td(
204
- s ? state_bar(s, max: maxima[service]) : nil
212
+ s ? state_bar(s, :max => maxima[service]) : nil
205
213
  )
206
214
  end
207
215
  )
208
- end,
209
- :class => 'chart'
216
+ end <<
217
+ {:class => 'chart'}
210
218
  )
211
219
  end
212
220
  end
213
221
 
214
222
  # Renders a state as a short tag.
215
- def state_short(s, opts={tag: 'li'})
223
+ def state_short(s, opts={:tag => 'li'})
216
224
  if s
217
225
  "<#{opts[:tag]} class=\"state #{s.state}\" style=\"opacity: #{age_fraction s.time}\" title=\"#{h s.description}\">#{h s.host} #{h s.service}</#{opts[:tag]}>"
218
226
  else
@@ -1,4 +1,4 @@
1
1
  module Riemann; end
2
2
  class Riemann::Dash
3
- VERSION = '0.0.3'
3
+ VERSION = '0.0.4'
4
4
  end
@@ -2,7 +2,7 @@
2
2
  <div class="box"><%= state_list query('state != "ok"') %></div>
3
3
 
4
4
  <div class="box">
5
- <%= state_chart query('service = "cpu" or service = "memory" or service =~ "disk%" or service = "load"'), title: "Health" %>
5
+ <%= state_chart query('service = "cpu" or service = "memory" or service =~ "disk%" or service = "load"'), :title => "Health" %>
6
6
  </div>
7
7
 
8
- <div class="box"><%= state_chart query('true'), title: "Everything" %></div>
8
+ <div class="box"><%= state_chart query('true'), :title => "Everything" %></div>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riemann-dash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-24 00:00:00.000000000 Z
12
+ date: 2012-04-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: riemann-client
16
- requirement: &9900960 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: 0.0.3
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *9900960
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.0.3
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: erubis
27
- requirement: &9900240 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: 2.7.0
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *9900240
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 2.7.0
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: sinatra
38
- requirement: &9899640 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: 1.3.2
44
54
  type: :runtime
45
55
  prerelease: false
46
- version_requirements: *9899640
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.3.2
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: sass
49
- requirement: &9898820 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: 3.1.14
55
70
  type: :runtime
56
71
  prerelease: false
57
- version_requirements: *9898820
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 3.1.14
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: thin
60
- requirement: &9898320 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
@@ -65,7 +85,12 @@ dependencies:
65
85
  version: 1.3.1
66
86
  type: :runtime
67
87
  prerelease: false
68
- version_requirements: *9898320
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 1.3.1
69
94
  description:
70
95
  email: aphyr@aphyr.com
71
96
  executables:
@@ -75,13 +100,13 @@ extra_rdoc_files: []
75
100
  files:
76
101
  - lib/riemann/dash.rb
77
102
  - lib/riemann/dash/version.rb
78
- - lib/riemann/dash/rack/static.rb
79
- - lib/riemann/dash/views/index.erubis
103
+ - lib/riemann/dash/controller/css.rb
104
+ - lib/riemann/dash/controller/index.rb
80
105
  - lib/riemann/dash/views/layout.erubis
106
+ - lib/riemann/dash/views/index.erubis
81
107
  - lib/riemann/dash/views/css.scss
82
- - lib/riemann/dash/controller/index.rb
83
- - lib/riemann/dash/controller/css.rb
84
108
  - lib/riemann/dash/helper/renderer.rb
109
+ - lib/riemann/dash/rack/static.rb
85
110
  - bin/riemann-dash
86
111
  - LICENSE
87
112
  - README.markdown
@@ -105,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
130
  version: '0'
106
131
  requirements: []
107
132
  rubyforge_project: riemann-dash
108
- rubygems_version: 1.8.10
133
+ rubygems_version: 1.8.22
109
134
  signing_key:
110
135
  specification_version: 3
111
136
  summary: HTTP dashboard for the distributed event system Riemann.