Class: Fluent::AppdynamicsInput::StateStore
- Inherits:
-
Object
- Object
- Fluent::AppdynamicsInput::StateStore
- Defined in:
- lib/fluent/plugin/in_appdynamics.rb
Overview
Class statestore
Instance Method Summary collapse
-
#initialize(path, tag) ⇒ StateStore
constructor
A new instance of StateStore.
- #last_records(tag = nil) ⇒ Object
- #update_records(time, tag = nil) ⇒ Object
Constructor Details
#initialize(path, tag) ⇒ StateStore
Returns a new instance of StateStore.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/fluent/plugin/in_appdynamics.rb', line 40 def initialize(path,tag) require 'yaml' @path = path if File.exists?(@path) @data = YAML.load_file(@path) if @data == false || @data == [] # this happens if an users created an empty file accidentally @data = {} elsif !@data.is_a?(Hash) raise "state_file on #{@path.inspect} is invalid" end else @data = {} end end |
Instance Method Details
#last_records(tag = nil) ⇒ Object
56 57 58 59 |
# File 'lib/fluent/plugin/in_appdynamics.rb', line 56 def last_records(tag=nil) return @data[tag] #@data['last_records'] ||= {} end |
#update_records(time, tag = nil) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/fluent/plugin/in_appdynamics.rb', line 61 def update_records(time, tag=nil) @data[tag]=time pp @data File.open(@path, 'w') {|f| f.write YAML.dump(@data) } end |