rrd-ffi 0.2.3 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/CHANGELOG.rdoc +8 -0
- data/README.rdoc +3 -2
- data/Rakefile +2 -1
- data/lib/rrd.rb +18 -14
- data/lib/rrd/graph.rb +13 -6
- data/lib/rrd/time_extension.rb +18 -0
- data/lib/rrd/version.rb +1 -1
- data/rrd-ffi.gemspec +9 -6
- data/spec/rrd/base_spec.rb +2 -2
- data/spec/rrd/graph_spec.rb +29 -11
- metadata +47 -16
- data/lib/rrd/ext/fixnum.rb +0 -39
data/.gitignore
CHANGED
data/CHANGELOG.rdoc
CHANGED
@@ -9,6 +9,14 @@
|
|
9
9
|
* TODO: Add memory leak test
|
10
10
|
* TODO: Add tune methods to RRD::Base instance
|
11
11
|
|
12
|
+
== 2010-08-31 version 0.2.5
|
13
|
+
|
14
|
+
* Added support for repeated parameters like --color BACK#FFFFFF --color FONT#000000 (Kamil Grabowski)
|
15
|
+
* Fixed draw lines and areas without :label param (Kamil Grabowski)
|
16
|
+
|
17
|
+
== 2010-07-23 version 0.2.4
|
18
|
+
* Added ActiveSupport to extend Fixnum and Integer time helpers (Wojciech Wnętrzak)
|
19
|
+
|
12
20
|
== 2010-05-18 version 0.2.3
|
13
21
|
* Fixed Bang methods to work with jruby, ruby 1.8.6, ruby 1.9.1
|
14
22
|
|
data/README.rdoc
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
= Introduction
|
1
|
+
= Introduction
|
2
2
|
|
3
3
|
rrd-ffi is a gem for using rrd actions in your ruby code.
|
4
4
|
|
@@ -83,8 +83,9 @@ From source:
|
|
83
83
|
end
|
84
84
|
|
85
85
|
# Generating a graph with memory and cpu usage from myrrd.rrd file
|
86
|
-
RRD.graph "graph.png", :title => "Test", :width => 800, :height => 250 do
|
86
|
+
RRD.graph "graph.png", :title => "Test", :width => 800, :height => 250, :color => ["FONT#000000", "BACK#FFFFFF"] do
|
87
87
|
area "myrrd.rrd", :cpu0 => :average, :color => "#00FF00", :label => "CPU 0"
|
88
|
+
line "myrrd.rrd", :cpu0 => :average, :color => "#007f3f"
|
88
89
|
line "myrrd.rrd", :memory => :average, :color => "#0000FF", :label => "Memory"
|
89
90
|
end
|
90
91
|
|
data/Rakefile
CHANGED
@@ -19,9 +19,10 @@ begin
|
|
19
19
|
gem.description = %Q{Provides bindings for many RRD functions (using ffi gem and librrd), as well as DSLs for graphic and rrd building. You must have librrd in your system!}
|
20
20
|
gem.email = "morellon@gmail.com"
|
21
21
|
gem.homepage = "http://github.com/morellon/rrd-ffi"
|
22
|
-
gem.authors = ["morellon"
|
22
|
+
gem.authors = ["morellon"]
|
23
23
|
gem.add_development_dependency "rspec"
|
24
24
|
gem.add_dependency "ffi"
|
25
|
+
gem.add_dependency "activesupport"
|
25
26
|
end
|
26
27
|
Jeweler::GemcutterTasks.new
|
27
28
|
rescue LoadError
|
data/lib/rrd.rb
CHANGED
@@ -4,42 +4,46 @@ require "rrd/wrapper"
|
|
4
4
|
require "rrd/base"
|
5
5
|
require "rrd/graph"
|
6
6
|
require "rrd/builder"
|
7
|
-
require "rrd/
|
7
|
+
require "rrd/time_extension"
|
8
8
|
|
9
9
|
module RRD
|
10
10
|
extend self
|
11
|
-
|
11
|
+
|
12
12
|
BANG_METHODS = [:graph!]
|
13
|
-
|
13
|
+
|
14
14
|
def graph(image_file, options = {}, &block)
|
15
15
|
graph = Graph.new(image_file, options)
|
16
16
|
graph.instance_eval(&block)
|
17
17
|
graph.save
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def error
|
21
21
|
Wrapper.error
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def to_line_parameters(hash, known_flags = [])
|
25
25
|
used_flags = []
|
26
26
|
known_flags.each do |flag|
|
27
27
|
used_flags << "--#{flag}".gsub(/_/, "-") if hash.delete(flag)
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
line_params = []
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
31
|
+
|
32
|
+
hash.each_pair do |key,value|
|
33
|
+
if value.kind_of? Array
|
34
|
+
value.each {|v| line_params += ["--#{key}".gsub(/_/, "-"), v.to_s]}
|
35
|
+
else
|
36
|
+
line_params += ["--#{key}".gsub(/_/, "-"), value.to_s]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
used_flags + line_params
|
37
41
|
end
|
38
|
-
|
42
|
+
|
39
43
|
def methods
|
40
44
|
super + BANG_METHODS
|
41
45
|
end
|
42
|
-
|
46
|
+
|
43
47
|
def bang(method, *args, &block)
|
44
48
|
result = send(method, *args, &block)
|
45
49
|
raise error unless result
|
data/lib/rrd/graph.rb
CHANGED
@@ -80,19 +80,26 @@ module RRD
|
|
80
80
|
[definition, printable]
|
81
81
|
end
|
82
82
|
|
83
|
-
def save
|
83
|
+
def save
|
84
|
+
Wrapper.graph(*generate_args)
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
def generate_args
|
84
89
|
args = [output]
|
85
90
|
args += RRD.to_line_parameters(parameters, GRAPH_FLAGS)
|
86
91
|
args += definitions
|
87
92
|
args += printables
|
88
|
-
|
89
|
-
Wrapper.graph(*args)
|
90
93
|
end
|
91
94
|
|
92
|
-
private
|
93
95
|
def draw(type, options)
|
94
|
-
|
95
|
-
|
96
|
+
printable = "#{type}:#{options[:data]}#{options[:color]}"
|
97
|
+
|
98
|
+
if options[:label]
|
99
|
+
options[:label] = options[:label].gsub(/^:/, "\\:").gsub(/([^\\]):/, "\\1\\:") # Escape all non-escaped ':'
|
100
|
+
printable += ":#{options[:label]}"
|
101
|
+
end
|
102
|
+
|
96
103
|
printables << printable
|
97
104
|
printable
|
98
105
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'active_support/version'
|
2
|
+
|
3
|
+
if ActiveSupport::VERSION::MAJOR >= 3
|
4
|
+
require 'active_support/core_ext/numeric/time'
|
5
|
+
require 'active_support/core_ext/integer/time'
|
6
|
+
else
|
7
|
+
require 'active_support/duration'
|
8
|
+
require 'active_support/core_ext/numeric/time'
|
9
|
+
require 'active_support/core_ext/integer/time'
|
10
|
+
|
11
|
+
class Numeric
|
12
|
+
include ActiveSupport::CoreExtensions::Numeric::Time
|
13
|
+
end
|
14
|
+
|
15
|
+
class Integer
|
16
|
+
include ActiveSupport::CoreExtensions::Integer::Time
|
17
|
+
end
|
18
|
+
end
|
data/lib/rrd/version.rb
CHANGED
data/rrd-ffi.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rrd-ffi}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["morellon"
|
12
|
-
s.date = %q{2010-
|
11
|
+
s.authors = ["morellon"]
|
12
|
+
s.date = %q{2010-08-31}
|
13
13
|
s.description = %q{Provides bindings for many RRD functions (using ffi gem and librrd), as well as DSLs for graphic and rrd building. You must have librrd in your system!}
|
14
14
|
s.email = %q{morellon@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -24,8 +24,8 @@ Gem::Specification.new do |s|
|
|
24
24
|
"lib/rrd.rb",
|
25
25
|
"lib/rrd/base.rb",
|
26
26
|
"lib/rrd/builder.rb",
|
27
|
-
"lib/rrd/ext/fixnum.rb",
|
28
27
|
"lib/rrd/graph.rb",
|
28
|
+
"lib/rrd/time_extension.rb",
|
29
29
|
"lib/rrd/version.rb",
|
30
30
|
"lib/rrd/wrapper.rb",
|
31
31
|
"rrd-ffi.gemspec",
|
@@ -40,7 +40,7 @@ Gem::Specification.new do |s|
|
|
40
40
|
s.homepage = %q{http://github.com/morellon/rrd-ffi}
|
41
41
|
s.rdoc_options = ["--charset=UTF-8"]
|
42
42
|
s.require_paths = ["lib"]
|
43
|
-
s.rubygems_version = %q{1.3.
|
43
|
+
s.rubygems_version = %q{1.3.7}
|
44
44
|
s.summary = %q{RRDTool gem using librrd and ffi}
|
45
45
|
s.test_files = [
|
46
46
|
"spec/rrd/base_spec.rb",
|
@@ -56,16 +56,19 @@ Gem::Specification.new do |s|
|
|
56
56
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
57
57
|
s.specification_version = 3
|
58
58
|
|
59
|
-
if Gem::Version.new(Gem::
|
59
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
60
60
|
s.add_development_dependency(%q<rspec>, [">= 0"])
|
61
61
|
s.add_runtime_dependency(%q<ffi>, [">= 0"])
|
62
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
62
63
|
else
|
63
64
|
s.add_dependency(%q<rspec>, [">= 0"])
|
64
65
|
s.add_dependency(%q<ffi>, [">= 0"])
|
66
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
65
67
|
end
|
66
68
|
else
|
67
69
|
s.add_dependency(%q<rspec>, [">= 0"])
|
68
70
|
s.add_dependency(%q<ffi>, [">= 0"])
|
71
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
69
72
|
end
|
70
73
|
end
|
71
74
|
|
data/spec/rrd/base_spec.rb
CHANGED
@@ -40,8 +40,8 @@ describe RRD::Base do
|
|
40
40
|
it "should fetch data from rrd file" do
|
41
41
|
start_time = Time.now - 3600
|
42
42
|
end_time = Time.now
|
43
|
-
raw_params = ["AVERAGE", "--
|
44
|
-
RRD::Wrapper.should_receive(:fetch).with(RRD_FILE,
|
43
|
+
raw_params = ["AVERAGE", "--start", "#{start_time.to_i}", "--end", "#{end_time.to_i}", "--resolution", "1" ]
|
44
|
+
RRD::Wrapper.should_receive(:fetch).with(RRD_FILE, raw_params[0], anything, anything, anything, anything, anything, anything).and_return([])
|
45
45
|
@rrd.fetch(:average, :start => start_time, :end => end_time, :resolution => 1.second)
|
46
46
|
end
|
47
47
|
|
data/spec/rrd/graph_spec.rb
CHANGED
@@ -4,7 +4,8 @@ describe RRD::Graph do
|
|
4
4
|
|
5
5
|
before do
|
6
6
|
RRD::Base.new(RRD_FILE).restore(XML_FILE)
|
7
|
-
@graph = RRD::Graph.new IMG_FILE, :title => "Title", :width => 800, :height => 200, :full_size_mode => true
|
7
|
+
@graph = RRD::Graph.new IMG_FILE, :title => "Title", :width => 800, :height => 200, :full_size_mode => true,
|
8
|
+
:color => ["FONT#000000", "BACK#FFFFFF"]
|
8
9
|
end
|
9
10
|
|
10
11
|
it "should store definition for rrd data" do
|
@@ -27,6 +28,11 @@ describe RRD::Graph do
|
|
27
28
|
result.should == "LINE1:mem#0000FF:Memory"
|
28
29
|
end
|
29
30
|
|
31
|
+
it "should store printable for line drawing withou label" do
|
32
|
+
result = @graph.draw_line :data => "mem", :color => "#0000FF", :width => 1
|
33
|
+
result.should == "LINE1:mem#0000FF"
|
34
|
+
end
|
35
|
+
|
30
36
|
it "should store printable for area drawing" do
|
31
37
|
result = @graph.draw_area :data => "cpu", :color => "#00FF00", :label => "CPU 0"
|
32
38
|
result.should == "AREA:cpu#00FF00:CPU 0"
|
@@ -47,6 +53,12 @@ describe RRD::Graph do
|
|
47
53
|
result[0].should == "DEF:memory_average=#{RRD_FILE}:memory:AVERAGE"
|
48
54
|
result[1].should == "LINE1:memory_average#0000FF:Memory\\: Avg"
|
49
55
|
end
|
56
|
+
|
57
|
+
it "should store definition and printable for line (without label)" do
|
58
|
+
result = @graph.line RRD_FILE, :memory => :average, :color => "#0000FF"
|
59
|
+
result[0].should == "DEF:memory_average=#{RRD_FILE}:memory:AVERAGE"
|
60
|
+
result[1].should == "LINE1:memory_average#0000FF"
|
61
|
+
end
|
50
62
|
|
51
63
|
it "should store definition and printable for area" do
|
52
64
|
result = @graph.area RRD_FILE, :memory => :average, :color => "#0000FF", :label => "Memory: Avg"
|
@@ -55,17 +67,23 @@ describe RRD::Graph do
|
|
55
67
|
end
|
56
68
|
|
57
69
|
it "should create a graph correctly" do
|
70
|
+
expected_args = [IMG_FILE,
|
71
|
+
"--full-size-mode",
|
72
|
+
"--color", "FONT#000000",
|
73
|
+
"--color", "BACK#FFFFFF",
|
74
|
+
"--title", "Title",
|
75
|
+
"--start", #starting_time,
|
76
|
+
"--height", "200",
|
77
|
+
"--end", #ending_time,
|
78
|
+
"--width", "800",
|
79
|
+
"DEF:memory_average=#{RRD_FILE}:memory:AVERAGE",
|
80
|
+
"LINE1:memory_average#0000FF:Memory\\: Avg"]
|
58
81
|
@graph.line RRD_FILE, :memory => :average, :color => "#0000FF", :label => "Memory: Avg"
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
"--start", anything(),
|
64
|
-
"--title", "Title",
|
65
|
-
"--width", "800",
|
66
|
-
"DEF:memory_average=#{RRD_FILE}:memory:AVERAGE",
|
67
|
-
"LINE1:memory_average#0000FF:Memory\\: Avg").and_return true
|
68
|
-
@graph.save
|
82
|
+
generated_args = @graph.send(:generate_args)
|
83
|
+
generated_args.size.should == expected_args.size + 2
|
84
|
+
generated_args.first.should == expected_args.first
|
85
|
+
(expected_args - generated_args).should be_empty
|
69
86
|
end
|
87
|
+
|
70
88
|
|
71
89
|
end
|
metadata
CHANGED
@@ -1,40 +1,65 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rrd-ffi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 5
|
10
|
+
version: 0.2.5
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- morellon
|
8
|
-
- fnando
|
9
|
-
- rafaelrosafu
|
10
|
-
- dalcico
|
11
14
|
autorequire:
|
12
15
|
bindir: bin
|
13
16
|
cert_chain: []
|
14
17
|
|
15
|
-
date: 2010-
|
18
|
+
date: 2010-08-31 00:00:00 -03:00
|
16
19
|
default_executable:
|
17
20
|
dependencies:
|
18
21
|
- !ruby/object:Gem::Dependency
|
19
22
|
name: rspec
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
27
|
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
26
32
|
version: "0"
|
27
|
-
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
28
35
|
- !ruby/object:Gem::Dependency
|
29
36
|
name: ffi
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
30
47
|
type: :runtime
|
31
|
-
|
32
|
-
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: activesupport
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
33
54
|
requirements:
|
34
55
|
- - ">="
|
35
56
|
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
36
60
|
version: "0"
|
37
|
-
|
61
|
+
type: :runtime
|
62
|
+
version_requirements: *id003
|
38
63
|
description: Provides bindings for many RRD functions (using ffi gem and librrd), as well as DSLs for graphic and rrd building. You must have librrd in your system!
|
39
64
|
email: morellon@gmail.com
|
40
65
|
executables: []
|
@@ -52,8 +77,8 @@ files:
|
|
52
77
|
- lib/rrd.rb
|
53
78
|
- lib/rrd/base.rb
|
54
79
|
- lib/rrd/builder.rb
|
55
|
-
- lib/rrd/ext/fixnum.rb
|
56
80
|
- lib/rrd/graph.rb
|
81
|
+
- lib/rrd/time_extension.rb
|
57
82
|
- lib/rrd/version.rb
|
58
83
|
- lib/rrd/wrapper.rb
|
59
84
|
- rrd-ffi.gemspec
|
@@ -74,21 +99,27 @@ rdoc_options:
|
|
74
99
|
require_paths:
|
75
100
|
- lib
|
76
101
|
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
77
103
|
requirements:
|
78
104
|
- - ">="
|
79
105
|
- !ruby/object:Gem::Version
|
106
|
+
hash: 3
|
107
|
+
segments:
|
108
|
+
- 0
|
80
109
|
version: "0"
|
81
|
-
version:
|
82
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
83
112
|
requirements:
|
84
113
|
- - ">="
|
85
114
|
- !ruby/object:Gem::Version
|
115
|
+
hash: 3
|
116
|
+
segments:
|
117
|
+
- 0
|
86
118
|
version: "0"
|
87
|
-
version:
|
88
119
|
requirements: []
|
89
120
|
|
90
121
|
rubyforge_project:
|
91
|
-
rubygems_version: 1.3.
|
122
|
+
rubygems_version: 1.3.7
|
92
123
|
signing_key:
|
93
124
|
specification_version: 3
|
94
125
|
summary: RRDTool gem using librrd and ffi
|
data/lib/rrd/ext/fixnum.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
#TODO: Change to ActiveSupport from Rails 3
|
2
|
-
class Fixnum
|
3
|
-
def second
|
4
|
-
self
|
5
|
-
end
|
6
|
-
alias :seconds :second
|
7
|
-
|
8
|
-
def minute
|
9
|
-
second * 60
|
10
|
-
end
|
11
|
-
alias :minutes :minute
|
12
|
-
|
13
|
-
def hour
|
14
|
-
minute * 60
|
15
|
-
end
|
16
|
-
alias :hours :hour
|
17
|
-
|
18
|
-
def day
|
19
|
-
hour * 24
|
20
|
-
end
|
21
|
-
alias :days :day
|
22
|
-
|
23
|
-
def week
|
24
|
-
day * 7
|
25
|
-
end
|
26
|
-
alias :weeks :week
|
27
|
-
|
28
|
-
def month
|
29
|
-
day * 30
|
30
|
-
end
|
31
|
-
alias :months :month
|
32
|
-
|
33
|
-
def year
|
34
|
-
day * 365
|
35
|
-
end
|
36
|
-
alias :years :year
|
37
|
-
end
|
38
|
-
|
39
|
-
|