impulse 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.rdoc +124 -0
- data/Rakefile +2 -0
- data/impulse.gemspec +21 -0
- data/lib/impulse/version.rb +3 -0
- data/lib/impulse.rb +84 -0
- metadata +72 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
= impulse
|
2
|
+
|
3
|
+
* http://github.com/lloydpick/impulse
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
RubyGem to help generate & maintain RRDTool graphs
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* Ability to create and push data into RRD files with multiple data sources
|
12
|
+
* Ability to draw graphs based on multiple RRD files with multiple data sources
|
13
|
+
|
14
|
+
== SYNOPSIS:
|
15
|
+
|
16
|
+
Require and initialize the gem
|
17
|
+
|
18
|
+
require 'impulse'
|
19
|
+
imp = Impulse::Graph.new
|
20
|
+
|
21
|
+
Lets push some data into an RRD file, it will be created if it doesn't exist...
|
22
|
+
|
23
|
+
imp.push("elb_eu_west", 5000)
|
24
|
+
|
25
|
+
We'll now have an RRD file named 'elb_eu_west' and it will contain a data source called 'data'
|
26
|
+
|
27
|
+
To draw a graph based on this data...
|
28
|
+
|
29
|
+
imp.draw("elb_eu_west", :hour, { :filename => 'elb_eu_west_hour.png', :title => 'ELB Requests - Last Hour', :vertical => 'Requests' })
|
30
|
+
|
31
|
+
We specify the name of the RRD file, the time duration we want, it can be...
|
32
|
+
|
33
|
+
:hour
|
34
|
+
:day
|
35
|
+
:week
|
36
|
+
:month
|
37
|
+
:year
|
38
|
+
|
39
|
+
...or any value in seconds.
|
40
|
+
|
41
|
+
Then some various other graphical options.
|
42
|
+
|
43
|
+
|
44
|
+
If we want to have more than one data source in the RRD file, we can do that too...
|
45
|
+
|
46
|
+
imp.push("data_in_out", { :in => 50, :out => 20 })
|
47
|
+
|
48
|
+
We will now have a 'data_in_out.rrd' file and it will contain 2 data sources named 'in' and 'out'
|
49
|
+
|
50
|
+
To draw a graph with two data sources...
|
51
|
+
|
52
|
+
imp.draw(
|
53
|
+
{
|
54
|
+
'In' => { :name => "data_in_out", :data => :in, :color => '#000000' },
|
55
|
+
'Out' => { :name => "data_in_out", :data => :out }
|
56
|
+
},
|
57
|
+
:hour,
|
58
|
+
{
|
59
|
+
:filename => 'data_in_out.png',
|
60
|
+
:title => 'In/Out - Last Hour',
|
61
|
+
:vertical => 'Data'
|
62
|
+
}
|
63
|
+
)
|
64
|
+
|
65
|
+
Simply need to specify the different data sources within a hash, since we provide the name of the file we can combine multiple files...
|
66
|
+
|
67
|
+
imp.draw(
|
68
|
+
{
|
69
|
+
'In' => { :name => "data_in_out", :data => :in, :color => '#000000' },
|
70
|
+
'Out' => { :name => "data_in_out", :data => :out },
|
71
|
+
'Requests' => { :name => "elb_eu_west" }
|
72
|
+
},
|
73
|
+
:hour,
|
74
|
+
{
|
75
|
+
:filename => 'data_in_out_elb.png',
|
76
|
+
:title => 'In/Out + ELB - Last Hour',
|
77
|
+
:vertical => 'Data'
|
78
|
+
}
|
79
|
+
)
|
80
|
+
|
81
|
+
Note that it will attempt to guess as much of the options as it can, as you can see we didn't have to tell it the name of the data source for the 'elb_eu_west' RRD file.
|
82
|
+
|
83
|
+
== PARAMS:
|
84
|
+
|
85
|
+
Default parameters...
|
86
|
+
|
87
|
+
:filename => 'impuse.png',
|
88
|
+
:height => 200,
|
89
|
+
:width => 600,
|
90
|
+
:title => 'Impuse Graph',
|
91
|
+
:vertical => '',
|
92
|
+
:legend => ''
|
93
|
+
|
94
|
+
All can be configured on a per graph basis.
|
95
|
+
|
96
|
+
|
97
|
+
== INSTALL:
|
98
|
+
|
99
|
+
gem install impulse
|
100
|
+
|
101
|
+
== LICENSE:
|
102
|
+
|
103
|
+
(The MIT License)
|
104
|
+
|
105
|
+
Copyright (c) 2010 Lloyd Pick
|
106
|
+
|
107
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
108
|
+
a copy of this software and associated documentation files (the
|
109
|
+
'Software'), to deal in the Software without restriction, including
|
110
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
111
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
112
|
+
permit persons to whom the Software is furnished to do so, subject to
|
113
|
+
the following conditions:
|
114
|
+
|
115
|
+
The above copyright notice and this permission notice shall be
|
116
|
+
included in all copies or substantial portions of the Software.
|
117
|
+
|
118
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
119
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
120
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
121
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
122
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
123
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
124
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/impulse.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "impulse/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "impulse"
|
7
|
+
s.version = Impulse::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Lloyd Pick"]
|
10
|
+
s.email = ["lloydpick+impulse@gmail.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{RubyGem to help make very quick RRDTool graphs}
|
13
|
+
s.description = %q{Ability to make RRDTool graphs with zero thought}
|
14
|
+
|
15
|
+
s.rubyforge_project = "impulse"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
end
|
data/lib/impulse.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
module Impulse
|
2
|
+
class Graph
|
3
|
+
attr_reader :debug
|
4
|
+
|
5
|
+
def initialize(debug = false)
|
6
|
+
@debug = debug
|
7
|
+
end
|
8
|
+
|
9
|
+
def push(name, datas, params = {})
|
10
|
+
create_or_find_rrd(name, datas)
|
11
|
+
push_to_rrd(name, datas)
|
12
|
+
end
|
13
|
+
|
14
|
+
def draw(name, time_scale = :day, params = {})
|
15
|
+
params = {
|
16
|
+
:filename => 'impuse.png',
|
17
|
+
:height => 200,
|
18
|
+
:width => 600,
|
19
|
+
:title => 'Impuse Graph',
|
20
|
+
:vertical => '',
|
21
|
+
:legend => ''
|
22
|
+
}.merge(params)
|
23
|
+
|
24
|
+
defaults = "-E -W 'Generated at #{Time.at(Time.now)}' -e now -h #{params[:height]} -w #{params[:width]}"
|
25
|
+
cmd = ["rrdtool graph #{params[:filename]} -s -#{seconds_for(time_scale)} #{defaults} -t '#{params[:title]}' -v '#{params[:vertical]}'"]
|
26
|
+
|
27
|
+
if name.is_a?(Hash)
|
28
|
+
c = 0
|
29
|
+
name.each do |k,v|
|
30
|
+
v = { :color => '#FF0000', :data => :data }.merge(v)
|
31
|
+
cmd << "DEF:d#{c}=./#{v[:name]}.rrd:#{v[:data].to_s}:MAX"
|
32
|
+
cmd << "LINE1:d#{c}#{v[:color]}:'#{k}' GPRINT:d#{c}:LAST:\"Last\\:%8.0lf\" GPRINT:d#{c}:MIN:\" Min\\:%8.0lf\" GPRINT:d#{c}:AVERAGE:\" Avg\\:%8.0lf\" GPRINT:d#{c}:MAX:\" Max\\:%8.0lf\\n\""
|
33
|
+
c += 1
|
34
|
+
end
|
35
|
+
else
|
36
|
+
cmd << "DEF:average=./#{name}.rrd:data:MAX"
|
37
|
+
cmd << "LINE1:average#FF0000:'#{params[:legend]}' GPRINT:average:LAST:\"Last\\:%8.0lf\" GPRINT:average:MIN:\" Min\\:%8.0lf\" GPRINT:average:AVERAGE:\" Avg\\:%8.0lf\" GPRINT:average:MAX:\" Max\\:%8.0lf\\n\""
|
38
|
+
end
|
39
|
+
|
40
|
+
system cmd.join(" ")
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
def create_or_find_rrd(name, datas)
|
45
|
+
averages = "RRA:AVERAGE:0.5:1:576 RRA:MIN:0.5:1:576 RRA:MAX:0.5:1:576 RRA:AVERAGE:0.5:6:432 RRA:MIN:0.5:6:432 RRA:MAX:0.5:6:432 RRA:AVERAGE:0.5:24:540 RRA:MIN:0.5:24:540 RRA:MAX:0.5:24:540 RRA:AVERAGE:0.5:288:450 RRA:MIN:0.5:288:450 RRA:MAX:0.5:288:450"
|
46
|
+
unless File.exist?(name + ".rrd")
|
47
|
+
puts 'Creating RRD' if @debug
|
48
|
+
if datas.is_a?(Hash)
|
49
|
+
entries = []
|
50
|
+
datas.each do |k,v|
|
51
|
+
entries << "DS:#{k.to_s}:GAUGE:600:0:U"
|
52
|
+
end
|
53
|
+
system "rrdtool create #{name}.rrd --step 300 --start #{Time.now.to_i - 1} #{entries.join(' ')} #{averages}"
|
54
|
+
else
|
55
|
+
system "rrdtool create #{name}.rrd --step 300 --start #{Time.now.to_i - 1} DS:data:GAUGE:600:0:U #{averages}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def push_to_rrd(name, data)
|
61
|
+
unless File.exist?(name + ".rrd")
|
62
|
+
puts 'Updating RRD' if @debug
|
63
|
+
system "rrdtool update #{name}.rrd #{Time.now.to_i}:#{data}"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def seconds_for(time_scale)
|
68
|
+
case time_scale
|
69
|
+
when :hour
|
70
|
+
3600
|
71
|
+
when :day
|
72
|
+
86400
|
73
|
+
when :week
|
74
|
+
604800
|
75
|
+
when :month
|
76
|
+
2629743
|
77
|
+
when :year
|
78
|
+
31556926
|
79
|
+
else
|
80
|
+
time_scale
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: impulse
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Lloyd Pick
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-05-09 00:00:00 Z
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Ability to make RRDTool graphs with zero thought
|
22
|
+
email:
|
23
|
+
- lloydpick+impulse@gmail.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- .gitignore
|
32
|
+
- Gemfile
|
33
|
+
- README.rdoc
|
34
|
+
- Rakefile
|
35
|
+
- impulse.gemspec
|
36
|
+
- lib/impulse.rb
|
37
|
+
- lib/impulse/version.rb
|
38
|
+
homepage: ""
|
39
|
+
licenses: []
|
40
|
+
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
hash: 3
|
52
|
+
segments:
|
53
|
+
- 0
|
54
|
+
version: "0"
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project: impulse
|
67
|
+
rubygems_version: 1.8.1
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: RubyGem to help make very quick RRDTool graphs
|
71
|
+
test_files: []
|
72
|
+
|