Module: FFWD::Plugin::Riemann::Shared
Instance Method Summary collapse
- #make_event(event) ⇒ Object
- #make_message(message) ⇒ Object
- #make_metric(metric) ⇒ Object
- #read_attributes(e, source) ⇒ Object
- #read_event(event) ⇒ Object
- #read_message(data) ⇒ Object
- #read_tags(e, source) ⇒ Object
- #read_time(e, source) ⇒ Object
- #write_attributes(e, source) ⇒ Object
- #write_tags(e, source) ⇒ Object
- #write_time(e, source) ⇒ Object
Instance Method Details
#make_event(event) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/ffwd/plugin/riemann/shared.rb', line 82 def make_event event e = ::Riemann::Event.new write_attributes e, event.attributes e, event. write_time e, event.time EVENT_MAPPING.each do |key, reader, writer| if (v = event.send(key)).nil? next end v = v.to_s if v.is_a? Symbol e.send writer, v end e end |
#make_message(message) ⇒ Object
138 139 140 |
# File 'lib/ffwd/plugin/riemann/shared.rb', line 138 def () ::Riemann::Message.new() end |
#make_metric(metric) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/ffwd/plugin/riemann/shared.rb', line 101 def make_metric metric e = ::Riemann::Event.new write_attributes e, metric.attributes e, metric. write_time e, metric.time METRIC_MAPPING.each do |key, reader, writer| if (v = metric.send(key)).nil? next end v = v.to_s if v.is_a? Symbol e.send writer, v end e end |
#read_attributes(e, source) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ffwd/plugin/riemann/shared.rb', line 40 def read_attributes e, source return if source.nil? or source.empty? attributes = {} source.each do |a| attributes[a.key] = a.value end e[:attributes] = attributes end |
#read_event(event) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/ffwd/plugin/riemann/shared.rb', line 120 def read_event event e = {} read_attributes e, event.attributes e, event. read_time e, event.time EVENT_MAPPING.each do |key, reader, writer| if (v = event.send(reader)).nil? next end e[key] = v end e end |
#read_message(data) ⇒ Object
142 143 144 |
# File 'lib/ffwd/plugin/riemann/shared.rb', line 142 def (data) ::Riemann::Message.decode data end |
#read_tags(e, source) ⇒ Object
62 63 64 65 |
# File 'lib/ffwd/plugin/riemann/shared.rb', line 62 def e, source return if source.nil? or source.empty? e[:tags] = source.to_a end |
#read_time(e, source) ⇒ Object
72 73 74 75 |
# File 'lib/ffwd/plugin/riemann/shared.rb', line 72 def read_time e, source return if source.nil? e[:time] = Time.at source end |
#write_attributes(e, source) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/ffwd/plugin/riemann/shared.rb', line 52 def write_attributes e, source return if source.nil? or source.empty? e.attributes = source.map{|k, v| k = k.to_s.dup unless k.nil? v = v.to_s.dup unless v.nil? ::Riemann::Attribute.new(:key => k, :value => v) } end |
#write_tags(e, source) ⇒ Object
67 68 69 70 |
# File 'lib/ffwd/plugin/riemann/shared.rb', line 67 def e, source return if source.nil? or source.empty? e. = source.map{|v| v.dup} end |
#write_time(e, source) ⇒ Object
77 78 79 80 |
# File 'lib/ffwd/plugin/riemann/shared.rb', line 77 def write_time e, source return if source.nil? e.time = source.to_i end |