bipbip 0.1.9 → 0.2.0
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.
- checksums.yaml +4 -4
- data/README.md +5 -3
- data/lib/bipbip.rb +5 -2
- data/lib/bipbip/agent.rb +43 -92
- data/lib/bipbip/helper.rb +10 -0
- data/lib/bipbip/plugin.rb +22 -11
- data/lib/bipbip/plugin/apache2.rb +5 -5
- data/lib/bipbip/plugin/gearman.rb +3 -3
- data/lib/bipbip/plugin/memcached.rb +6 -6
- data/lib/bipbip/plugin/mysql.rb +21 -21
- data/lib/bipbip/plugin/network.rb +2 -2
- data/lib/bipbip/plugin/nginx.rb +4 -4
- data/lib/bipbip/plugin/php_apc.rb +5 -5
- data/lib/bipbip/plugin/redis.rb +5 -5
- data/lib/bipbip/storage.rb +27 -0
- data/lib/bipbip/storage/copperegg.rb +67 -0
- data/lib/bipbip/version.rb +1 -1
- data/lib/{bipbip/interruptible_sleep.rb → interruptible_sleep.rb} +0 -0
- metadata +34 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23a9fee96f16b13c84f67946b0e3c64c6b8624f4
|
4
|
+
data.tar.gz: 1c4a817735f2e4f35cafdb1c421a141990516c09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc37152e3c4c278b049c71b1a9d89acca947afddf14ea8c45b31e901bf71b723effe16ef0901ee62992bd3e6478fb807f0c4a4dcc22869ffa32b3576d1687bf2
|
7
|
+
data.tar.gz: 78621bb55b7465384c27dadaa0a31a5c8d347bbee9eaa1af7caf42c07a104975756ef74daec69ab04d98850f485d30887eea15600ca630900f86b20579d08b79
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
bipbip
|
1
|
+
bipbip [](https://travis-ci.org/cargomedia/bipbip)
|
2
2
|
======
|
3
3
|
Agent to collect server metrics and send them to the [CopperEgg RevealMetrics](http://copperegg.com/) platform.
|
4
4
|
Plugins for different metrics available.
|
@@ -24,8 +24,10 @@ loglevel: INFO
|
|
24
24
|
frequency: 15
|
25
25
|
include: services.d/
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
storages:
|
28
|
+
-
|
29
|
+
name: copperegg
|
30
|
+
api_key: YOUR_APIKEY
|
29
31
|
|
30
32
|
services:
|
31
33
|
-
|
data/lib/bipbip.rb
CHANGED
@@ -7,9 +7,12 @@ module Bipbip
|
|
7
7
|
require 'logger'
|
8
8
|
require 'socket'
|
9
9
|
|
10
|
+
require 'interruptible_sleep'
|
11
|
+
|
10
12
|
require 'bipbip/version'
|
11
|
-
require 'bipbip/
|
13
|
+
require 'bipbip/helper'
|
12
14
|
require 'bipbip/agent'
|
15
|
+
require 'bipbip/storage'
|
13
16
|
require 'bipbip/plugin'
|
14
17
|
|
15
18
|
def self.logger
|
@@ -21,6 +24,6 @@ module Bipbip
|
|
21
24
|
end
|
22
25
|
|
23
26
|
def self.fqdn
|
24
|
-
@fqdn ||= Socket.gethostbyname(Socket.gethostname).first
|
27
|
+
@fqdn ||= Socket.gethostbyname(Socket.gethostname).first rescue Socket.gethostname
|
25
28
|
end
|
26
29
|
end
|
data/lib/bipbip/agent.rb
CHANGED
@@ -2,64 +2,36 @@ module Bipbip
|
|
2
2
|
|
3
3
|
class Agent
|
4
4
|
|
5
|
-
|
5
|
+
attr_accessor :plugins
|
6
|
+
attr_accessor :storages
|
7
|
+
|
8
|
+
def initialize(config_file = nil)
|
9
|
+
@plugins = []
|
10
|
+
@storages = []
|
6
11
|
@plugin_pids = []
|
7
|
-
@logfile = STDOUT
|
8
|
-
@loglevel = 'INFO'
|
9
|
-
@frequency = 60
|
10
|
-
@services = []
|
11
|
-
@copperegg_api_key
|
12
12
|
|
13
|
-
load_config(config_file)
|
13
|
+
load_config(config_file) if config_file
|
14
14
|
end
|
15
15
|
|
16
16
|
def run
|
17
|
-
Bipbip.logger = Logger.new(@logfile)
|
18
|
-
Bipbip.logger.level = Logger::const_get(@loglevel)
|
19
17
|
Bipbip.logger.info 'Startup...'
|
18
|
+
Bipbip.logger.warn 'No services configured' if @plugins.empty?
|
19
|
+
Bipbip.logger.warn 'No storages configured' if @storages.empty?
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
exit 1
|
21
|
+
@storages.each do |storage|
|
22
|
+
@plugins.each do |plugin|
|
23
|
+
Bipbip.logger.info "Setting up plugin #{plugin.name} for storage #{storage.name}"
|
24
|
+
storage.setup_plugin(plugin)
|
25
|
+
end
|
27
26
|
end
|
28
27
|
|
29
28
|
['INT', 'TERM'].each { |sig| trap(sig) {
|
30
29
|
Thread.new { interrupt }
|
31
30
|
} }
|
32
31
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
plugin_names = @services.map { |service| service['plugin'] }
|
37
|
-
plugin_names.each do |plugin_name|
|
38
|
-
plugin = plugin_factory(plugin_name)
|
39
|
-
|
40
|
-
metric_group = metric_groups.detect { |m| m.name == plugin_name }
|
41
|
-
if metric_group.nil? || !metric_group.is_a?(CopperEgg::MetricGroup)
|
42
|
-
Bipbip.logger.info "Creating metric group `#{plugin_name}`"
|
43
|
-
metric_group = CopperEgg::MetricGroup.new(:name => plugin_name, :label => plugin_name, :frequency => @frequency)
|
44
|
-
end
|
45
|
-
metric_group.frequency = @frequency
|
46
|
-
metric_group.metrics = plugin.metrics_schema
|
47
|
-
metric_group.save
|
48
|
-
|
49
|
-
dashboard = dashboards.detect { |d| d.name == plugin_name }
|
50
|
-
if dashboard.nil?
|
51
|
-
Bipbip.logger.info "Creating dashboard `#{plugin_name}`"
|
52
|
-
metrics = metric_group.metrics || []
|
53
|
-
CopperEgg::CustomDashboard.create(metric_group, :name => plugin_name, :identifiers => nil, :metrics => metrics)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
@services.each do |service|
|
58
|
-
plugin_name = service['plugin']
|
59
|
-
plugin = plugin_factory(plugin_name)
|
60
|
-
service_config = service.reject { |key, value| ['plugin'].include?(key) }
|
61
|
-
Bipbip.logger.info "Starting plugin #{plugin_name}"
|
62
|
-
@plugin_pids.push plugin.run(service_config, @frequency)
|
32
|
+
@plugins.each do |plugin|
|
33
|
+
Bipbip.logger.info "Starting plugin #{plugin.name} with config #{plugin.config}"
|
34
|
+
@plugin_pids.push plugin.run(@storages)
|
63
35
|
end
|
64
36
|
|
65
37
|
while true
|
@@ -67,58 +39,37 @@ module Bipbip
|
|
67
39
|
end
|
68
40
|
end
|
69
41
|
|
70
|
-
def get_copperegg_metric_groups
|
71
|
-
Bipbip.logger.info 'Loading metric groups'
|
72
|
-
metric_groups = CopperEgg::MetricGroup.find
|
73
|
-
if metric_groups.nil?
|
74
|
-
Bipbip.logger.fatal 'Cannot load metric groups'
|
75
|
-
exit 1
|
76
|
-
end
|
77
|
-
metric_groups
|
78
|
-
end
|
79
|
-
|
80
|
-
def get_copperegg_dashboards
|
81
|
-
Bipbip.logger.info 'Loading dashboards'
|
82
|
-
dashboards = CopperEgg::CustomDashboard.find
|
83
|
-
if dashboards.nil?
|
84
|
-
Bipbip.logger.fatal 'Cannot load dashboards'
|
85
|
-
exit 1
|
86
|
-
end
|
87
|
-
dashboards
|
88
|
-
end
|
89
|
-
|
90
|
-
def plugin_factory(plugin_name)
|
91
|
-
file_name = plugin_name.tr('-', '_')
|
92
|
-
require "bipbip/plugin/#{file_name}"
|
93
|
-
|
94
|
-
class_name = plugin_name.split('-').map{|w| w.capitalize}.join
|
95
|
-
Plugin::const_get(class_name).new(plugin_name)
|
96
|
-
end
|
97
|
-
|
98
42
|
def load_config(config_file)
|
99
43
|
config = YAML.load(File.open(config_file))
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
44
|
+
config = {
|
45
|
+
'logfile' => STDOUT,
|
46
|
+
'loglevel' => 'INFO',
|
47
|
+
'frequency' => 60,
|
48
|
+
'include' => nil,
|
49
|
+
'services' => [],
|
50
|
+
'services' => [],
|
51
|
+
}.merge(config)
|
52
|
+
|
53
|
+
Bipbip.logger = Logger.new(config['logfile'])
|
54
|
+
Bipbip.logger.level = Logger::const_get(config['loglevel'])
|
55
|
+
|
56
|
+
services = config['services'].to_a
|
57
|
+
if config['include']
|
113
58
|
include_path = File.expand_path(config['include'].to_s, File.dirname(config_file))
|
114
59
|
files = Dir[include_path + '/**/*.yaml', include_path + '/**/*.yml']
|
115
|
-
|
60
|
+
services += files.map { |file| YAML.load(File.open(file)) }
|
116
61
|
end
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
62
|
+
@plugins = services.map do |service|
|
63
|
+
service_name = service['plugin'].to_s
|
64
|
+
service_config = service.reject { |key, value| ['plugin'].include?(key) }
|
65
|
+
Bipbip::Plugin.factory(service_name, service_config, config['frequency'])
|
66
|
+
end
|
67
|
+
|
68
|
+
storages = config['storages'].to_a
|
69
|
+
@storages = storages.map do |storage|
|
70
|
+
storage_name = storage['name'].to_s
|
71
|
+
storage_config = storage.reject { |key, value| ['name'].include?(key) }
|
72
|
+
Bipbip::Storage.factory(storage_name, storage_config)
|
122
73
|
end
|
123
74
|
end
|
124
75
|
|
data/lib/bipbip/plugin.rb
CHANGED
@@ -3,27 +3,38 @@ module Bipbip
|
|
3
3
|
class Plugin
|
4
4
|
include InterruptibleSleep
|
5
5
|
|
6
|
-
|
6
|
+
attr_accessor :name
|
7
|
+
attr_accessor :config
|
8
|
+
|
9
|
+
def self.factory(name, config, frequency)
|
10
|
+
require "bipbip/plugin/#{Bipbip::Helper.name_to_filename(name)}"
|
11
|
+
Plugin::const_get(Bipbip::Helper.name_to_classname(name)).new(name, config, frequency)
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(name, config, frequency)
|
7
15
|
@name = name.to_s
|
16
|
+
@config = config.to_hash
|
17
|
+
@frequency = frequency.to_i
|
8
18
|
end
|
9
19
|
|
10
|
-
def run(
|
20
|
+
def run(storages)
|
11
21
|
child_pid = fork do
|
12
22
|
['INT', 'TERM'].each { |sig| trap(sig) {
|
13
23
|
Thread.new { interrupt } if !@interrupted
|
14
24
|
} }
|
15
25
|
|
16
26
|
retry_delay = frequency
|
17
|
-
metric_identifier = metric_identifier(server)
|
18
27
|
begin
|
19
28
|
until interrupted? do
|
20
29
|
time = Time.now
|
21
|
-
data = monitor
|
30
|
+
data = monitor
|
22
31
|
if data.empty?
|
23
32
|
raise "#{name} #{metric_identifier}: Empty data"
|
24
33
|
end
|
25
34
|
Bipbip.logger.debug "#{name} #{metric_identifier}: Data: #{data}"
|
26
|
-
|
35
|
+
storages.each do |storage|
|
36
|
+
storage.store_sample(self, time, data)
|
37
|
+
end
|
27
38
|
retry_delay = frequency
|
28
39
|
interruptible_sleep (frequency - (Time.now - time))
|
29
40
|
end
|
@@ -46,14 +57,14 @@ module Bipbip
|
|
46
57
|
@interrupted || Process.getpgid(Process.ppid) != Process.getpgrp
|
47
58
|
end
|
48
59
|
|
49
|
-
def
|
50
|
-
@
|
60
|
+
def frequency
|
61
|
+
@frequency
|
51
62
|
end
|
52
63
|
|
53
|
-
def metric_identifier
|
64
|
+
def metric_identifier
|
54
65
|
identifier = Bipbip.fqdn
|
55
|
-
unless
|
56
|
-
identifier += '::' +
|
66
|
+
unless config.empty?
|
67
|
+
identifier += '::' + config.values.first.to_s
|
57
68
|
end
|
58
69
|
identifier
|
59
70
|
end
|
@@ -66,7 +77,7 @@ module Bipbip
|
|
66
77
|
raise 'Missing method metrics_schema'
|
67
78
|
end
|
68
79
|
|
69
|
-
def monitor
|
80
|
+
def monitor
|
70
81
|
raise 'Missing method monitor'
|
71
82
|
end
|
72
83
|
end
|
@@ -4,16 +4,16 @@ module Bipbip
|
|
4
4
|
|
5
5
|
def metrics_schema
|
6
6
|
[
|
7
|
-
{:name => 'request_per_sec', :type => '
|
8
|
-
{:name => 'busy_workers', :type => '
|
7
|
+
{:name => 'request_per_sec', :type => 'gauge', :unit => 'Requests'},
|
8
|
+
{:name => 'busy_workers', :type => 'gauge', :unit => 'Workers'},
|
9
9
|
]
|
10
10
|
end
|
11
11
|
|
12
|
-
def monitor
|
13
|
-
uri = URI.parse(
|
12
|
+
def monitor
|
13
|
+
uri = URI.parse(config['url'])
|
14
14
|
response = Net::HTTP.get_response(uri)
|
15
15
|
|
16
|
-
raise "Invalid response from server at #{
|
16
|
+
raise "Invalid response from server at #{config['url']}" unless response.code == '200'
|
17
17
|
|
18
18
|
astats = response.body.split(/\r*\n/)
|
19
19
|
|
@@ -8,12 +8,12 @@ module Bipbip
|
|
8
8
|
|
9
9
|
def metrics_schema
|
10
10
|
[
|
11
|
-
{:name => 'jobs_queued_total', :type => '
|
11
|
+
{:name => 'jobs_queued_total', :type => 'gauge', :unit => 'Jobs'},
|
12
12
|
]
|
13
13
|
end
|
14
14
|
|
15
|
-
def monitor
|
16
|
-
gearman = GearmanServer.new(
|
15
|
+
def monitor
|
16
|
+
gearman = GearmanServer.new(config['hostname'] + ':' + config['port'].to_s)
|
17
17
|
stats = gearman.status
|
18
18
|
|
19
19
|
jobs_queued_total = 0
|
@@ -8,15 +8,15 @@ module Bipbip
|
|
8
8
|
|
9
9
|
def metrics_schema
|
10
10
|
[
|
11
|
-
{:name => 'cmd_get', :type => '
|
12
|
-
{:name => 'cmd_set', :type => '
|
13
|
-
{:name => 'get_misses', :type => '
|
14
|
-
{:name => 'bytes', :type => '
|
11
|
+
{:name => 'cmd_get', :type => 'counter'},
|
12
|
+
{:name => 'cmd_set', :type => 'counter'},
|
13
|
+
{:name => 'get_misses', :type => 'counter'},
|
14
|
+
{:name => 'bytes', :type => 'gauge', :unit => 'b'},
|
15
15
|
]
|
16
16
|
end
|
17
17
|
|
18
|
-
def monitor
|
19
|
-
memcached = MemcachedClient.new(
|
18
|
+
def monitor
|
19
|
+
memcached = MemcachedClient.new(config['hostname'].to_s + ':' + config['port'].to_s)
|
20
20
|
stats = memcached.stats
|
21
21
|
memcached.quit
|
22
22
|
|
data/lib/bipbip/plugin/mysql.rb
CHANGED
@@ -6,37 +6,37 @@ module Bipbip
|
|
6
6
|
|
7
7
|
def metrics_schema
|
8
8
|
[
|
9
|
-
{:name => 'Max_used_connections', :type => '
|
10
|
-
{:name => 'Connections', :type => '
|
11
|
-
{:name => 'Threads_connected', :type => '
|
9
|
+
{:name => 'Max_used_connections', :type => 'gauge', :unit => 'Connections'},
|
10
|
+
{:name => 'Connections', :type => 'counter', :unit => 'Connections'},
|
11
|
+
{:name => 'Threads_connected', :type => 'gauge', :unit => 'Threads'},
|
12
12
|
|
13
|
-
{:name => 'Seconds_Behind_Master', :type => '
|
13
|
+
{:name => 'Seconds_Behind_Master', :type => 'gauge', :unit => 'Seconds'},
|
14
14
|
|
15
|
-
{:name => 'Created_tmp_disk_tables', :type => '
|
15
|
+
{:name => 'Created_tmp_disk_tables', :type => 'counter', :unit => 'Tables'},
|
16
16
|
|
17
|
-
{:name => 'Queries', :type => '
|
18
|
-
{:name => 'Slow_queries', :type => '
|
17
|
+
{:name => 'Queries', :type => 'counter', :unit => 'Queries'},
|
18
|
+
{:name => 'Slow_queries', :type => 'counter', :unit => 'Queries'},
|
19
19
|
|
20
|
-
{:name => 'Table_locks_immediate', :type => '
|
21
|
-
{:name => 'Table_locks_waited', :type => '
|
20
|
+
{:name => 'Table_locks_immediate', :type => 'counter', :unit => 'Locks'},
|
21
|
+
{:name => 'Table_locks_waited', :type => 'counter', :unit => 'Locks'},
|
22
22
|
|
23
|
-
{:name => 'Processlist', :type => '
|
24
|
-
{:name => 'Processlist_Locked', :type => '
|
23
|
+
{:name => 'Processlist', :type => 'gauge', :unit => 'Processes'},
|
24
|
+
{:name => 'Processlist_Locked', :type => 'gauge', :unit => 'Processes'},
|
25
25
|
|
26
|
-
{:name => 'Com_select', :type => '
|
27
|
-
{:name => 'Com_delete', :type => '
|
28
|
-
{:name => 'Com_insert', :type => '
|
29
|
-
{:name => 'Com_update', :type => '
|
30
|
-
{:name => 'Com_replace', :type => '
|
26
|
+
{:name => 'Com_select', :type => 'counter', :unit => 'Commands'},
|
27
|
+
{:name => 'Com_delete', :type => 'counter', :unit => 'Commands'},
|
28
|
+
{:name => 'Com_insert', :type => 'counter', :unit => 'Commands'},
|
29
|
+
{:name => 'Com_update', :type => 'counter', :unit => 'Commands'},
|
30
|
+
{:name => 'Com_replace', :type => 'counter', :unit => 'Commands'},
|
31
31
|
]
|
32
32
|
end
|
33
33
|
|
34
|
-
def monitor
|
34
|
+
def monitor
|
35
35
|
mysql = Mysql2::Client.new(
|
36
|
-
:host =>
|
37
|
-
:port =>
|
38
|
-
:username =>
|
39
|
-
:password =>
|
36
|
+
:host => config['hostname'],
|
37
|
+
:port => config['port'],
|
38
|
+
:username => config['username'],
|
39
|
+
:password => config['password']
|
40
40
|
)
|
41
41
|
|
42
42
|
stats = Hash.new(0)
|
@@ -4,11 +4,11 @@ module Bipbip
|
|
4
4
|
|
5
5
|
def metrics_schema
|
6
6
|
[
|
7
|
-
{:name => 'connections_total', :type => '
|
7
|
+
{:name => 'connections_total', :type => 'gauge', :unit => 'Connections'},
|
8
8
|
]
|
9
9
|
end
|
10
10
|
|
11
|
-
def monitor
|
11
|
+
def monitor
|
12
12
|
connections = `netstat -tn | wc -l`
|
13
13
|
{:connections_total => connections.to_i}
|
14
14
|
end
|
data/lib/bipbip/plugin/nginx.rb
CHANGED
@@ -4,15 +4,15 @@ module Bipbip
|
|
4
4
|
|
5
5
|
def metrics_schema
|
6
6
|
[
|
7
|
-
{:name => 'connections_requested', :type => '
|
7
|
+
{:name => 'connections_requested', :type => 'counter', :unit => 'Requests'},
|
8
8
|
]
|
9
9
|
end
|
10
10
|
|
11
|
-
def monitor
|
12
|
-
uri = URI.parse(
|
11
|
+
def monitor
|
12
|
+
uri = URI.parse(config['url'])
|
13
13
|
response = Net::HTTP.get_response(uri)
|
14
14
|
|
15
|
-
raise "Invalid response from server at #{
|
15
|
+
raise "Invalid response from server at #{config['url']}" unless response.code == "200"
|
16
16
|
|
17
17
|
nstats = response.body.split(/\r*\n/)
|
18
18
|
connections_requested = nstats[2].lstrip.split(/\s+/)[2].to_i
|
@@ -4,16 +4,16 @@ module Bipbip
|
|
4
4
|
|
5
5
|
def metrics_schema
|
6
6
|
[
|
7
|
-
{:name => 'opcode_mem_size', :type => '
|
8
|
-
{:name => 'user_mem_size', :type => '
|
7
|
+
{:name => 'opcode_mem_size', :type => 'gauge', :unit => 'b'},
|
8
|
+
{:name => 'user_mem_size', :type => 'gauge', :unit => 'b'},
|
9
9
|
]
|
10
10
|
end
|
11
11
|
|
12
|
-
def monitor
|
13
|
-
uri = URI.parse(
|
12
|
+
def monitor
|
13
|
+
uri = URI.parse(config['url'])
|
14
14
|
response = Net::HTTP.get_response(uri)
|
15
15
|
|
16
|
-
raise "Invalid response from server at #{
|
16
|
+
raise "Invalid response from server at #{config['url']}" unless response.code == '200'
|
17
17
|
|
18
18
|
stats = JSON.parse(response.body)
|
19
19
|
|
data/lib/bipbip/plugin/redis.rb
CHANGED
@@ -8,15 +8,15 @@ module Bipbip
|
|
8
8
|
|
9
9
|
def metrics_schema
|
10
10
|
[
|
11
|
-
{:name => 'total_commands_processed', :type => '
|
12
|
-
{:name => 'used_memory', :type => '
|
11
|
+
{:name => 'total_commands_processed', :type => 'counter', :unit => 'Commands'},
|
12
|
+
{:name => 'used_memory', :type => 'gauge', :unit => 'b'},
|
13
13
|
]
|
14
14
|
end
|
15
15
|
|
16
|
-
def monitor
|
16
|
+
def monitor
|
17
17
|
redis = RedisClient.new(
|
18
|
-
:host =>
|
19
|
-
:port =>
|
18
|
+
:host => config['hostname'],
|
19
|
+
:port => config['port']
|
20
20
|
)
|
21
21
|
stats = redis.info
|
22
22
|
redis.quit
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Bipbip
|
2
|
+
|
3
|
+
class Storage
|
4
|
+
|
5
|
+
attr_accessor :name
|
6
|
+
attr_accessor :config
|
7
|
+
|
8
|
+
def self.factory(name, config)
|
9
|
+
require "bipbip/storage/#{Bipbip::Helper.name_to_filename(name)}"
|
10
|
+
Storage::const_get(Bipbip::Helper.name_to_classname(name)).new(name, config)
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(name, config)
|
14
|
+
@name = name.to_s
|
15
|
+
@config = config.to_hash
|
16
|
+
end
|
17
|
+
|
18
|
+
def setup_plugin(plugin)
|
19
|
+
raise 'Missing method setup_plugin'
|
20
|
+
end
|
21
|
+
|
22
|
+
def store_sample(plugin, time, data)
|
23
|
+
raise 'Missing method store_sample'
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Bipbip
|
2
|
+
|
3
|
+
class Storage::Copperegg < Storage
|
4
|
+
|
5
|
+
def initialize(name, config)
|
6
|
+
super(name, config)
|
7
|
+
CopperEgg::Api.apikey = config['api_key']
|
8
|
+
end
|
9
|
+
|
10
|
+
def setup_plugin(plugin)
|
11
|
+
@metric_groups ||= _load_metric_groups
|
12
|
+
@dashboards ||= _load_dashboards
|
13
|
+
|
14
|
+
if ![5, 15, 60, 300, 900, 3600, 21600].include?(plugin.frequency)
|
15
|
+
Bipbip.logger.fatal "Copperegg cannot use frequency #{plugin.frequency}"
|
16
|
+
exit 1
|
17
|
+
end
|
18
|
+
|
19
|
+
metric_group = @metric_groups.detect { |m| m.name == plugin.name }
|
20
|
+
if metric_group.nil? || !metric_group.is_a?(CopperEgg::MetricGroup)
|
21
|
+
Bipbip.logger.info "Creating copperegg metric group `#{plugin.name}`"
|
22
|
+
metric_group = CopperEgg::MetricGroup.new(:name => plugin.name, :label => plugin.name, :frequency => plugin.frequency)
|
23
|
+
end
|
24
|
+
metric_group.frequency = plugin.frequency
|
25
|
+
metric_group.metrics = plugin.metrics_schema.map do |sample|
|
26
|
+
{
|
27
|
+
:name => sample[:name],
|
28
|
+
:type => 'ce_' + sample[:type],
|
29
|
+
:unit => sample[:unit],
|
30
|
+
}
|
31
|
+
end
|
32
|
+
metric_group.save
|
33
|
+
|
34
|
+
dashboard = @dashboards.detect { |d| d.name == plugin.name }
|
35
|
+
if dashboard.nil?
|
36
|
+
Bipbip.logger.info "Creating copperegg dashboard `#{plugin.name}`"
|
37
|
+
metrics = metric_group.metrics || []
|
38
|
+
CopperEgg::CustomDashboard.create(metric_group, :name => plugin.name, :identifiers => nil, :metrics => metrics)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def store_sample(plugin, time, data)
|
43
|
+
CopperEgg::MetricSample.save(plugin.name, plugin.metric_identifier, time.to_i, data)
|
44
|
+
end
|
45
|
+
|
46
|
+
def _load_metric_groups
|
47
|
+
Bipbip.logger.info 'Loading copperegg metric groups'
|
48
|
+
metric_groups = CopperEgg::MetricGroup.find
|
49
|
+
if metric_groups.nil?
|
50
|
+
Bipbip.logger.fatal 'Cannot load copperegg metric groups'
|
51
|
+
exit 1
|
52
|
+
end
|
53
|
+
metric_groups
|
54
|
+
end
|
55
|
+
|
56
|
+
def _load_dashboards
|
57
|
+
Bipbip.logger.info 'Loading copperegg dashboards'
|
58
|
+
dashboards = CopperEgg::CustomDashboard.find
|
59
|
+
if dashboards.nil?
|
60
|
+
Bipbip.logger.fatal 'Cannot load copperegg dashboards'
|
61
|
+
exit 1
|
62
|
+
end
|
63
|
+
dashboards
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
data/lib/bipbip/version.rb
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bipbip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cargo Media
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: copperegg
|
@@ -80,6 +80,34 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2.0'
|
83
111
|
description: Agent to collect data for common server programs and push them to CopperEgg
|
84
112
|
email: hello@cargomedia.ch
|
85
113
|
executables:
|
@@ -91,7 +119,7 @@ files:
|
|
91
119
|
- README.md
|
92
120
|
- bin/bipbip
|
93
121
|
- lib/bipbip/agent.rb
|
94
|
-
- lib/bipbip/
|
122
|
+
- lib/bipbip/helper.rb
|
95
123
|
- lib/bipbip/plugin/apache2.rb
|
96
124
|
- lib/bipbip/plugin/gearman.rb
|
97
125
|
- lib/bipbip/plugin/memcached.rb
|
@@ -101,8 +129,11 @@ files:
|
|
101
129
|
- lib/bipbip/plugin/php_apc.rb
|
102
130
|
- lib/bipbip/plugin/redis.rb
|
103
131
|
- lib/bipbip/plugin.rb
|
132
|
+
- lib/bipbip/storage/copperegg.rb
|
133
|
+
- lib/bipbip/storage.rb
|
104
134
|
- lib/bipbip/version.rb
|
105
135
|
- lib/bipbip.rb
|
136
|
+
- lib/interruptible_sleep.rb
|
106
137
|
homepage: https://github.com/cargomedia/bipbip
|
107
138
|
licenses:
|
108
139
|
- MIT
|