bosh-monitor 1.2789.0 → 1.2792.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.
@@ -0,0 +1,68 @@
1
+ module Bosh::Monitor
2
+ module Plugins
3
+ class Graphite < Base
4
+ def validate_options
5
+ !!(options.kind_of?(Hash) && options["host"] && options["port"])
6
+ end
7
+
8
+ def run
9
+ unless EM.reactor_running?
10
+ logger.error("Graphite delivery agent can only be started when event loop is running")
11
+ return false
12
+ end
13
+
14
+ host = options["host"]
15
+ port = options["port"]
16
+ @connection = EM.connect(host, port, Bhm::GraphiteConnection, host, port)
17
+ end
18
+
19
+ def process(event)
20
+ if event.is_a? Bosh::Monitor::Events::Heartbeat
21
+
22
+ metrics = event.metrics
23
+
24
+ unless metrics.kind_of?(Enumerable)
25
+ raise PluginError, "Invalid event metrics: Enumerable expected, #{metrics.class} given"
26
+ end
27
+
28
+ metrics.each do |metric|
29
+ metric_name = get_metric_name(event, metric)
30
+ metric_timestamp = get_metric_timestamp(metric.timestamp)
31
+ metric_value = metric.value
32
+ @connection.send_metric(metric_name, metric_value, metric_timestamp)
33
+ end
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def get_metric_name heartbeat, metric
40
+ [get_metric_prefix(heartbeat), metric.name.to_s.gsub('.', '_')].join '.'
41
+ end
42
+
43
+ def get_metric_prefix(heartbeat)
44
+ deployment = heartbeat.deployment
45
+ job = heartbeat.job
46
+ index = heartbeat.index
47
+ agent_id = heartbeat.agent_id
48
+ if options["prefix"]
49
+ [options["prefix"], deployment, job, index, agent_id].join '.'
50
+ else
51
+ [deployment, job, index, agent_id].join '.'
52
+ end
53
+ end
54
+
55
+ def get_metric_timestamp(ts)
56
+ if ts && is_epoch?(ts)
57
+ return ts
58
+ end
59
+
60
+ Time.now.to_i
61
+ end
62
+
63
+ def is_epoch?(ts)
64
+ /^1[0-9]{9}$/.match(ts.to_s)
65
+ end
66
+ end
67
+ end
68
+ end
@@ -23,6 +23,8 @@ module Bosh::Monitor
23
23
  return false
24
24
  end
25
25
 
26
+ return false if event.is_a? Bosh::Monitor::Events::Alert
27
+
26
28
  metrics = event.metrics
27
29
 
28
30
  if !metrics.kind_of?(Enumerable)
@@ -0,0 +1,17 @@
1
+ module Bosh::Monitor
2
+ class GraphiteConnection < Bosh::Monitor::TcpConnection
3
+ def initialize(host, port)
4
+ super("connection.graphite", host, port)
5
+ end
6
+
7
+ def send_metric(name, value, timestamp)
8
+ if name && value && timestamp
9
+ command = "#{name} #{value} #{timestamp}\n"
10
+ @logger.debug("[Graphite] >> #{command.chomp}")
11
+ send_data(command)
12
+ else
13
+ @logger.warn("Missing graphite metrics (name: '#{name}', value: '#{value}', timestamp: '#{timestamp}')")
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,62 @@
1
+ module Bosh::Monitor
2
+ class TcpConnection < EventMachine::Connection
3
+
4
+ BACKOFF_CEILING = 9
5
+ MAX_RETRIES = 35
6
+
7
+ attr_reader :retries, :logger_name
8
+
9
+ def initialize(logger_name, host, port)
10
+ @logger_name = logger_name
11
+ @host = host
12
+ @port = port
13
+ @logger = Bhm.logger
14
+ reset_retries
15
+ end
16
+
17
+ def reset_retries
18
+ @retries = 0
19
+ end
20
+
21
+ def increment_retries
22
+ @retries += 1
23
+ end
24
+
25
+ def connection_completed
26
+ reset_retries
27
+ @reconnecting = false
28
+ @connected = true
29
+ @logger.info("#{@logger_name}-connected")
30
+ end
31
+
32
+ def unbind
33
+ if @connected
34
+ @logger.warn("#{@logger_name}-connection-lost")
35
+ end
36
+ @connected = false
37
+
38
+ retry_in = 2**[retries, BACKOFF_CEILING].min - 1
39
+ increment_retries
40
+
41
+ if retries > MAX_RETRIES
42
+ raise "#{logger_name}-failed-to-reconnect after #{MAX_RETRIES} retries"
43
+ end
44
+
45
+ if retries > 1
46
+ @logger.info("#{logger_name}-failed-to-reconnect, will try again in #{retry_in} seconds...")
47
+ end
48
+
49
+ EM.add_timer(retry_in) { retry_reconnect }
50
+ end
51
+
52
+ def retry_reconnect
53
+ @logger.info("#{@logger_name}-reconnecting (#{retries})...")
54
+ reconnect(@host, @port)
55
+ end
56
+
57
+ def receive_data(data)
58
+ @logger.info("#{logger_name} << #{data.chomp}")
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,14 @@
1
+ module Bosh::Monitor
2
+ class TsdbConnection < Bosh::Monitor::TcpConnection
3
+ def initialize(host, port)
4
+ super("connection.tsdb", host, port)
5
+ end
6
+
7
+ def send_metric(name, timestamp, value, tags = {})
8
+ formatted_tags = tags.map { |tag| tag.join("=") }.sort.join(" ")
9
+ command = "put #{name} #{timestamp} #{value} #{formatted_tags}\n"
10
+ @logger.debug("[TSDB] >> #{command.chomp}")
11
+ send_data(command)
12
+ end
13
+ end
14
+ end
@@ -1,5 +1,5 @@
1
1
  module Bosh
2
2
  module Monitor
3
- VERSION = '1.2789.0'
3
+ VERSION = '1.2792.0'
4
4
  end
5
5
  end
data/lib/bosh/monitor.rb CHANGED
@@ -48,7 +48,10 @@ require 'bosh/monitor/event_processor'
48
48
  require 'bosh/monitor/api_controller'
49
49
 
50
50
  # Protocols
51
- require 'bosh/monitor/protocols/tsdb'
51
+ require 'bosh/monitor/protocols/tcp_connection'
52
+ require 'bosh/monitor/protocols/tsdb_connection'
53
+ require 'bosh/monitor/protocols/graphite_connection'
54
+
52
55
 
53
56
  # Events
54
57
  require 'bosh/monitor/events/base'
@@ -64,6 +67,7 @@ require 'bosh/monitor/plugins/cloud_watch'
64
67
  require 'bosh/monitor/plugins/datadog'
65
68
  require 'bosh/monitor/plugins/paging_datadog_client'
66
69
  require 'bosh/monitor/plugins/email'
70
+ require 'bosh/monitor/plugins/graphite'
67
71
  require 'bosh/monitor/plugins/logger'
68
72
  require 'bosh/monitor/plugins/nats'
69
73
  require 'bosh/monitor/plugins/pagerduty'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bosh-monitor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2789.0
4
+ version: 1.2792.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-12-13 00:00:00.000000000 Z
12
+ date: 2014-12-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine
@@ -157,7 +157,7 @@ dependencies:
157
157
  version: 1.6.0
158
158
  description: ! 'BOSH Health Monitor
159
159
 
160
- 177517'
160
+ 5e7f33'
161
161
  email: support@cloudfoundry.com
162
162
  executables:
163
163
  - bosh-monitor-console
@@ -185,6 +185,7 @@ files:
185
185
  - lib/bosh/monitor/plugins/datadog.rb
186
186
  - lib/bosh/monitor/plugins/dummy.rb
187
187
  - lib/bosh/monitor/plugins/email.rb
188
+ - lib/bosh/monitor/plugins/graphite.rb
188
189
  - lib/bosh/monitor/plugins/http_request_helper.rb
189
190
  - lib/bosh/monitor/plugins/logger.rb
190
191
  - lib/bosh/monitor/plugins/nats.rb
@@ -194,7 +195,9 @@ files:
194
195
  - lib/bosh/monitor/plugins/resurrector_helper.rb
195
196
  - lib/bosh/monitor/plugins/tsdb.rb
196
197
  - lib/bosh/monitor/plugins/varz.rb
197
- - lib/bosh/monitor/protocols/tsdb.rb
198
+ - lib/bosh/monitor/protocols/graphite_connection.rb
199
+ - lib/bosh/monitor/protocols/tcp_connection.rb
200
+ - lib/bosh/monitor/protocols/tsdb_connection.rb
198
201
  - lib/bosh/monitor/runner.rb
199
202
  - lib/bosh/monitor/version.rb
200
203
  - lib/bosh/monitor/yaml_helper.rb
@@ -223,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
223
226
  version: '0'
224
227
  segments:
225
228
  - 0
226
- hash: 1089129721426212207
229
+ hash: 4403752010181669552
227
230
  requirements: []
228
231
  rubyforge_project:
229
232
  rubygems_version: 1.8.23
@@ -1,68 +0,0 @@
1
- module Bosh::Monitor
2
- class TsdbConnection < EventMachine::Connection
3
-
4
- BACKOFF_CEILING = 9
5
- MAX_RETRIES = 35
6
-
7
- attr_reader :retries
8
-
9
- def initialize(host, port)
10
- @host = host
11
- @port = port
12
- @logger = Bhm.logger
13
- reset_retries
14
- end
15
-
16
- def reset_retries
17
- @retries = 0
18
- end
19
-
20
- def increment_retries
21
- @retries += 1
22
- end
23
-
24
- def send_metric(name, timestamp, value, tags = {})
25
- formatted_tags = tags.map { |tag| tag.join("=") }.sort.join(" ")
26
- command = "put #{name} #{timestamp} #{value} #{formatted_tags}\n"
27
- @logger.debug("[TSDB] >> #{command.chomp}")
28
- send_data(command)
29
- end
30
-
31
- def connection_completed
32
- reset_retries
33
- @reconnecting = false
34
- @connected = true
35
- @logger.info("Connected to TSDB server at #{@host}:#{@port}")
36
- end
37
-
38
- def unbind
39
- if @connected
40
- @logger.warn("Lost connection to TSDB server at #{@host}:#{@port}")
41
- end
42
- @connected = false
43
-
44
- retry_in = 2**[retries, BACKOFF_CEILING].min - 1
45
- increment_retries
46
-
47
- if retries > MAX_RETRIES
48
- raise "Failed to reconnect to TSDB after #{MAX_RETRIES} retries"
49
- end
50
-
51
- if retries > 1
52
- @logger.info("Failed to reconnect to TSDB, will try again in #{retry_in} seconds...")
53
- end
54
-
55
- EM.add_timer(retry_in) { tsdb_reconnect }
56
- end
57
-
58
- def tsdb_reconnect
59
- @logger.info("Trying to reconnect to TSDB server at #{@host}:#{@port} (#{retries})...")
60
- reconnect(@host, @port)
61
- end
62
-
63
- def receive_data(data)
64
- @logger.info("[TSDB] << #{data.chomp}")
65
- end
66
-
67
- end
68
- end