tplot 0.0.1 → 0.0.2
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/.gitignore +1 -0
- data/bin/tplot +12 -3
- data/lib/tplot/bar_chart.rb +3 -0
- data/lib/tplot/plugin.rb +0 -4
- data/lib/tplot/version.rb +1 -1
- data/lib/tplot.rb +1 -1
- data/plugins/free.rb +4 -3
- data/plugins/help.rb +24 -0
- data/plugins/list.rb +17 -6
- data/plugins/network.rb +19 -0
- data/plugins/uptime.rb +27 -4
- metadata +3 -2
- data/log/debug.log +0 -536758
data/bin/tplot
CHANGED
@@ -6,7 +6,14 @@ trap(:INT) do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
BASE_DIR = File.expand_path(__FILE__.gsub(%r{/[^/]+\z},'') + "/../")
|
9
|
-
plugin_name = ARGV.
|
9
|
+
plugin_name = ARGV.shift
|
10
|
+
plugin_name ||= "list"
|
11
|
+
|
12
|
+
PLUGIN_DIR = "#{BASE_DIR}/plugins"
|
13
|
+
USER_PLUGIN_DIR = "#{ENV['HOME']}/.tplot/plugins"
|
14
|
+
|
15
|
+
require 'fileutils'
|
16
|
+
FileUtils.mkdir_p(USER_PLUGIN_DIR)
|
10
17
|
|
11
18
|
# debug setting
|
12
19
|
require 'logger'
|
@@ -18,13 +25,15 @@ else
|
|
18
25
|
end
|
19
26
|
|
20
27
|
# plugin check
|
21
|
-
|
28
|
+
if(!File.exists?("#{PLUGIN_DIR}/#{plugin_name}.rb") and
|
29
|
+
!File.exists?("#{USER_PLUGIN_DIR}/#{plugin_name}.rb"))
|
22
30
|
puts "#{plugin_name} plugin is not found."
|
23
31
|
puts
|
24
32
|
plugin_name = "list"
|
25
33
|
end
|
26
34
|
|
27
35
|
# load basic module
|
36
|
+
require 'optparse'
|
28
37
|
require 'curses'
|
29
38
|
require "#{BASE_DIR}/lib/tplot"
|
30
39
|
require "#{BASE_DIR}/lib/tplot/plugin"
|
@@ -34,4 +43,4 @@ require "#{BASE_DIR}/lib/tplot/bar_chart"
|
|
34
43
|
# execute plugin
|
35
44
|
require "#{BASE_DIR}/plugins/#{plugin_name}"
|
36
45
|
plugin_class = Tplot.const_get(plugin_name.capitalize)
|
37
|
-
plugin_class.new
|
46
|
+
plugin_class.new.execute
|
data/lib/tplot/bar_chart.rb
CHANGED
@@ -89,13 +89,16 @@ module Tplot
|
|
89
89
|
|
90
90
|
def calc_mapping_value(value)
|
91
91
|
range = (@max_value - @min_value).abs
|
92
|
+
return 0 if range == 0
|
92
93
|
ratio = (value - @min_value).abs.to_f / range.to_f
|
93
94
|
(@height * ratio * 2).to_i
|
94
95
|
end
|
95
96
|
|
96
97
|
def calc_position(value)
|
97
98
|
range = (@max_value - @min_value).abs
|
99
|
+
return 0 if range == 0
|
98
100
|
ratio = (value - @min_value).abs.to_f / range.to_f
|
101
|
+
LOGGER.debug "#{range}:#{ratio}"
|
99
102
|
(@height * (1 - ratio)).to_i
|
100
103
|
end
|
101
104
|
|
data/lib/tplot/plugin.rb
CHANGED
data/lib/tplot/version.rb
CHANGED
data/lib/tplot.rb
CHANGED
data/plugins/free.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
class Tplot::Free < Tplot::Plugin
|
2
2
|
|
3
|
-
description "plot free commands result"
|
4
|
-
|
5
3
|
def execute
|
6
4
|
chart = Tplot::BarChart.new
|
7
|
-
chart.labels =
|
5
|
+
chart.labels = [" total ", " used "]
|
8
6
|
|
9
7
|
while true
|
10
8
|
uptime = `free | grep Mem`.gsub(/^Mem:/, "").split(" ").map{|v| v.strip.to_f}
|
@@ -12,4 +10,7 @@ class Tplot::Free < Tplot::Plugin
|
|
12
10
|
sleep 1
|
13
11
|
end
|
14
12
|
end
|
13
|
+
|
14
|
+
description "plot free commands result"
|
15
|
+
help "Usage: tplot free"
|
15
16
|
end
|
data/plugins/help.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
class Tplot::Help < Tplot::Plugin
|
2
|
+
|
3
|
+
description "print plugins help."
|
4
|
+
|
5
|
+
def execute
|
6
|
+
plugin_name = ARGV.shift
|
7
|
+
if File.exists?("#{PLUGIN_DIR}/#{plugin_name}.rb")
|
8
|
+
print_help("#{PLUGIN_DIR}/#{plugin_name}.rb", PLUGIN_DIR)
|
9
|
+
exit 0
|
10
|
+
end
|
11
|
+
if File.exists?("#{USER_PLUGIN_DIR}/#{plugin_name}.rb")
|
12
|
+
print_help("#{PLUGIN_DIR}/#{plugin_name}.rb", USER_PLUGIN_DIR)
|
13
|
+
exit 0
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def print_help(plugin_path, dir)
|
18
|
+
require plugin_path
|
19
|
+
name = plugin_path.gsub("#{dir}/", '').gsub(".rb", '')
|
20
|
+
plugin_class = Tplot.const_get(name.capitalize)
|
21
|
+
return puts plugin_class.help.call if plugin_class.help.is_a? Proc
|
22
|
+
return puts plugin_class.help
|
23
|
+
end
|
24
|
+
end
|
data/plugins/list.rb
CHANGED
@@ -3,12 +3,23 @@ class Tplot::List < Tplot::Plugin
|
|
3
3
|
description "list installed plugins."
|
4
4
|
|
5
5
|
def execute
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
plugin_class = Tplot.const_get(name.capitalize)
|
11
|
-
puts "tplot #{name}\t: #{plugin_class.description}"
|
6
|
+
# builtin plugin.
|
7
|
+
puts "-- builtin plugins --"
|
8
|
+
Dir.glob("#{PLUGIN_DIR}/*.rb").each do |plugin|
|
9
|
+
puts_description(plugin, PLUGIN_DIR)
|
12
10
|
end
|
11
|
+
|
12
|
+
# user plugin.
|
13
|
+
puts "\n-- user plugins --" unless Dir.glob("#{USER_PLUGIN_DIR}/*.rb").empty?
|
14
|
+
Dir.glob("#{USER_PLUGIN_DIR}/*.rb").each do |plugin|
|
15
|
+
puts_description(plugin, USER_PLUGIN_DIR)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def puts_description(plugin, dir)
|
20
|
+
require plugin
|
21
|
+
name = plugin.gsub("#{dir}/", '').gsub(".rb", '')
|
22
|
+
plugin_class = Tplot.const_get(name.capitalize)
|
23
|
+
puts "tplot #{name}\t: #{plugin_class.description}"
|
13
24
|
end
|
14
25
|
end
|
data/plugins/network.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
class Tplot::Network < Tplot::Plugin
|
2
|
+
|
3
|
+
def execute
|
4
|
+
chart = Tplot::BarChart.new
|
5
|
+
chart.labels = %w(InOctets OutOctets)
|
6
|
+
|
7
|
+
while true
|
8
|
+
values = `cat /proc/net/netstat | tail -n 1 | cut -d" " -f8,9`.split(" ").map{|v| v.strip.to_f}
|
9
|
+
inoctet ||= values.first
|
10
|
+
outoctet ||= values.last
|
11
|
+
chart.add([values.first - inoctet, values.last - outoctet])
|
12
|
+
inoctet, outoctet = values.first, values.last
|
13
|
+
sleep 1
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
description "plot InOctets/OutOctets"
|
18
|
+
help "Usage: tplot network"
|
19
|
+
end
|
data/plugins/uptime.rb
CHANGED
@@ -1,15 +1,38 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
1
2
|
class Tplot::Uptime < Tplot::Plugin
|
2
3
|
|
3
|
-
|
4
|
+
def initialize
|
5
|
+
@options = {
|
6
|
+
chart_type: Tplot::BarChart,
|
7
|
+
delay: 1
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
def parser
|
12
|
+
OptionParser.new do |opt|
|
13
|
+
opt.banner = "Usage: tplot uptime [options]\n"
|
14
|
+
opt.on('-l', '--line','line chart.') do
|
15
|
+
@options[:chart_type] = Tplot::LineChart
|
16
|
+
end
|
17
|
+
opt.on('-n N', '--delay=N', 'set interval.') do |n|
|
18
|
+
@options[:delay] = n.to_i
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
4
22
|
|
5
23
|
def execute
|
6
|
-
|
7
|
-
|
24
|
+
parser.parse!(ARGV)
|
25
|
+
|
26
|
+
chart = @options[:chart_type].new
|
27
|
+
chart.labels = [" 1min ", " 5min ", " 15min "]
|
8
28
|
|
9
29
|
while true
|
10
30
|
uptime = `uptime`.gsub(/^.*load average: /, "").split(",").map{|v| v.strip.to_f}
|
11
31
|
chart.add(uptime)
|
12
|
-
sleep
|
32
|
+
sleep @options[:delay]
|
13
33
|
end
|
14
34
|
end
|
35
|
+
|
36
|
+
description "plot uptime commands result"
|
37
|
+
help self.new.parser.to_s
|
15
38
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tplot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -31,9 +31,10 @@ files:
|
|
31
31
|
- lib/tplot/line_chart.rb
|
32
32
|
- lib/tplot/plugin.rb
|
33
33
|
- lib/tplot/version.rb
|
34
|
-
- log/debug.log
|
35
34
|
- plugins/free.rb
|
35
|
+
- plugins/help.rb
|
36
36
|
- plugins/list.rb
|
37
|
+
- plugins/network.rb
|
37
38
|
- plugins/uptime.rb
|
38
39
|
- tplot.gemspec
|
39
40
|
homepage: https://github.com/mitoma/tplot
|