Class: RRDReader::File
- Inherits:
-
Object
- Object
- RRDReader::File
- Defined in:
- lib/rrd-grapher/rrd.rb
Instance Attribute Summary collapse
-
#ds ⇒ Object
readonly
Returns the value of attribute ds.
-
#last_update ⇒ Object
readonly
Returns the value of attribute last_update.
-
#rra ⇒ Object
(also: #archives)
readonly
Returns the value of attribute rra.
-
#rrd_version ⇒ Object
readonly
Returns the value of attribute rrd_version.
-
#short_name ⇒ Object
readonly
Returns the value of attribute short_name.
-
#step ⇒ Object
readonly
Returns the value of attribute step.
Instance Method Summary collapse
-
#get_values(consolidation_function, from, to, opts = {}) ⇒ Object
options: - rra : clip from/to to ensure returned values come from this rra.
-
#initialize(path, base_path = nil) ⇒ File
constructor
A new instance of File.
- #to_json(*args) ⇒ Object
- #xport_values(consolidation_function, from, to, opts = {}) ⇒ Object
Constructor Details
#initialize(path, base_path = nil) ⇒ File
Returns a new instance of File.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/rrd-grapher/rrd.rb', line 86 def initialize(path, base_path = nil) if base_path @path = ::File.join(base_path, path) @short_name = path else @path = @short_name = path end unless ::File.exists?(@path) puts "RRD Not found: '#{@path}'" raise Sinatra::NotFound end parse_data(@path) end |
Instance Attribute Details
#ds ⇒ Object (readonly)
Returns the value of attribute ds.
83 84 85 |
# File 'lib/rrd-grapher/rrd.rb', line 83 def ds @ds end |
#last_update ⇒ Object (readonly)
Returns the value of attribute last_update.
81 82 83 |
# File 'lib/rrd-grapher/rrd.rb', line 81 def last_update @last_update end |
#rra ⇒ Object (readonly) Also known as: archives
Returns the value of attribute rra.
83 84 85 |
# File 'lib/rrd-grapher/rrd.rb', line 83 def rra @rra end |
#rrd_version ⇒ Object (readonly)
Returns the value of attribute rrd_version.
81 82 83 |
# File 'lib/rrd-grapher/rrd.rb', line 81 def rrd_version @rrd_version end |
#short_name ⇒ Object (readonly)
Returns the value of attribute short_name.
81 82 83 |
# File 'lib/rrd-grapher/rrd.rb', line 81 def short_name @short_name end |
#step ⇒ Object (readonly)
Returns the value of attribute step.
81 82 83 |
# File 'lib/rrd-grapher/rrd.rb', line 81 def step @step end |
Instance Method Details
#get_values(consolidation_function, from, to, opts = {}) ⇒ Object
options:
-
rra : clip from/to to ensure returned values come from this rra
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/rrd-grapher/rrd.rb', line 119 def get_values(consolidation_function, from, to, opts = {}) = {} rra_id = opts[:rra] if rra_id [:resolution] = @rra[rra_id].interval from, to = @rra[rra_id].clip_time(from, to, @last_update) end [:start] = from.to_i [:end] = to.to_i line_params = RRD.to_line_parameters() # RRD::Wrapper.xport("--start", "1266933600", "--end", "1266944400", "DEF:xx=#{RRD_FILE}:cpu0:AVERAGE", "XPORT:xx:Legend 0") ds_name = @ds.keys[0] ret = RRD::Wrapper.xport(*line_params, "DEF:v1=#{@path}:#{ds_name}:#{consolidation_function}", "XPORT:v1:v1") if ret.is_a?(Array) ret = ret[1..-1].inject({}) do |h, (t,v)| h[t] = v.finite? ? v : nil h end end ret end |
#to_json(*args) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/rrd-grapher/rrd.rb', line 101 def to_json(*args) ret = { :path => @path, :short_name => ::File.basename(@short_name, '.rrd'), :step => @step, :sources => self.ds.keys, :last_update => @last_update.iso8601 } ret.to_json(*args) end |
#xport_values(consolidation_function, from, to, opts = {}) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/rrd-grapher/rrd.rb', line 147 def xport_values(consolidation_function, from, to, opts = {}) args = [] args += ["--start", from.to_i.to_s] args += ["--end", to.to_i.to_s] if opts[:maxrows] rows = opts[:maxrows].to_i raise ArgumentError, "maxrows needs to be greater or equal to 10" unless rows >= 10 args += ["--maxrows", rows.to_s] end if opts[:rra] rra_id = opts[:rra].to_i interval = @rra[rra_id].interval args += ['--step', interval.to_s] end if opts[:rrdcached] args += ['--daemon', opts[:rrdcached]] end if opts[:ds_name] ds_name = opts[:ds_name] else ds_name = @ds.keys[0] end args += ["DEF:v1=#{@path}:#{ds_name}:#{consolidation_function}", "XPORT:v1:v1"] ret = RRD::Wrapper.xport(*args) if ret.is_a?(Array) ret = ret[1..-1].inject({}) do |h, (t,v)| h[t.to_i] = v.finite? ? v : nil h end end ret end |