class Mysqlcollector::Cli

Attributes

config[R]

Public Class Methods

new() click to toggle source
# File lib/mysqlcollector/cli.rb, line 17
def initialize
  options
end

Public Instance Methods

options() click to toggle source
# File lib/mysqlcollector/cli.rb, line 21
def options
  ARGV.options do |opt|
    begin
      opt.on('--alias ALIAS', String, 'Alias for instance') do |v|
        $config[:influx_database] = v
      end
      opt.on('--mysql-host HOST', String, 'MySQL Host') do |v|
        $config[:mysql_host] = v
      end
      opt.on('--mysql-port PORT', Integer, 'MySQL Port') do |v|
        $config[:mysql_host] = v
      end
      opt.on('--mysql-username USER', String, 'MySQL User name') do |v|
        $config[:mysql_username] = v
      end
      opt.on('--mysql-password PASSWORD', String, 'MySQL User password') do |v|
        $config[:mysql_password] = v
      end
      opt.on('--influx-host HOST', String, 'InfluxDB Host') do |v|
        $config[:influx_host] = v
      end
      opt.on('--influx-username USER', String, 'InfluxDB User') do |v|
        $config[:influx_user] = v
      end
      opt.on('--influx-password PASSWORD', String, 'InfluxDB User password') do |v|
        $config[:influx_password] = v
      end
      opt.on('--influx-database DATABASE', String, 'InfluxDB Database') do |v|
        $config[:influx_database] = v
      end
      opt.on('--daemonize', 'Run this every 30 seconds') do |v|
        $config[:daemonize] = v
      end
      opt.on('--template', 'Export JSON template for Grafana') do |v|
        $config[:template] = v
      end
      opt.on('--debug', 'Debug this tool') do |v|
        $config[:debug] = v
      end

      opt.on('-v', '--version', 'Show version') do
        puts "MySQL Collector V-#{Mysqlcollector::VERSION}"
      end
      opt.on('-?', '--help', 'Show this help') { puts opt.help; }
      opt.parse!

      if $config.empty?
        puts opt.help
        exit 1
      end
    rescue => e
      puts e
      exit 1
    end
  end
end
start() click to toggle source
# File lib/mysqlcollector/cli.rb, line 78
def start
  if $config[:daemonize]
    Deamon.new('Collector.new.start').run!
  elsif $config[:template]
    Template.new.grafana
  else
    collector = Collector.new
    collector.start
  end
end