casseo 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,11 +6,14 @@ module Casseo
6
6
 
7
7
  extend Index
8
8
 
9
- def initialize
9
+ def initialize(name="")
10
+ init_colors
11
+
10
12
  @confs = []
11
13
  @compressed_chart = Config.compressed_chart
12
14
  @data = nil
13
15
  @decimal_precision = Config.decimal_precision
16
+ @name = name
14
17
  @page = 0
15
18
  @period = Config.period_default # minutes
16
19
  @show_max = false
@@ -27,6 +30,7 @@ module Casseo
27
30
  def run
28
31
  @longest_display = @confs.compact.
29
32
  map { |c| c[:display] || c[:metric] }.map { |c| c.length }.max
33
+ @num_metrics = @confs.compact.count
30
34
 
31
35
  # no data yet, but force drawing of stats to the screen
32
36
  show(true)
@@ -56,6 +60,12 @@ module Casseo
56
60
 
57
61
  private
58
62
 
63
+ # color pairs
64
+ NORMAL = 0
65
+ WARNING = 1
66
+ CRITICAL = 2
67
+ STATUS = 3
68
+
59
69
  def clamp(n, min, max)
60
70
  if n < min
61
71
  min
@@ -69,7 +79,8 @@ module Casseo
69
79
  def fetch(suppress_errors=true)
70
80
  metrics = @confs.compact.map { |c| c[:metric] }
71
81
  targets = metrics.map { |m| "target=#{URI.encode(m)}" }.join("&")
72
- uri = URI.parse("#{Config.graphite_url}/render/?#{targets}&from=-#{@period}minutes&format=json")
82
+ uri = URI.parse("#{Config.graphite_url}/render/?#{targets}&" +
83
+ "from=-#{@period}minutes&format=json")
73
84
 
74
85
  http = Net::HTTP.new(uri.host, uri.port)
75
86
  http.use_ssl = true
@@ -140,8 +151,22 @@ module Casseo
140
151
  end
141
152
  end
142
153
 
154
+ def init_colors
155
+ Curses.start_color
156
+ Curses.use_default_colors
157
+
158
+ Curses.init_pair(1, Curses::COLOR_YELLOW, -1)
159
+ Curses.init_pair(2, Curses::COLOR_RED, -1)
160
+ Curses.init_pair(3, Curses::COLOR_GREEN, Curses::COLOR_BLUE)
161
+ end
162
+
163
+ def num_lines
164
+ # -1 for the status line
165
+ Curses.lines - 1
166
+ end
167
+
143
168
  def num_pages
144
- (@confs.count / Curses.lines).ceil
169
+ (@confs.count / num_lines).ceil
145
170
  end
146
171
 
147
172
  def show(force_draw=false)
@@ -153,7 +178,7 @@ module Casseo
153
178
 
154
179
  @confs.each_with_index do |conf, i|
155
180
  next unless conf
156
- next unless i >= @page * Curses.lines && i < (@page + 1) * Curses.lines
181
+ next unless i >= @page * num_lines && i < (@page + 1) * num_lines
157
182
 
158
183
  data_points = @data.detect { |d| d["target"] == conf[:metric] }
159
184
  data_points = data_points ? data_points["datapoints"].dup : []
@@ -195,10 +220,36 @@ module Casseo
195
220
 
196
221
  str += chart
197
222
  str = str[0...Curses.cols]
198
- Curses.setpos(i % Curses.lines, 0)
199
- Curses.addstr(str)
223
+
224
+ color_pair = if conf[:critical] && latest >= conf[:critical]
225
+ CRITICAL
226
+ elsif conf[:warning] && latest >= conf[:warning]
227
+ WARNING
228
+ else
229
+ NORMAL
230
+ end
231
+
232
+ Curses.setpos(i % num_lines, 0)
233
+ Curses.attron(Curses::color_pair(color_pair) | Curses::A_NORMAL) do
234
+ Curses.addstr(str)
235
+ end
200
236
  end
237
+
238
+ show_status
201
239
  Curses.refresh
202
240
  end
241
+
242
+ def show_status
243
+ Curses.setpos(num_lines, 0)
244
+ Curses.attron(Curses::color_pair(STATUS) | Curses::A_NORMAL) do
245
+ str = "Casseo: =#{@name} (#{@period}m) " +
246
+ "[Metrics:#{@num_metrics} Page:#{@page}/#{num_pages} " +
247
+ "Interval:#{Config.interval.to_i}s]"
248
+
249
+ # pad until the end of the line so we get the background
250
+ str += " " * (Curses.cols - str.length)
251
+ Curses.addstr(str)
252
+ end
253
+ end
203
254
  end
204
255
  end
data/lib/casseo/index.rb CHANGED
@@ -3,7 +3,7 @@ module Casseo
3
3
  @@index = {}
4
4
 
5
5
  def define(name)
6
- dashboard = Dashboard.new
6
+ dashboard = Dashboard.new(name)
7
7
  yield(dashboard)
8
8
  @@index[name] = dashboard
9
9
  dashboard
data/lib/casseo/runner.rb CHANGED
@@ -17,7 +17,7 @@ module Casseo
17
17
 
18
18
  Curses.init_screen
19
19
 
20
- # fail fast on missing required config
20
+ # fail fast on missing config
21
21
  Config.required
22
22
 
23
23
  load_dashboards
@@ -1,3 +1,3 @@
1
1
  module Casseo
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: casseo
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:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-01 00:00:00.000000000 Z
12
+ date: 2012-07-20 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: brandur@mutelight.org
@@ -20,8 +20,7 @@ extra_rdoc_files: []
20
20
  files:
21
21
  - README.md
22
22
  - Rakefile
23
- - !binary |-
24
- YmluL2Nhc3Nlbw==
23
+ - bin/casseo
25
24
  - lib/casseo/config.rb
26
25
  - lib/casseo/dashboard.rb
27
26
  - lib/casseo/index.rb
@@ -49,7 +48,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
48
  version: '0'
50
49
  requirements: []
51
50
  rubyforge_project:
52
- rubygems_version: 1.8.24
51
+ rubygems_version: 1.8.23
53
52
  signing_key:
54
53
  specification_version: 3
55
54
  summary: A Graphite dashboard for the command line.