Sha256: 59fd1171e5b7ca6911e5f8a3b0457265d81de5d96c9a0ae9542f6540930b072c

Contents?: true

Size: 960 Bytes

Versions: 1

Compression:

Stored size: 960 Bytes

Contents

# frozen_string_literal: true

module Stackeye
  module Metrics
    class Mysql < Stackeye::Metrics::Base

      CREDENTIALS ||= {
        user: 'root',
        host: 'localhost',
        password: nil
      }.freeze

      def generate_data
        generate_stats
      end

      private

      def generate_stats
        cmd = "mysqladmin -u#{user} -h#{host} -p#{password} status"
        lines = Stackeye::Tools::Cli.execute(cmd).split("\n")
        stats = lines.last.strip.split('  ')

        stats.each do |stat|
          key, val = stat.split(': ')
          key = key.downcase.tr(' ', '_')
          key = 'velocity' if key == 'queries_per_second_avg'

          @data[key] = val.to_f.round(2)
        end
      end

      %i[host password user].each do |name|
        define_method(name) do
          credentials = Stackeye.configuration.credentials[:mysql]
          credentials[name] || CREDENTIALS[name]
        end
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stackeye-0.1.0 lib/stackeye/metrics/mysql.rb