casseo 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -12,7 +12,7 @@ Or if you're really concerned about Rubygems' speed, clone the reposistory and c
12
12
  git clone https://github.com/brandur/casseo.git
13
13
  cd casseo
14
14
  rake standalone
15
- mv casseo ~/bin/casseo
15
+ mv casseo ~/bin/
16
16
 
17
17
  Configuration
18
18
  -------------
@@ -24,10 +24,11 @@ Casseo expects to be able to find your Graphite credentials at `~/.casseorc`:
24
24
 
25
25
  Other allowed configuration options are:
26
26
 
27
- * `compressed_chart:` whether to include a space between chart symbols
28
- * `dashboard_default:` name of the dashboard to load if none is specified
29
- * `interval:` Graphite update interval in seconds
30
- * `period_default:` default period of data to show
27
+ * `compressed_chart:` whether to include a space between chart symbols (default: false)
28
+ * `dashboard_default:` name of the dashboard to load if none is specified (default: home)
29
+ * `decimal_precision:` floating point precision to show (default: 1); see also `p` shortcut
30
+ * `interval:` Graphite update interval in seconds (default: 2)
31
+ * `period_default:` default period of data to show (default: 5 minutes)
31
32
 
32
33
  Dashboards
33
34
  ----------
@@ -68,6 +69,8 @@ For now, there are no options on key bindings. Here's what you get:
68
69
 
69
70
  * `j` page down
70
71
  * `k` page up
72
+ * `m` show/hide max value column
73
+ * `p` show more floating point precision
71
74
  * `q` quit
72
75
  * `1` 5 minute range
73
76
  * `2` 60 minute range
@@ -4,13 +4,18 @@ module Casseo
4
4
 
5
5
  # whether an extra space is inserted between chart characters
6
6
  def compressed_chart
7
- config(:compressed_chart)
7
+ !!config(:compressed_chart)
8
8
  end
9
9
 
10
10
  def dashboard_default
11
11
  config(:dashboard_default) || :home
12
12
  end
13
13
 
14
+ # show extra decimal precision
15
+ def decimal_precision
16
+ config(:decimal_precision) || 1
17
+ end
18
+
14
19
  def graphite_auth
15
20
  config!(:graphite_auth)
16
21
  end
@@ -9,8 +9,10 @@ module Casseo
9
9
  def initialize
10
10
  @confs = []
11
11
  @data = nil
12
+ @decimal_precision = Config.decimal_precision
12
13
  @page = 0
13
14
  @period = Config.period_default # minutes
15
+ @show_max = false
14
16
  end
15
17
 
16
18
  def blank
@@ -84,13 +86,18 @@ module Casseo
84
86
 
85
87
  def handle_key_presses
86
88
  loop do
87
- new_page = nil
88
- new_period = nil
89
+ new_decimal_precision = nil
90
+ new_page = nil
91
+ new_period = nil
92
+ new_show_max = nil
89
93
 
90
94
  case Curses.getch
91
95
  when Curses::KEY_RESIZE then show
92
96
  when ?j then new_page = clamp(@page + 1, 0, num_pages)
93
97
  when ?k then new_page = clamp(@page - 1, 0, num_pages)
98
+ when ?m then new_show_max = !@show_max
99
+ when ?p then new_decimal_precision = @decimal_precision == 3 ?
100
+ Config.decimal_precision : 3
94
101
  when ?q then Kernel.exit(0)
95
102
  when ?1 then new_period = 5
96
103
  when ?2 then new_period = 60
@@ -105,6 +112,18 @@ module Casseo
105
112
  show
106
113
  end
107
114
 
115
+ if new_show_max != nil
116
+ @show_max = new_show_max
117
+ Curses.clear
118
+ show
119
+ end
120
+
121
+ if new_decimal_precision && new_decimal_precision != @decimal_precision
122
+ @decimal_precision = new_decimal_precision
123
+ Curses.clear
124
+ show
125
+ end
126
+
108
127
  if new_period && new_period != @period
109
128
  @period = new_period
110
129
  # will update the next time the fetch loop runs
@@ -130,20 +149,25 @@ module Casseo
130
149
  data_points = @data.detect { |d| d["target"] == conf[:metric] }
131
150
  data_points = data_points ? data_points["datapoints"].dup : []
132
151
 
133
- # smaller range high resolution requests will have nil values
134
- data_points.reject! { |p| p[0] == nil }
135
-
136
152
  # show left to right latest to oldest
137
153
  data_points.reverse!
138
154
 
139
- max = data_points.max { |p1, p2| p1[0] <=> p2[0] }
155
+ max = data_points.select { |p| p[0] != nil }.
156
+ max { |p1, p2| p1[0] <=> p2[0] }
140
157
  max = max ? max[0] : nil
141
158
 
142
- latest = data_points.count > 0 ? data_points[0][0] : 0.0
159
+ # keep everything under a very small threshold at 0 bars
160
+ max = 0.0 if max && max < 0.01
161
+
162
+ latest = data_points.detect { |p| p[0] != nil }
163
+ latest = latest ? latest[0] : 0.0
143
164
 
144
165
  unit = conf[:unit] || " "
145
- str = "%-#{@longest_display}s %8.1f%s " %
166
+ float_width = 7 + @decimal_precision
167
+ str = "%-#{@longest_display}s %#{float_width}.#{@decimal_precision}f%s " %
146
168
  [conf[:display] || conf[:metric], latest, unit]
169
+ str += "%#{float_width}.#{@decimal_precision}f%s " %
170
+ [max || 0.0, unit] if @show_max
147
171
 
148
172
  chart = ""
149
173
  if max && max > 0
@@ -152,6 +176,7 @@ module Casseo
152
176
  next if i % 2 == 0 unless Config.compressed_chart
153
177
  index = ((i.to_f / num_samples.to_f) * data_points.count.to_f).to_i - 1
154
178
  sample = data_points[index][0]
179
+ sample = 0.0 unless sample
155
180
 
156
181
  index = (sample / max * CHART_CHARS.count).to_i - 1
157
182
  chart += CHART_CHARS[index]
@@ -1,3 +1,3 @@
1
1
  module Casseo
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
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.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: