Skip to content

Commit

Permalink
readme, 2 space indent for code snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
portertech committed Sep 17, 2014
1 parent f541d92 commit 67ebd39
Showing 1 changed file with 53 additions and 53 deletions.
106 changes: 53 additions & 53 deletions README.md
Expand Up @@ -15,97 +15,97 @@ user. You can't manage what you don't measure.
Append the following to your Chef client configs, usually at `/etc/chef/client.rb`

```ruby
require "chef-metrics"
require "chef-metrics"

metric_handler = ChefMetrics.new do
# see examples below
end
metric_handler = ChefMetrics.new do
# see examples below
end

report_handlers << metric_handler
exception_handlers << metric_handler
report_handlers << metric_handler
exception_handlers << metric_handler
```

Alternatively, you can use the Chef cookbook
[LWRP](http://community.opscode.com/cookbooks/chef_handler).

```ruby
chef_gem "chef-metrics"
chef_gem "chef-metrics"

handler_path = File.join(node["chef_handler"]["handler_path"], "chef_metrics.rb")
handler_path = File.join(node["chef_handler"]["handler_path"], "chef_metrics.rb")

directory File.dirname(handler_path) do
recursive true
end
directory File.dirname(handler_path) do
recursive true
end

file handler_path do
content "require 'chef-metrics'"
end
file handler_path do
content "require 'chef-metrics'"
end

action_block = Proc.new do
# see examples below
end
action_block = Proc.new do
# see examples below
end

chef_handler "ChefMetrics" do
source handler_path
arguments action_block
end
chef_handler "ChefMetrics" do
source handler_path
arguments action_block
end
```

## Examples

The following examples are "action" blocks:

```ruby
metric_handler = ChefMetrics.new do
# action block
end
metric_handler = ChefMetrics.new do
# action block
end
```

Note: I recommend adding logging, timeouts, and error handling to the following.

### Graphite

```ruby
require 'socket'
require 'socket'

socket = TCPSocket.new(GRAPHITE_HOST, GRAPHITE_PORT)
socket.write(graphite_formatted)
socket.close
socket = TCPSocket.new(GRAPHITE_HOST, GRAPHITE_PORT)
socket.write(graphite_formatted)
socket.close
```

### Sensu

```ruby
require 'socket'

sensu_result = {
:name => "chef_report",
:type => "metric",
:handler => "metrics",
:output => graphite_formatted
}

socket = TCPSocket.open('127.0.0.1', 3030)
socket.write(sensu_result.to_json)
socket.close
require 'socket'

sensu_result = {
:name => "chef_report",
:type => "metric",
:handler => "metrics",
:output => graphite_formatted
}

socket = TCPSocket.open('127.0.0.1', 3030)
socket.write(sensu_result.to_json)
socket.close
```

### More

```ruby
puts metrics
# {:updated_resources=>12, :all_resources=>236, :elapsed_time=>22, :success=>1, :fail=>0}

puts graphite_formatted
# chef.i-424242.updated_resources 12
# chef.i-424242.all_resources 236
# ...

self.metric_scheme = "#{node.environment}.chef.#{node.name.gsub(".", "_")}"
puts graphite_formatted
# production.chef.i-424242.updated_resources 12
# production.chef.i-424242.all_resources 236
# ...
puts metrics
# {:updated_resources=>12, :all_resources=>236, :elapsed_time=>22, :success=>1, :fail=>0}

puts graphite_formatted
# chef.i-424242.updated_resources 12
# chef.i-424242.all_resources 236
# ...

self.metric_scheme = "#{node.environment}.chef.#{node.name.gsub(".", "_")}"
puts graphite_formatted
# production.chef.i-424242.updated_resources 12
# production.chef.i-424242.all_resources 236
# ...
```

## Contributing
Expand Down

0 comments on commit 67ebd39

Please sign in to comment.