bipbip 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ffb2e47b0d064209e1459b7be4036cc1ab15f2bb
4
- data.tar.gz: 6da35aa18a085d1bfcc572c5d7197d903b7a4ee1
3
+ metadata.gz: 8aa8df7e73d0d7c9d463fb6770ad5b3e59327375
4
+ data.tar.gz: 75973cff2c74e8eff315d6484b89628ec4d9e7be
5
5
  SHA512:
6
- metadata.gz: 3ef24076ec298fc436416646b4c09d936b767282d93fc77e083da7345d7ce506efd8cb3915b93997390038c5030169ec66e5f5df80841ef32aac5df397882478
7
- data.tar.gz: 3c6330c8064fe34ca717e177e7f6e1be8f86b0008cd02ace5f3e46a286381a6e0e80f7c2d2690faac28fba85fadfe296cb5e1c5c0a495802ba62de387cfb0eae
6
+ metadata.gz: 0a19418f1f7693d768ab30a6b14000d2dd50fcd24b4702c8ef307962f8f77369bab604ae21f73a1daeec26d31fe3c71fd2556569a38b6ebd9cdd12639543d701
7
+ data.tar.gz: c1453b8c39cb419f6c8d6ecd614d0105aa5bce98eaec83a0e5493c7d439e073a5d279c29d423aed7bfc30c6b60107595c551f4164198051763c9d830671bf88e
data/README.md CHANGED
@@ -1,22 +1,31 @@
1
1
  bipbip
2
2
  ======
3
3
  Agent to collect server metrics and send them to the [CopperEgg RevealMetrics](http://copperegg.com/) platform.
4
- Plugins for different metrics available in the `plugin/`-directory.
4
+ Plugins for different metrics available.
5
5
  Will spawn a child process for every plugin and server you tell it to monitor.
6
6
 
7
- Configure and run
8
- -----------------
7
+ Installation
8
+ ------------
9
+ ```
10
+ gem install bipbip
11
+ ```
12
+
13
+ Configuration
14
+ -------------
9
15
  Pass the path to your configuration file to `bipbip` using the `-c` command line argument.
10
16
  ```sh
11
- bipbip -c /etc/bipbip/bipbip.yml
17
+ bipbip -c /etc/bipbip/config.yml
12
18
  ```
13
19
 
14
- The configuration file should list the services you want to collect for, and the servers for each of them, e.g.:
20
+ The configuration file should list the services you want to collect data for:
15
21
  ```yml
22
+ logfile: /var/log/bipbip.log
16
23
  loglevel: INFO
24
+ frequency: 15
25
+ include: services.d/
26
+
17
27
  copperegg:
18
28
  apikey: YOUR_APIKEY
19
- frequency: 15
20
29
 
21
30
  services:
22
31
  -
data/bin/bipbip CHANGED
@@ -39,4 +39,4 @@ rescue OptionParser::InvalidOption, OptionParser::MissingArgument
39
39
  exit
40
40
  end
41
41
 
42
- Bipbip::Agent.new.run options[:config]
42
+ Bipbip::Agent.new(options[:config]).run
@@ -16,7 +16,7 @@ module Bipbip
16
16
  require 'bipbip/plugin/gearman'
17
17
 
18
18
  def self.logger
19
- @logger
19
+ @logger || Logger.new(STDOUT)
20
20
  end
21
21
 
22
22
  def self.logger=(logger)
@@ -2,49 +2,47 @@ module Bipbip
2
2
 
3
3
  class Agent
4
4
 
5
- def initialize
5
+ def initialize(config_file)
6
6
  @plugin_pids = []
7
- end
7
+ @logfile = STDOUT
8
+ @loglevel = 'INFO'
9
+ @frequency = 60
10
+ @services = []
11
+ @copperegg_api_key
8
12
 
9
- def run(config_file)
10
- config = YAML.load(File.open(config_file))
13
+ load_config(config_file)
14
+ end
11
15
 
12
- Bipbip.logger = Logger.new(STDOUT)
13
- Bipbip.logger.level = Logger::const_get(config['loglevel'] || 'INFO')
16
+ def run
17
+ Bipbip.logger = Logger.new(@logfile)
18
+ Bipbip.logger.level = Logger::const_get(@loglevel)
14
19
  Bipbip.logger.info 'Startup...'
15
20
 
16
- CopperEgg::Api.apikey = config['copperegg']['apikey']
17
- CopperEgg::Api.host = config['copperegg']['host'] if !config['copperegg']['host'].nil?
18
- frequency = config['copperegg']['frequency'].to_i
21
+ Bipbip.logger.info "Using CopperEgg API key `#{@copperegg_api_key}`"
22
+ CopperEgg::Api.apikey = @copperegg_api_key
19
23
 
20
- if ![5, 15, 60, 300, 900, 3600, 21600].include?(frequency)
21
- Bipbip.logger.fatal "Invalid frequency: #{frequency}"
22
- exit
24
+ if ![5, 15, 60, 300, 900, 3600, 21600].include?(@frequency)
25
+ Bipbip.logger.fatal "Invalid frequency: #{@frequency}"
26
+ exit 1
23
27
  end
24
28
 
25
29
  ['INT', 'TERM'].each { |sig| trap(sig) {
26
30
  Thread.new { interrupt }
27
31
  } }
28
32
 
29
- services = config['services']
30
- if config.has_key?('include')
31
- include_path = File.expand_path(config['include'], File.dirname(config_file))
32
- services += load_include_configs(include_path)
33
- end
34
-
35
- metric_groups = load_metric_groups
36
- dashboards = load_dashboards
33
+ metric_groups = get_copperegg_metric_groups
34
+ dashboards = get_copperegg_dashboards
37
35
 
38
- plugin_names = services.map { |service| service['plugin'] }
36
+ plugin_names = @services.map { |service| service['plugin'] }
39
37
  plugin_names.each do |plugin_name|
40
38
  plugin = Plugin::const_get(plugin_name).new
41
39
 
42
40
  metric_group = metric_groups.detect { |m| m.name == plugin_name }
43
41
  if metric_group.nil? || !metric_group.is_a?(CopperEgg::MetricGroup)
44
42
  Bipbip.logger.info "Creating metric group `#{plugin_name}`"
45
- metric_group = CopperEgg::MetricGroup.new(:name => plugin_name, :label => plugin_name, :frequency => frequency)
43
+ metric_group = CopperEgg::MetricGroup.new(:name => plugin_name, :label => plugin_name, :frequency => @frequency)
46
44
  end
47
- metric_group.frequency = frequency
45
+ metric_group.frequency = @frequency
48
46
  metric_group.metrics = plugin.metrics_schema
49
47
  metric_group.save
50
48
 
@@ -56,37 +54,61 @@ module Bipbip
56
54
  end
57
55
  end
58
56
 
59
- services.each do |service|
57
+ @services.each do |service|
60
58
  plugin_name = service['plugin']
61
59
  Bipbip.logger.info "Starting plugin #{plugin_name}"
62
60
  plugin = Plugin::const_get(plugin_name).new
63
- @plugin_pids.push plugin.run(service, frequency)
61
+ @plugin_pids.push plugin.run(service, @frequency)
64
62
  end
65
63
 
66
64
  p Process.waitall
67
65
  end
68
66
 
69
- def load_metric_groups
67
+ def get_copperegg_metric_groups
70
68
  Bipbip.logger.info 'Loading metric groups'
71
69
  metric_groups = CopperEgg::MetricGroup.find
72
70
  if metric_groups.nil?
73
- raise 'Cannot load metric groups'
71
+ Bipbip.logger.fatal 'Cannot load metric groups'
72
+ exit 1
74
73
  end
75
74
  metric_groups
76
75
  end
77
76
 
78
- def load_dashboards
77
+ def get_copperegg_dashboards
79
78
  Bipbip.logger.info 'Loading dashboards'
80
79
  dashboards = CopperEgg::CustomDashboard.find
81
80
  if dashboards.nil?
82
- raise 'Cannot load dashboards'
81
+ Bipbip.logger.fatal 'Cannot load dashboards'
82
+ exit 1
83
83
  end
84
84
  dashboards
85
85
  end
86
86
 
87
- def load_include_configs(directory)
88
- files = Dir[directory + '/**/*.yaml', directory + '/**/*.yml']
89
- services = files.map {|file| YAML.load(File.open(file))}
87
+ def load_config(config_file)
88
+ config = YAML.load(File.open(config_file))
89
+ if config.has_key?('logfile')
90
+ @logfile = config['logfile'].to_s
91
+ end
92
+ if config.has_key?('loglevel')
93
+ @loglevel = config['loglevel'].to_s
94
+ end
95
+ if config.has_key?('frequency')
96
+ @frequency = config['frequency'].to_i
97
+ end
98
+ if config.has_key?('services')
99
+ @services = config['services'].to_a
100
+ end
101
+ if config.has_key?('include')
102
+ include_path = File.expand_path(config['include'].to_s, File.dirname(config_file))
103
+ files = Dir[include_path + '/**/*.yaml', include_path + '/**/*.yml']
104
+ @services += files.map {|file| YAML.load(File.open(file))}
105
+ end
106
+ if config.has_key?('copperegg')
107
+ config_copperegg = config['copperegg']
108
+ if config_copperegg.has_key?('apikey')
109
+ @copperegg_api_key = config_copperegg['apikey']
110
+ end
111
+ end
90
112
  end
91
113
 
92
114
  def interrupt
@@ -1,3 +1,3 @@
1
1
  module Bipbip
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bipbip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cargo Media