prrd 0.2.0

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.
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # File: hrule.rb
4
+ # Time-stamp: <2014-10-01 21:15:13 pierre>
5
+ # Copyright (C) 2014 Pierre Lecocq
6
+ # Description: Hrul class for PRRD
7
+
8
+ module PRRD
9
+ class Graph
10
+ # PRRD Graph Hrule class
11
+ class Hrule < PRRD::Entity
12
+ # Constructor
13
+ def initialize(values = nil)
14
+ @keys = [
15
+ :value,
16
+ :color,
17
+ :legend,
18
+ :dashes,
19
+ :dashes_offset
20
+ ]
21
+
22
+ super values
23
+ end
24
+
25
+ # Transform to a HRULE formatted string
26
+ def to_s
27
+ fail 'Empty hrule object' if @data.empty?
28
+
29
+ validate_presence :value, :color
30
+
31
+ chunks = []
32
+
33
+ @keys.each do |k|
34
+ next unless @data.key?(k)
35
+ case k
36
+ when :value
37
+ chunks << "HRULE:%s%s" % [@data[k], @data[:color]]
38
+ when :dashes
39
+ chunks << "dashes=\"%s\"" % @data[k]
40
+ when :dashes_offset
41
+ chunks << "dashes-offset=\"%s\"" % @data[k]
42
+ when :color
43
+ # nope
44
+ else
45
+ chunks << @data[k]
46
+ end
47
+ end
48
+
49
+ chunks.join ':'
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,53 @@
1
+ # File: line.rb
2
+ # Time-stamp: <2014-10-01 21:16:41 pierre>
3
+ # Copyright (C) 2014 Pierre Lecocq
4
+ # Description: Line class for PRRD
5
+
6
+ module PRRD
7
+ class Graph
8
+ # PRRD Graph Line class
9
+ class Line < PRRD::Entity
10
+ # Constructor
11
+ def initialize(values = nil)
12
+ @keys = [
13
+ :value,
14
+ :width,
15
+ :color,
16
+ :legend,
17
+ :stack
18
+ ]
19
+
20
+ super values
21
+ end
22
+
23
+ # Transform to a LINE formatted string
24
+ def to_s
25
+ fail 'Empty line object' if @data.empty?
26
+
27
+ @data[:width] ||= 1
28
+
29
+ validate_presence :value
30
+
31
+ chunks = []
32
+
33
+ @keys.each do |k|
34
+ next unless @data.key?(k)
35
+ case k
36
+ when :value
37
+ chunks << "LINE%s:%s%s" % [@data[:width], @data[k], @data[:color]]
38
+ when :width, :color
39
+ # nope
40
+ when :legend
41
+ chunks << "\"%s\"" % @data[k]
42
+ when :stack
43
+ chunks << "STACK"
44
+ else
45
+ chunks << @data[k]
46
+ end
47
+ end
48
+
49
+ chunks.join ':'
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,48 @@
1
+ # File: print.rb
2
+ # Time-stamp: <2014-10-01 21:17:17 pierre>
3
+ # Copyright (C) 2014 Pierre Lecocq
4
+ # Description: Print class for PRRD
5
+
6
+ module PRRD
7
+ class Graph
8
+ # PRRD Graph Line class
9
+ class Print < PRRD::Entity
10
+ # Constructor
11
+ def initialize(values = nil)
12
+ @keys = [
13
+ :gprint,
14
+ :vname,
15
+ :cf,
16
+ :format,
17
+ :strftime
18
+ ]
19
+
20
+ super values
21
+ end
22
+
23
+ # Transform to a PRINT formatted string
24
+ def to_s
25
+ fail 'Empty print object' if @data.empty?
26
+
27
+ validate_presence :vname, :cf, :format
28
+
29
+ @data[:grpint] ||= false
30
+
31
+ chunks = []
32
+
33
+ if @data.key?(:gprint) && @data[:gprint] == true
34
+ chunks << 'GPRINT'
35
+ else
36
+ chunks << 'PRINT'
37
+ end
38
+
39
+ chunks << @data[:vname]
40
+ chunks << @data[:cf]
41
+ chunks << @data[:format]
42
+ chunks << @data[:strftime] if @data.key?(:strftime)
43
+
44
+ chunks.join ':'
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,30 @@
1
+ # File: shift.rb
2
+ # Time-stamp: <2014-10-01 21:17:51 pierre>
3
+ # Copyright (C) 2014 Pierre Lecocq
4
+ # Description: Shift class for PRRD
5
+
6
+ module PRRD
7
+ class Graph
8
+ # PRRD Shift Line class
9
+ class Shift < PRRD::Entity
10
+ # Constructor
11
+ def initialize(values = nil)
12
+ @keys = [
13
+ :vname,
14
+ :offset
15
+ ]
16
+
17
+ super values
18
+ end
19
+
20
+ # Transform to a SHIFT formatted string
21
+ def to_s
22
+ fail 'Empty shift object' if @data.empty?
23
+
24
+ validate_presence :vname, :offset
25
+
26
+ "SHIFT:%s:%s" % [@data[:vname], @data[:offset]]
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,32 @@
1
+ # File: textalign.rb
2
+ # Time-stamp: <2014-10-01 21:18:12 pierre>
3
+ # Copyright (C) 2014 Pierre Lecocq
4
+ # Description: Textalign class for PRRD
5
+
6
+ module PRRD
7
+ class Graph
8
+ # PRRD Textalign Line class
9
+ class Textalign < PRRD::Entity
10
+ # Constructor
11
+ def initialize(values = nil)
12
+ @keys = [
13
+ :orientation
14
+ ]
15
+
16
+ super values
17
+ end
18
+
19
+ # Transform to a TEXTALIGN formatted string
20
+ def to_s
21
+ fail 'Empty textalign object' if @data.empty?
22
+
23
+ validate_presence :orientation
24
+ unless ['left', 'right', 'justified', 'center'].include? @data[:orientation].to_s
25
+ fail 'Orientation option muts be: left|right|justified|center'
26
+ end
27
+
28
+ "TEXTALIGN:\"%s\"" % @data[:orientation]
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,51 @@
1
+ # File: vrule.rb
2
+ # Time-stamp: <2014-10-01 21:19:19 pierre>
3
+ # Copyright (C) 2014 Pierre Lecocq
4
+ # Description: Hrul class for PRRD
5
+
6
+ module PRRD
7
+ class Graph
8
+ # PRRD Graph Vrule class
9
+ class Vrule < PRRD::Entity
10
+ # Constructor
11
+ def initialize(values = nil)
12
+ @keys = [
13
+ :time,
14
+ :color,
15
+ :legend,
16
+ :dashes,
17
+ :dashes_offset
18
+ ]
19
+
20
+ super values
21
+ end
22
+
23
+ # Transform to a VRULE formatted string
24
+ def to_s
25
+ fail 'Empty vrule object' if @data.empty?
26
+
27
+ validate_presence :time, :color
28
+
29
+ chunks = []
30
+
31
+ @keys.each do |k|
32
+ next unless @data.key?(k)
33
+ case k
34
+ when :time
35
+ chunks << "VRULE:%s%s" % [@data[k], @data[:color]]
36
+ when :color
37
+ # nope
38
+ when :dashes
39
+ chunks << "dashes=\"%s\"" % @data[k]
40
+ when :dashes_offset
41
+ chunks << "dashes-offset=\"%s\"" % @data[k]
42
+ else
43
+ chunks << @data[k]
44
+ end
45
+ end
46
+
47
+ chunks.join ':'
48
+ end
49
+ end
50
+ end
51
+ end
data/prrd.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # File: prrd.gemspec
2
+ # Time-stamp: <2015-07-13 10:48:12>
3
+ # Copyright (C) 2014 Pierre Lecocq
4
+ # Description: rrdtool ruby interface
5
+
6
+ require File.expand_path('../lib/prrd', __FILE__)
7
+
8
+ Gem::Specification.new do |gem|
9
+ gem.name = 'prrd'
10
+ gem.require_paths = ['lib']
11
+ gem.version = PRRD::VERSION
12
+ gem.files =
13
+ %w(README.md Gemfile Rakefile showcase.rb prrd.gemspec) +
14
+ `git ls-files lib spec`.split("\n")
15
+
16
+ gem.authors = ['Pierre Lecocq']
17
+ gem.email = ['pierre.lecocq@gmail.com']
18
+ gem.summary = 'rrdtool ruby interface'
19
+ gem.description = 'Graph your system with rrdtool in ruby'
20
+ gem.homepage = 'https://github.com/pierre-lecocq/prrd'
21
+ gem.date = Date.today.to_s
22
+ gem.license = 'MIT'
23
+ end
data/showcase.rb ADDED
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # File: showcase.rb
4
+ # Time-stamp: <2014-10-01 22:42:11 pierre>
5
+ # Copyright (C) 2014 Pierre Lecocq
6
+ # Description: Showcase
7
+
8
+ require_relative 'lib/prrd'
9
+
10
+ create = false
11
+
12
+ PRRD.activate_debug_mode
13
+
14
+ dbpath = '/home/pierre/rrd/showcase.rrd'
15
+ imgpath = '/home/pierre/rrd/showcase.png'
16
+ start_ts = Time.now.to_i - 86_400
17
+
18
+ if create
19
+ begin
20
+ File.delete dbpath, imgpath
21
+ rescue Exception
22
+ puts 'Nothing to delete, but we do not care'
23
+ end
24
+ end
25
+
26
+ # Db :: init
27
+
28
+ database = PRRD::Database.new({path: dbpath, start: start_ts, step: 300})
29
+
30
+ if create
31
+
32
+ database.add_datasources [
33
+ PRRD::Database::Datasource.new({name: 'ds1', type: 'GAUGE', heartbeat: 600, min: 0, max: 'U'}),
34
+ PRRD::Database::Datasource.new({name: 'ds2', type: 'GAUGE', heartbeat: 600, min: 0, max: 'U'}),
35
+ PRRD::Database::Datasource.new({name: 'ds3', type: 'GAUGE', heartbeat: 600, min: 0, max: 'U'})
36
+ ]
37
+
38
+ database.add_archives [
39
+ PRRD::Database::Archive.new({cf: 'AVERAGE', xff: 0.5, steps: 1, rows: 576}),
40
+ PRRD::Database::Archive.new({cf: 'AVERAGE', xff: 0.5, steps: 6, rows: 672}),
41
+ PRRD::Database::Archive.new({cf: 'AVERAGE', xff: 0.5, steps: 24, rows: 732}),
42
+ PRRD::Database::Archive.new({cf: 'AVERAGE', xff: 0.5, steps: 144, rows: 1460})
43
+ ]
44
+
45
+ database.create
46
+
47
+ # Db :: update
48
+
49
+ now_ts = Time.now.to_i
50
+ update_ts = start_ts + 1
51
+ while update_ts < now_ts
52
+ value1 = Random.rand(200)
53
+ value2 = Random.rand(80)
54
+ value3 = Random.rand(150)
55
+
56
+ database.update update_ts, value1, value2, value3
57
+
58
+ update_ts += 1
59
+ end
60
+
61
+ end
62
+
63
+ # Graph :: init
64
+
65
+ graph = PRRD::Graph.new({path: imgpath, database: database, width: 1024, height: 768, title: 'Showcase', lower_limit: 0, upper_limit: 200})
66
+
67
+ graph.add_colors [
68
+ PRRD::Graph::Color.new({colortag: 'BACK', color: '#222222'}),
69
+ PRRD::Graph::Color.new({colortag: 'FONT', color: '#777777'}),
70
+ PRRD::Graph::Color.new({colortag: 'CANVAS', color: '#222222'}),
71
+ PRRD::Graph::Color.new({colortag: 'ARROW', color: '#00ff00'}),
72
+ PRRD::Graph::Color.new({colortag: 'GRID', color: '#444444'}),
73
+ PRRD::Graph::Color.new({colortag: 'MGRID', color: '#333333'}),
74
+ ]
75
+
76
+ graph.add_definitions [
77
+ PRRD::Graph::Definition.new({vname: 'ds1', rrdfile: database.path, ds_name: 'ds1', cf: 'AVERAGE'}),
78
+ PRRD::Graph::Definition.new({vname: 'ds2', rrdfile: database.path, ds_name: 'ds2', cf: 'AVERAGE'}),
79
+ PRRD::Graph::Definition.new({vname: 'ds3', rrdfile: database.path, ds_name: 'ds3', cf: 'AVERAGE'})
80
+ ]
81
+
82
+ graph.add_comment PRRD::Graph::Comment.new({text: "This is a comment"})
83
+
84
+ graph.add_print PRRD::Graph::Print.new({gprint: true, vname: 'ds1', cf: 'AVERAGE', format: "%3.3le"})
85
+ graph.add_print PRRD::Graph::Print.new({gprint: true, vname: 'ds2', cf: 'AVERAGE', format: "%3.3le"})
86
+
87
+ color1 = PRRD::Color.new(:blue)
88
+ color2 = PRRD::Color.new(:blue, :dark)
89
+ color3 = PRRD::Color.new(:red)
90
+
91
+ graph.add_areas [
92
+ PRRD::Graph::Area.new({value: 'ds1', color: color1, legend: 'Ds1'}),
93
+ PRRD::Graph::Area.new({value: 'ds2', color: color2, legend: 'Ds2'})
94
+ ]
95
+
96
+ graph.add_lines [
97
+ PRRD::Graph::Line.new({width: 1, value: 'ds1', color: color1.lighten(50), legend: 'Ds1'}),
98
+ PRRD::Graph::Line.new({width: 1, value: 'ds2', color: color2.lighten(50), legend: 'Ds2'}),
99
+ PRRD::Graph::Line.new({width: 2, value: 'ds3', color: color3, legend: 'Ds3'})
100
+ ]
101
+
102
+ # Graph :: Generate
103
+
104
+ graph.generate
data/spec/prrd_spec.rb ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # File: prrd_spec.rb
4
+ # Time-stamp: <2014-09-22 22:44:14 pierre>
5
+ # Copyright (C) 2014 Pierre Lecocq
6
+ # Description: PRRD spec file
7
+
8
+ require_relative '../lib/prrd'
9
+ describe PRRD do
10
+ describe 'VERSION' do
11
+ it 'should return 0.2.0' do
12
+ expect(PRRD::VERSION).to eql '0.2.0'
13
+ end
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: prrd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Pierre Lecocq
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-13 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Graph your system with rrdtool in ruby
14
+ email:
15
+ - pierre.lecocq@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - README.md
21
+ - Gemfile
22
+ - Rakefile
23
+ - showcase.rb
24
+ - prrd.gemspec
25
+ - lib/prrd.rb
26
+ - lib/prrd/database.rb
27
+ - lib/prrd/database/archive.rb
28
+ - lib/prrd/database/datasource.rb
29
+ - lib/prrd/graph.rb
30
+ - lib/prrd/graph/area.rb
31
+ - lib/prrd/graph/colors.rb
32
+ - lib/prrd/graph/comment.rb
33
+ - lib/prrd/graph/definition.rb
34
+ - lib/prrd/graph/hrule.rb
35
+ - lib/prrd/graph/line.rb
36
+ - lib/prrd/graph/print.rb
37
+ - lib/prrd/graph/shift.rb
38
+ - lib/prrd/graph/textalign.rb
39
+ - lib/prrd/graph/vrule.rb
40
+ - spec/prrd_spec.rb
41
+ homepage: https://github.com/pierre-lecocq/prrd
42
+ licenses:
43
+ - MIT
44
+ metadata: {}
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 2.0.14
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: rrdtool ruby interface
65
+ test_files: []