chef-metrics 0.0.2 → 0.0.3
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.
- data/README.md +69 -4
- data/chef-metrics.gemspec +1 -1
- data/lib/chef-metrics.rb +11 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -1,14 +1,79 @@
|
|
1
|
-
#
|
1
|
+
# Chef Metrics
|
2
2
|
|
3
|
-
|
3
|
+
Chef Metrics is an OpsCode Chef report/exception handler for sending
|
4
|
+
Chef metrics to one or more endpoints. Metrics are gathered using
|
5
|
+
`run_status` and `node.run_state[:metrics]` (optional). The method of
|
6
|
+
metric delivery to the endpoint/s of choice is left up to the
|
7
|
+
user. You can't manage what you don't measure.
|
4
8
|
|
5
9
|
## Installation
|
6
10
|
|
7
|
-
|
11
|
+
gem install chef-metrics
|
8
12
|
|
9
13
|
## Usage
|
10
14
|
|
11
|
-
|
15
|
+
Append the following to your Chef client configs, usually at `/etc/chef/client.rb`
|
16
|
+
|
17
|
+
require "chef-metrics"
|
18
|
+
|
19
|
+
metric_handler = ChefMetrics.new do
|
20
|
+
# see examples below
|
21
|
+
end
|
22
|
+
|
23
|
+
report_handlers << metric_handler
|
24
|
+
exception_handlers << metric_handler
|
25
|
+
|
26
|
+
Alternatively, you can use the LWRP (available @
|
27
|
+
http://community.opscode.com/cookbooks/chef_handler)
|
28
|
+
|
29
|
+
## Examples
|
30
|
+
|
31
|
+
The following examples are "action" blocks:
|
32
|
+
|
33
|
+
metric_handler = ChefMetrics.new do
|
34
|
+
# action block
|
35
|
+
end
|
36
|
+
|
37
|
+
Note: I recommend adding logging, timeouts, and error handling to the following.
|
38
|
+
|
39
|
+
### Graphite
|
40
|
+
|
41
|
+
require 'socket'
|
42
|
+
|
43
|
+
socket = TCPSocket.new(GRAPHITE_HOST, GRAPHITE_PORT)
|
44
|
+
socket.write(graphite_formatted)
|
45
|
+
socket.close
|
46
|
+
|
47
|
+
### Sensu
|
48
|
+
|
49
|
+
require 'socket'
|
50
|
+
|
51
|
+
sensu_result = {
|
52
|
+
:name => "chef_report",
|
53
|
+
:type => "metric",
|
54
|
+
:handler => "metrics",
|
55
|
+
:output => graphite_formatted
|
56
|
+
}
|
57
|
+
|
58
|
+
socket = TCPSocket.open('127.0.0.1', 3030)
|
59
|
+
socket.write(sensu_result.to_json)
|
60
|
+
socket.close
|
61
|
+
|
62
|
+
### More
|
63
|
+
|
64
|
+
puts metrics
|
65
|
+
# {:updated_resources=>12, :all_resources=>236, :elapsed_time=>22, :success=>1, :fail=>0}
|
66
|
+
|
67
|
+
puts graphite_formatted
|
68
|
+
# chef.i-424242.updated_resources 12
|
69
|
+
# chef.i-424242.all_resources 236
|
70
|
+
# ...
|
71
|
+
|
72
|
+
self.metric_scheme = "#{node.environment}.chef.#{node.name.gsub(".", "_")}"
|
73
|
+
puts graphite_formatted
|
74
|
+
# production.chef.i-424242.updated_resources 12
|
75
|
+
# production.chef.i-424242.all_resources 236
|
76
|
+
# ...
|
12
77
|
|
13
78
|
## Contributing
|
14
79
|
|
data/chef-metrics.gemspec
CHANGED
data/lib/chef-metrics.rb
CHANGED
@@ -2,15 +2,22 @@ require "rubygems"
|
|
2
2
|
require "chef/handler"
|
3
3
|
|
4
4
|
class ChefMetrics < Chef::Handler
|
5
|
-
attr_accessor :metric_scheme, :measure_time, :metrics, :action
|
5
|
+
attr_accessor :metric_scheme, :measure_time, :metrics, :use_run_state, :action
|
6
6
|
|
7
7
|
def initialize(&action)
|
8
8
|
@metric_scheme = "chef.#{Chef::Config.node_name}"
|
9
9
|
@measure_time = Time.now.to_i
|
10
10
|
@metrics = Hash.new
|
11
|
+
@use_run_state = true
|
11
12
|
@action = action
|
12
13
|
end
|
13
14
|
|
15
|
+
def run_state_metrics!
|
16
|
+
if node.has_key?(:run_state) && node.run_state[:metrics].is_a?(Hash)
|
17
|
+
@metrics.merge!(node.run_state[:metrics])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
14
21
|
def graphite_formatted
|
15
22
|
@metrics.inject("") do |result, (metric, value)|
|
16
23
|
result << "#{@metric_scheme}.#{metric} #{value} #{@measure_time}\n"
|
@@ -30,6 +37,9 @@ class ChefMetrics < Chef::Handler
|
|
30
37
|
@metrics[:success] = 0
|
31
38
|
@metrics[:fail] = 1
|
32
39
|
end
|
40
|
+
if @use_run_state
|
41
|
+
run_state_metrics!
|
42
|
+
end
|
33
43
|
if @action
|
34
44
|
self.instance_eval(&@action)
|
35
45
|
else
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-metrics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Sean Porter
|