casseo 0.1.0 → 0.1.1
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 +14 -13
- data/Rakefile +17 -1
- data/bin/casseo +4 -42
- data/lib/casseo.rb +1 -0
- data/lib/casseo/config.rb +5 -0
- data/lib/casseo/dashboard.rb +19 -15
- data/lib/casseo/runner.rb +62 -0
- data/lib/casseo/version.rb +1 -1
- metadata +2 -1
data/README.md
CHANGED
@@ -24,18 +24,19 @@ Casseo expects to be able to find your Graphite credentials at `~/.casseorc`:
|
|
24
24
|
|
25
25
|
Other allowed configuration options are:
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
30
31
|
|
31
32
|
Dashboards
|
32
33
|
----------
|
33
34
|
|
34
|
-
Dashboards are configured via simple Ruby in a manner reminiscent of Tasseo. All `*.rb` files in `~/.casseo/dashboards` or in any of its subdirectories are loaded automatically
|
35
|
+
Dashboards are configured via simple Ruby in a manner reminiscent of Tasseo. All `*.rb` files in `~/.casseo/dashboards` or in any of its subdirectories are loaded automatically. Dashboards are assigned names so that they can be referenced and opened like so:
|
35
36
|
|
36
37
|
casseo home
|
37
38
|
|
38
|
-
An example dashboard
|
39
|
+
An example dashboard (save to `~/.casseo/dashboards/home.rb`):
|
39
40
|
|
40
41
|
``` ruby
|
41
42
|
Casseo::Dashboard.define(:api) do |d|
|
@@ -65,13 +66,13 @@ Key Bindings
|
|
65
66
|
|
66
67
|
For now, there are no options on key bindings. Here's what you get:
|
67
68
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
69
|
+
* `j` page down
|
70
|
+
* `k` page up
|
71
|
+
* `q` quit
|
72
|
+
* `1` 5 minute range
|
73
|
+
* `2` 60 minute range
|
74
|
+
* `3` 3 hour range
|
75
|
+
* `4` 24 hour range
|
76
|
+
* `5` 7 day range
|
76
77
|
|
77
78
|
[tasseo]: https://github.com/obfuscurity/tasseo
|
data/Rakefile
CHANGED
@@ -1,2 +1,18 @@
|
|
1
|
-
task :standalone
|
1
|
+
task :standalone do
|
2
|
+
# lib/casseo.rb knows the correct load order
|
3
|
+
source_files = File.read("./lib/casseo.rb").
|
4
|
+
scan(/require_relative "(.*)"/).map { |f| "./lib/#{f.first}.rb" }
|
5
|
+
|
6
|
+
# use bin/casseo as an executable template
|
7
|
+
skeleton = File.read("./bin/casseo")
|
8
|
+
source = source_files.map { |f| File.read(f) }.join("\n")
|
9
|
+
source = skeleton.gsub(
|
10
|
+
/# @@STANDALONE_START@@.*# @@STANDALONE_END@@\n\n/m, source)
|
11
|
+
|
12
|
+
target = "./casseo"
|
13
|
+
File.open(target, 'w') do |f|
|
14
|
+
f.puts source
|
15
|
+
f.chmod 0755
|
16
|
+
end
|
17
|
+
puts "Saved to #{target}"
|
2
18
|
end
|
data/bin/casseo
CHANGED
@@ -7,48 +7,10 @@ require "net/https"
|
|
7
7
|
require "timeout"
|
8
8
|
require "uri"
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
# load all user dashboards
|
13
|
-
dir = "#{File.expand_path("~")}/.casseo/dashboards"
|
14
|
-
if File.exists?(dir)
|
15
|
-
# clever hack to get symlinks working properly
|
16
|
-
Dir["#{dir}/**{,/*/**}/*.rb"].each do |d|
|
17
|
-
require d
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
$exit_message = nil
|
10
|
+
# @@STANDALONE_START@@
|
22
11
|
|
23
|
-
|
24
|
-
Signal.trap(s) do
|
25
|
-
$exit_message = "Caught deadly signal"
|
26
|
-
Kernel.exit(0)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
begin
|
31
|
-
Curses.cbreak # no need for a newline to get type chars
|
32
|
-
Curses.curs_set(1) # invisible
|
33
|
-
Curses.noecho # don't echo character on a getch
|
34
|
-
|
35
|
-
Curses.init_screen
|
12
|
+
require_relative "../lib/casseo"
|
36
13
|
|
37
|
-
|
38
|
-
Casseo::Config.required
|
14
|
+
# @@STANDALONE_END@@
|
39
15
|
|
40
|
-
|
41
|
-
require ARGV.first
|
42
|
-
elsif ARGV.count > 0 && ["-l", "--list"].include?(ARGV.first)
|
43
|
-
$exit_message = Casseo::Dashboard.index.sort.join("\n")
|
44
|
-
elsif ARGV.first
|
45
|
-
Casseo::Dashboard.run(ARGV.first.to_sym)
|
46
|
-
else
|
47
|
-
Casseo::Dashboard.run(Casseo::Config.dashboard_default)
|
48
|
-
end
|
49
|
-
rescue Casseo::ConfigError, Casseo::DashboardNotFound => e
|
50
|
-
$exit_message = e.message
|
51
|
-
ensure
|
52
|
-
Curses.close_screen
|
53
|
-
puts $exit_message if $exit_message
|
54
|
-
end
|
16
|
+
Casseo::Runner.execute(ARGV)
|
data/lib/casseo.rb
CHANGED
data/lib/casseo/config.rb
CHANGED
data/lib/casseo/dashboard.rb
CHANGED
@@ -10,7 +10,7 @@ module Casseo
|
|
10
10
|
@confs = []
|
11
11
|
@data = nil
|
12
12
|
@page = 0
|
13
|
-
@period =
|
13
|
+
@period = Config.period_default # minutes
|
14
14
|
end
|
15
15
|
|
16
16
|
def blank
|
@@ -128,34 +128,38 @@ module Casseo
|
|
128
128
|
next unless i >= @page * Curses.lines && i < (@page + 1) * Curses.lines
|
129
129
|
|
130
130
|
data_points = @data.detect { |d| d["target"] == conf[:metric] }
|
131
|
-
data_points = data_points ? data_points["datapoints"] : []
|
131
|
+
data_points = data_points ? data_points["datapoints"].dup : []
|
132
|
+
|
133
|
+
# smaller range high resolution requests will have nil values
|
134
|
+
data_points.reject! { |p| p[0] == nil }
|
132
135
|
|
133
136
|
# show left to right latest to oldest
|
134
137
|
data_points.reverse!
|
135
138
|
|
136
|
-
max = data_points.
|
137
|
-
select { |p| p[0] != nil }.
|
138
|
-
max { |p1, p2| p1[0] <=> p2[0] }
|
139
|
+
max = data_points.max { |p1, p2| p1[0] <=> p2[0] }
|
139
140
|
max = max ? max[0] : nil
|
140
141
|
|
141
|
-
latest = data_points.
|
142
|
-
|
142
|
+
latest = data_points.count > 0 ? data_points[0][0] : 0.0
|
143
|
+
|
144
|
+
unit = conf[:unit] || " "
|
145
|
+
str = "%-#{@longest_display}s %8.1f%s " %
|
146
|
+
[conf[:display] || conf[:metric], latest, unit]
|
143
147
|
|
144
|
-
current = nil
|
145
148
|
chart = ""
|
146
149
|
if max && max > 0
|
147
|
-
|
148
|
-
|
149
|
-
next unless
|
150
|
-
index = (
|
150
|
+
num_samples = Curses.cols - str.length
|
151
|
+
(1..num_samples).each do |i|
|
152
|
+
next if i % 2 == 0 unless Config.compressed_chart
|
153
|
+
index = ((i.to_f / num_samples.to_f) * data_points.count.to_f).to_i - 1
|
154
|
+
sample = data_points[index][0]
|
155
|
+
|
156
|
+
index = (sample / max * CHART_CHARS.count).to_i - 1
|
151
157
|
chart += CHART_CHARS[index]
|
152
158
|
chart += " " unless Config.compressed_chart
|
153
159
|
end
|
154
160
|
end
|
155
161
|
|
156
|
-
|
157
|
-
str = "%-#{@longest_display}s %8.1f%s %s" %
|
158
|
-
[conf[:display] || conf[:metric], latest, unit, chart]
|
162
|
+
str += chart
|
159
163
|
str = str[0...Curses.cols]
|
160
164
|
Curses.setpos(i % Curses.lines, 0)
|
161
165
|
Curses.addstr(str)
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Casseo
|
2
|
+
class Runner
|
3
|
+
def self.execute(args)
|
4
|
+
new(args).execute
|
5
|
+
end
|
6
|
+
|
7
|
+
def initialize(args)
|
8
|
+
@args = args
|
9
|
+
@exit_message = nil
|
10
|
+
setup_signals
|
11
|
+
end
|
12
|
+
|
13
|
+
def execute
|
14
|
+
Curses.cbreak # no need for a newline to get type chars
|
15
|
+
Curses.curs_set(1) # invisible
|
16
|
+
Curses.noecho # don't echo character on a getch
|
17
|
+
|
18
|
+
Curses.init_screen
|
19
|
+
|
20
|
+
# fail fast on missing required config
|
21
|
+
Config.required
|
22
|
+
|
23
|
+
load_dashboards
|
24
|
+
|
25
|
+
if @args.count > 0 && File.exists?(File.expand_path(@args.first))
|
26
|
+
eval(File.read(@args.first)).run
|
27
|
+
elsif @args.count > 0 && ["-l", "--list"].include?(@args.first)
|
28
|
+
@exit_message = Dashboard.index.sort.join("\n")
|
29
|
+
elsif @args.first
|
30
|
+
Dashboard.run(@args.first.to_sym)
|
31
|
+
else
|
32
|
+
Dashboard.run(Config.dashboard_default)
|
33
|
+
end
|
34
|
+
rescue ConfigError, DashboardNotFound => e
|
35
|
+
@exit_message = e.message
|
36
|
+
ensure
|
37
|
+
Curses.close_screen
|
38
|
+
puts @exit_message if @exit_message
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def load_dashboards
|
44
|
+
dir = "#{File.expand_path("~")}/.casseo/dashboards"
|
45
|
+
if File.exists?(dir)
|
46
|
+
# clever hack to get symlinks working properly
|
47
|
+
Dir["#{dir}/**{,/*/**}/*.rb"].each do |d|
|
48
|
+
require d
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def setup_signals
|
54
|
+
["TERM", "INT"].each do |s|
|
55
|
+
Signal.trap(s) do
|
56
|
+
@exit_message = "Caught deadly signal"
|
57
|
+
Kernel.exit(0)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/casseo/version.rb
CHANGED
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.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -25,6 +25,7 @@ files:
|
|
25
25
|
- lib/casseo/config.rb
|
26
26
|
- lib/casseo/dashboard.rb
|
27
27
|
- lib/casseo/index.rb
|
28
|
+
- lib/casseo/runner.rb
|
28
29
|
- lib/casseo/version.rb
|
29
30
|
- lib/casseo.rb
|
30
31
|
homepage: https://github.com/brandur/casseo
|