Method: Beaker::Perf#export_perf_data_to_graphite

Defined in:
lib/beaker/perf.rb

#export_perf_data_to_graphite(host) ⇒ void

This method returns an undefined value.

Send performance report numbers to an external Graphite instance

Parameters:

  • host (Host)

    The host we are working with



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/beaker/perf.rb', line 87

def export_perf_data_to_graphite(host)
  @logger.perf_output("Sending data to Graphite server: " + @options[:graphite_server])

  data = JSON.parse(host.exec(Command.new("sadf -j -- -A"), :silent => true).stdout)
  hostname = host['vmhostname'].split('.')[0]

  data['sysstat']['hosts'].each do |host|
    host['statistics'].each do |poll|
      timestamp = DateTime.parse(poll['timestamp']['date'] + ' ' + poll['timestamp']['time']).to_time.to_i

      poll.keys.each do |stat|
        case stat
        when 'cpu-load-all'
          poll[stat].each do |s|
            s.keys.each do |k|
              next if k == 'cpu'

              socket = TCPSocket.new(@options[:graphite_server], 2003)
              socket.puts "#{@options[:graphite_perf_data]}.#{hostname}.cpu.#{s['cpu']}.#{k} #{s[k]} #{timestamp}"
              socket.close
            end
          end

        when 'memory'
          poll[stat].keys.each do |s|
            socket = TCPSocket.new(@options[:graphite_server], 2003)
            socket.puts "#{@options[:graphite_perf_data]}.#{hostname}.memory.#{s} #{poll[stat][s]} #{timestamp}"
            socket.close
          end
        end
      end
    end
  end
end