Class: Mysqlcollector::Cli

Inherits:
Object show all
Defined in:
lib/mysqlcollector/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCli

Returns a new instance of Cli.



17
18
19
# File 'lib/mysqlcollector/cli.rb', line 17

def initialize
  options
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/mysqlcollector/cli.rb', line 5

def config
  @config
end

Instance Method Details

#optionsObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# 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

#startObject



78
79
80
81
82
83
84
85
86
87
# 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