bipbip 0.6.7 → 0.6.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,19 +1,17 @@
1
1
  module Bipbip
2
-
3
2
  class Plugin::Network < Plugin
4
-
5
3
  def metrics_schema
6
4
  [
7
- {:name => 'connections_total', :type => 'gauge', :unit => 'Connections'},
5
+ { name: 'connections_total', type: 'gauge', unit: 'Connections' }
8
6
  ]
9
7
  end
10
8
 
11
9
  def monitor
12
10
  tcp_summary = `ss -s | grep '^TCP:'`
13
11
  tcp_counters = /^TCP:\s+(\d+) \(estab (\d+), closed (\d+), orphaned (\d+), synrecv (\d+), timewait (\d+)\/(\d+)\), ports (\d+)$/.match(tcp_summary)
14
- raise "Cannot match ss-output `#{tcp_summary}`" unless tcp_counters
12
+ fail "Cannot match ss-output `#{tcp_summary}`" unless tcp_counters
15
13
 
16
- {:connections_total => tcp_counters[1].to_i}
14
+ { connections_total: tcp_counters[1].to_i }
17
15
  end
18
16
  end
19
17
  end
@@ -1,17 +1,15 @@
1
1
  module Bipbip
2
-
3
2
  class Plugin::Nginx < Plugin
4
-
5
3
  def metrics_schema
6
4
  [
7
- {:name => 'connections_accepts', :type => 'counter', :unit => 'Connections'},
8
- {:name => 'connections_handled', :type => 'counter', :unit => 'Connections'},
9
- {:name => 'connections_dropped', :type => 'counter', :unit => 'Connections'},
10
- {:name => 'connections_requests', :type => 'counter', :unit => 'Requests'},
11
- {:name => 'active_total', :type => 'gauge', :unit => 'Connections'},
12
- {:name => 'active_reading', :type => 'gauge', :unit => 'Connections'},
13
- {:name => 'active_writing', :type => 'gauge', :unit => 'Connections'},
14
- {:name => 'active_waiting', :type => 'gauge', :unit => 'Connections'},
5
+ { name: 'connections_accepts', type: 'counter', unit: 'Connections' },
6
+ { name: 'connections_handled', type: 'counter', unit: 'Connections' },
7
+ { name: 'connections_dropped', type: 'counter', unit: 'Connections' },
8
+ { name: 'connections_requests', type: 'counter', unit: 'Requests' },
9
+ { name: 'active_total', type: 'gauge', unit: 'Connections' },
10
+ { name: 'active_reading', type: 'gauge', unit: 'Connections' },
11
+ { name: 'active_writing', type: 'gauge', unit: 'Connections' },
12
+ { name: 'active_waiting', type: 'gauge', unit: 'Connections' }
15
13
  ]
16
14
  end
17
15
 
@@ -19,10 +17,10 @@ module Bipbip
19
17
  uri = URI.parse(config['url'])
20
18
  response = Net::HTTP.get_response(uri)
21
19
 
22
- raise "Invalid response from server at #{config['url']}" unless response.code == "200"
20
+ fail "Invalid response from server at #{config['url']}" unless response.code == '200'
23
21
 
24
22
  lines = response.body.split(/\r*\n/)
25
- lines.map { |line| line.strip! }
23
+ lines.map(&:strip!)
26
24
 
27
25
  data = {}
28
26
 
@@ -48,7 +46,7 @@ module Bipbip
48
46
  def match_or_fail(string, regexp)
49
47
  match_data = regexp.match(string)
50
48
  if match_data.nil?
51
- raise "Data `#{string}` doesn't match pattern `#{regexp}`."
49
+ fail "Data `#{string}` doesn't match pattern `#{regexp}`."
52
50
  end
53
51
  match_data
54
52
  end
@@ -1,11 +1,9 @@
1
1
  module Bipbip
2
-
3
2
  class Plugin::PhpApc < Plugin
4
-
5
3
  def metrics_schema
6
4
  [
7
- {:name => 'opcode_mem_size', :type => 'gauge', :unit => 'b'},
8
- {:name => 'user_mem_size', :type => 'gauge', :unit => 'b'},
5
+ { name: 'opcode_mem_size', type: 'gauge', unit: 'b' },
6
+ { name: 'user_mem_size', type: 'gauge', unit: 'b' }
9
7
  ]
10
8
  end
11
9
 
@@ -13,11 +11,11 @@ module Bipbip
13
11
  uri = URI.parse(config['url'])
14
12
  response = Net::HTTP.get_response(uri)
15
13
 
16
- raise "Invalid response from server at #{config['url']}" unless response.code == '200'
14
+ fail "Invalid response from server at #{config['url']}" unless response.code == '200'
17
15
 
18
16
  stats = JSON.parse(response.body)
19
17
 
20
- {:opcode_mem_size => stats['opcode_mem_size'].to_i, :user_mem_size => stats['user_mem_size'].to_i}
18
+ { opcode_mem_size: stats['opcode_mem_size'].to_i, user_mem_size: stats['user_mem_size'].to_i }
21
19
  end
22
20
  end
23
21
  end
@@ -1,17 +1,15 @@
1
1
  module Bipbip
2
-
3
2
  class Plugin::Postfix < Plugin
4
-
5
3
  def metrics_schema
6
4
  [
7
- {:name => 'mails_queued_total', :type => 'gauge', :unit => 'Mails'},
5
+ { name: 'mails_queued_total', type: 'gauge', unit: 'Mails' }
8
6
  ]
9
7
  end
10
8
 
11
9
  def monitor
12
10
  queue_counter = /(\d+) Request+s?\.$/.match(postqueue)
13
11
  {
14
- 'mails_queued_total' => queue_counter.nil? ? 0 : queue_counter[1].to_i
12
+ 'mails_queued_total' => queue_counter.nil? ? 0 : queue_counter[1].to_i
15
13
  }
16
14
  end
17
15
 
@@ -2,21 +2,19 @@ require 'pathname'
2
2
  require 'yaml'
3
3
 
4
4
  module Bipbip
5
-
6
5
  class Plugin::Puppet < Plugin
7
-
8
6
  def metrics_schema
9
7
  [
10
- {:name => 'report_ok', :type => 'gauge', :unit => 'Boolean'},
11
- {:name => 'last_run_total_time', :type => 'gauge', :unit => 'Seconds'},
12
- {:name => 'last_run_age', :type => 'gauge', :unit => 'Seconds'},
13
- {:name => 'events_failure_count', :type => 'gauge', :unit => 'Events'},
14
- {:name => 'events_success_count', :type => 'gauge', :unit => 'Events'},
15
- {:name => 'events_total_count', :type => 'gauge', :unit => 'Events'},
16
- {:name => 'resources_failed_count', :type => 'gauge', :unit => 'Resources'},
17
- {:name => 'resources_skipped_count', :type => 'gauge', :unit => 'Resources'},
18
- {:name => 'resources_total_count', :type => 'gauge', :unit => 'Resources'},
19
- {:name => 'changes_total_count', :type => 'gauge', :unit => 'Changes'},
8
+ { name: 'report_ok', type: 'gauge', unit: 'Boolean' },
9
+ { name: 'last_run_total_time', type: 'gauge', unit: 'Seconds' },
10
+ { name: 'last_run_age', type: 'gauge', unit: 'Seconds' },
11
+ { name: 'events_failure_count', type: 'gauge', unit: 'Events' },
12
+ { name: 'events_success_count', type: 'gauge', unit: 'Events' },
13
+ { name: 'events_total_count', type: 'gauge', unit: 'Events' },
14
+ { name: 'resources_failed_count', type: 'gauge', unit: 'Resources' },
15
+ { name: 'resources_skipped_count', type: 'gauge', unit: 'Resources' },
16
+ { name: 'resources_total_count', type: 'gauge', unit: 'Resources' },
17
+ { name: 'changes_total_count', type: 'gauge', unit: 'Changes' }
20
18
  ]
21
19
  end
22
20
 
@@ -24,14 +22,14 @@ module Bipbip
24
22
  puppet_report = last_run_summary
25
23
 
26
24
  report_age = Time.new.to_i - puppet_report['time']['last_run'].to_i
27
- has_events = puppet_report.has_key?('events')
28
- has_resources = puppet_report.has_key?('resources')
29
- has_changes = puppet_report.has_key?('changes')
25
+ has_events = puppet_report.key?('events')
26
+ has_resources = puppet_report.key?('resources')
27
+ has_changes = puppet_report.key?('changes')
30
28
 
31
29
  metrics = {
32
- 'report_ok' => ((has_events and has_changes and has_resources) ? 1 : 0),
33
- 'last_run_total_time' => puppet_report['time']['total'].to_i,
34
- 'last_run_age' => report_age,
30
+ 'report_ok' => ((has_events && has_changes && has_resources) ? 1 : 0),
31
+ 'last_run_total_time' => puppet_report['time']['total'].to_i,
32
+ 'last_run_age' => report_age
35
33
  }
36
34
 
37
35
  if has_events
@@ -3,30 +3,28 @@ class RedisClient < Redis
3
3
  end
4
4
 
5
5
  module Bipbip
6
-
7
6
  class Plugin::Redis < Plugin
8
-
9
7
  def metrics_schema
10
8
  [
11
- {:name => 'total_commands_processed', :type => 'counter', :unit => 'Commands'},
12
- {:name => 'used_memory', :type => 'gauge', :unit => 'b'},
13
- {:name => 'used_memory_rss', :type => 'gauge', :unit => 'b'},
14
- {:name => 'mem_fragmentation_ratio', :type => 'gauge', :unit => 'Frag'},
15
- {:name => 'connected_clients', :type => 'gauge', :unit => 'Clients'},
16
- {:name => 'blocked_clients', :type => 'gauge', :unit => 'BlockedClients'},
9
+ { name: 'total_commands_processed', type: 'counter', unit: 'Commands' },
10
+ { name: 'used_memory', type: 'gauge', unit: 'b' },
11
+ { name: 'used_memory_rss', type: 'gauge', unit: 'b' },
12
+ { name: 'mem_fragmentation_ratio', type: 'gauge', unit: 'Frag' },
13
+ { name: 'connected_clients', type: 'gauge', unit: 'Clients' },
14
+ { name: 'blocked_clients', type: 'gauge', unit: 'BlockedClients' }
17
15
  ]
18
16
  end
19
17
 
20
18
  def float_roundings
21
19
  {
22
- 'mem_fragmentation_ratio' => 2
20
+ 'mem_fragmentation_ratio' => 2
23
21
  }
24
22
  end
25
23
 
26
24
  def monitor
27
25
  redis = RedisClient.new(
28
- :host => config['hostname'],
29
- :port => config['port']
26
+ host: config['hostname'],
27
+ port: config['port']
30
28
  )
31
29
  stats = redis.info
32
30
  redis.quit
@@ -2,19 +2,18 @@ require 'redis'
2
2
  require 'resque'
3
3
 
4
4
  module Bipbip
5
-
6
5
  class Plugin::Resque < Plugin
7
-
8
6
  def metrics_schema
9
7
  schema_list = [
10
- {:name => 'num_workers', :type => 'counter', :unit => 'Workers'},
11
- {:name => 'num_idle_workers', :type => 'counter', :unit => 'Workers'},
12
- {:name => 'num_active_workers', :type => 'counter', :unit => 'Workers'},
8
+ { name: 'num_workers', type: 'counter', unit: 'Workers' },
9
+ { name: 'num_idle_workers', type: 'counter', unit: 'Workers' },
10
+ { name: 'num_active_workers', type: 'counter', unit: 'Workers' },
11
+ { name: 'num_failures', type: 'counter', unit: 'Jobs' }
13
12
  ]
14
13
 
15
14
  with_resque_connection do
16
15
  ::Resque.queues.each do |queue|
17
- schema_list << {:name => "queue_size_#{sanitize_queue_name(queue)}", :type => 'gauge', :unit => 'Jobs'}
16
+ schema_list << { name: "queue_size_#{sanitize_queue_name(queue)}", type: 'gauge', unit: 'Jobs' }
18
17
  end
19
18
  end
20
19
 
@@ -27,8 +26,8 @@ module Bipbip
27
26
 
28
27
  def with_resque_connection
29
28
  redis = ::Redis.new(
30
- :host => config['hostname'] || 'localhost',
31
- :port => config['port'] || 6369
29
+ host: config['hostname'] || 'localhost',
30
+ port: config['port'] || 6369
32
31
  )
33
32
  redis.select config['database']
34
33
  ::Resque.redis = redis
@@ -43,8 +42,9 @@ module Bipbip
43
42
  data = {}
44
43
  with_resque_connection do
45
44
  data['num_workers'] = ::Resque.workers.count
46
- data['num_idle_workers'] = ::Resque.workers.select { |w| w.idle? }.count
45
+ data['num_idle_workers'] = ::Resque.workers.count(&:idle?)
47
46
  data['num_active_workers'] = data['num_workers'] - data['num_idle_workers']
47
+ data['num_failures'] = ::Resque::Failure.count
48
48
  ::Resque.queues.each do |queue|
49
49
  data["queue_size_#{sanitize_queue_name(queue)}"] = ::Resque.size(queue).to_i
50
50
  end
@@ -1,21 +1,19 @@
1
1
  require 'net/http'
2
2
 
3
3
  module Bipbip
4
-
5
4
  class Plugin::SocketRedis < Plugin
6
-
7
5
  def metrics_schema
8
6
  [
9
- {:name => 'channels_count', :type => 'gauge', :unit => 'Channels'},
10
- {:name => 'subscribers_count', :type => 'gauge', :unit => 'Subscribers'},
7
+ { name: 'channels_count', type: 'gauge', unit: 'Channels' },
8
+ { name: 'subscribers_count', type: 'gauge', unit: 'Subscribers' }
11
9
  ]
12
10
  end
13
11
 
14
12
  def monitor
15
13
  stats = fetch_socket_redis_status
16
14
  {
17
- 'channels_count' => stats.length,
18
- 'subscribers_count' => stats.values.reduce(0) { |memo, channel| memo += channel['subscribers'].length },
15
+ 'channels_count' => stats.length,
16
+ 'subscribers_count' => stats.values.reduce(0) { |memo, channel| memo += channel['subscribers'].length }
19
17
  }
20
18
  end
21
19
 
@@ -26,10 +24,11 @@ module Bipbip
26
24
  uri = URI.parse(url)
27
25
 
28
26
  response = Net::HTTP.get_response(uri)
29
- raise "Invalid response from server at `#{url}`. Response code `#{response.code}`, message `#{response.message}`, body `#{response.body}`" unless response.code == '200'
27
+ unless response.code == '200'
28
+ fail "Invalid response from server at `#{url}`. Response code `#{response.code}`, message `#{response.message}`, body `#{response.body}`"
29
+ end
30
30
 
31
31
  JSON.parse(response.body)
32
32
  end
33
-
34
33
  end
35
34
  end
@@ -1,13 +1,11 @@
1
1
  module Bipbip
2
-
3
2
  class Storage
4
-
5
3
  attr_accessor :name
6
4
  attr_accessor :config
7
5
 
8
6
  def self.factory(name, config)
9
7
  require "bipbip/storage/#{Bipbip::Helper.name_to_filename(name)}"
10
- Storage::const_get(Bipbip::Helper.name_to_classname(name)).new(name, config)
8
+ Storage.const_get(Bipbip::Helper.name_to_classname(name)).new(name, config)
11
9
  end
12
10
 
13
11
  def initialize(name, config)
@@ -15,12 +13,12 @@ module Bipbip
15
13
  @config = config.to_hash
16
14
  end
17
15
 
18
- def setup_plugin(plugin)
19
- raise 'Missing method setup_plugin'
16
+ def setup_plugin(_plugin)
17
+ fail 'Missing method setup_plugin'
20
18
  end
21
19
 
22
- def store_sample(plugin, time, data)
23
- raise 'Missing method store_sample'
20
+ def store_sample(_plugin, _time, _data)
21
+ fail 'Missing method store_sample'
24
22
  end
25
23
 
26
24
  private
@@ -28,6 +26,5 @@ module Bipbip
28
26
  def log(severity, message)
29
27
  Bipbip.logger.add(severity, message, "#{name}")
30
28
  end
31
-
32
29
  end
33
30
  end
@@ -1,7 +1,5 @@
1
1
  module Bipbip
2
-
3
2
  class Storage::Copperegg < Storage
4
-
5
3
  def initialize(name, config)
6
4
  super(name, config)
7
5
  ::Copperegg::Revealmetrics::Api.apikey = config['api_key']
@@ -12,7 +10,7 @@ module Bipbip
12
10
  @dashboards ||= _load_dashboards
13
11
  @tags ||= _load_tags
14
12
 
15
- if ![5, 15, 60, 300, 900, 3600, 21600].include?(plugin.frequency)
13
+ unless [5, 15, 60, 300, 900, 3600, 21_600].include?(plugin.frequency)
16
14
  log(Logger::FATAL, "Cannot use frequency #{plugin.frequency}")
17
15
  exit 1
18
16
  end
@@ -20,14 +18,14 @@ module Bipbip
20
18
  metric_group = @metric_groups.detect { |m| m.name == plugin.metric_group }
21
19
  if metric_group.nil? || !metric_group.is_a?(::Copperegg::Revealmetrics::MetricGroup)
22
20
  log(Logger::INFO, "Creating metric group `#{plugin.metric_group}`")
23
- metric_group = ::Copperegg::Revealmetrics::MetricGroup.new(:name => plugin.metric_group, :label => plugin.metric_group, :frequency => plugin.frequency)
21
+ metric_group = ::Copperegg::Revealmetrics::MetricGroup.new(name: plugin.metric_group, label: plugin.metric_group, frequency: plugin.frequency)
24
22
  end
25
23
  metric_group.frequency = plugin.frequency
26
24
  metric_group.metrics = plugin.metrics_schema.map do |sample|
27
25
  {
28
- :name => sample[:name],
29
- :type => 'ce_' + sample[:type],
30
- :unit => sample[:unit],
26
+ name: sample[:name],
27
+ type: 'ce_' + sample[:type],
28
+ unit: sample[:unit]
31
29
  }
32
30
  end
33
31
  log(Logger::INFO, "Updating metric group `#{plugin.metric_group}`")
@@ -37,7 +35,7 @@ module Bipbip
37
35
  tag = @tags.detect { |t| t.name == tag_name }
38
36
  if tag.nil?
39
37
  log(Logger::INFO, "Creating tag `#{tag_name}`")
40
- tag = ::Copperegg::Revealmetrics::Tag.new(:name => tag_name)
38
+ tag = ::Copperegg::Revealmetrics::Tag.new(name: tag_name)
41
39
  end
42
40
  object_identifier = plugin.source_identifier
43
41
  unless tag.objects.include?(object_identifier)
@@ -53,14 +51,14 @@ module Bipbip
53
51
  if dashboard.nil?
54
52
  log(Logger::INFO, "Creating dashboard `#{plugin.metric_group}`")
55
53
  metrics = metric_group.metrics || []
56
- ::Copperegg::Revealmetrics::CustomDashboard.create(metric_group, :name => plugin.metric_group, :identifiers => nil, :metrics => metrics)
54
+ ::Copperegg::Revealmetrics::CustomDashboard.create(metric_group, name: plugin.metric_group, identifiers: nil, metrics: metrics)
57
55
  end
58
56
  end
59
57
 
60
58
  def store_sample(plugin, time, data)
61
59
  response = ::Copperegg::Revealmetrics::MetricSample.save(plugin.metric_group, plugin.source_identifier, time.to_i, data)
62
60
  if response.code != '200'
63
- raise("Cannot store copperegg data `#{data}`. Response code `#{response.code}`, message `#{response.message}`, body `#{response.body}`")
61
+ fail("Cannot store copperegg data `#{data}`. Response code `#{response.code}`, message `#{response.message}`, body `#{response.body}`")
64
62
  end
65
63
  end
66
64
 
@@ -94,6 +92,5 @@ module Bipbip
94
92
  end
95
93
  tags
96
94
  end
97
-
98
95
  end
99
96
  end
@@ -1,3 +1,3 @@
1
1
  module Bipbip
2
- VERSION = '0.6.7'
2
+ VERSION = '0.6.8'
3
3
  end
@@ -7,6 +7,6 @@ module InterruptibleSleep
7
7
  end
8
8
 
9
9
  def interrupt_sleep
10
- @_sleep_interrupt.close if @_sleep_interrupt and !@_sleep_interrupt.closed?
10
+ @_sleep_interrupt.close if @_sleep_interrupt && !@_sleep_interrupt.closed?
11
11
  end
12
12
  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.6.7
4
+ version: 0.6.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cargo Media
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-09-17 00:00:00.000000000 Z
13
+ date: 2015-12-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: copperegg-revealmetrics
@@ -208,6 +208,20 @@ dependencies:
208
208
  - - "~>"
209
209
  - !ruby/object:Gem::Version
210
210
  version: '1.21'
211
+ - !ruby/object:Gem::Dependency
212
+ name: rubocop
213
+ requirement: !ruby/object:Gem::Requirement
214
+ requirements:
215
+ - - "~>"
216
+ - !ruby/object:Gem::Version
217
+ version: '0.35'
218
+ type: :development
219
+ prerelease: false
220
+ version_requirements: !ruby/object:Gem::Requirement
221
+ requirements:
222
+ - - "~>"
223
+ - !ruby/object:Gem::Version
224
+ version: '0.35'
211
225
  description: Agent to collect data for common server programs and push them to CopperEgg
212
226
  email: hello@cargomedia.ch
213
227
  executables:
@@ -269,7 +283,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
269
283
  version: '0'
270
284
  requirements: []
271
285
  rubyforge_project:
272
- rubygems_version: 2.4.6
286
+ rubygems_version: 2.5.0
273
287
  signing_key:
274
288
  specification_version: 4
275
289
  summary: Gather services data and store in CopperEgg