This repository has been archived by the owner on Dec 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d408e14
Showing
3 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Copyright 2014 John E. Vincent and contributors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Requirements | ||
`influxdb` ruby gem | ||
|
||
# Usage | ||
The configuration options are pretty straight forward. Note that the files are called `influx` not `influxdb`. | ||
|
||
Metrics are inserted into the database with a table per check name. So if you're using the `rabbitmq_overview_metrics` plugin, you'd have a table in the defined database called `rabbitmq_overview_metrics` with the following columns: | ||
|
||
- host | ||
- metric | ||
- value | ||
|
||
Additionally a `duration` column would be present based on the time it took the check to run (this is gleaned from the sensu event data). | ||
|
||
The value for `metric` is determined based on the value of `strip_metric` described below. You can query it like so: | ||
|
||
![an image](http://s3itch.lusis.org/InfluxDB_Administration_20140203_153132.png) | ||
|
||
## Handler definition (`/etc/sensu/conf.d/handlers/influx.json`) | ||
```json | ||
{ | ||
"handlers": { | ||
"influx": { | ||
"type": "pipe", | ||
"command": "influx.rb" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Handler config (`/etc/sensu/conf.d/influx.json`) | ||
```json | ||
{ | ||
"influx": { | ||
"host": "localhost", | ||
"port": "8086", | ||
"user": "stats", | ||
"password": "stats", | ||
"database": "stats", | ||
"strip_metric": "somevalue" | ||
} | ||
} | ||
``` | ||
|
||
Host, port, user, password and database are pretty straight forward. `strip_metric` however might not be. This is used to "clean up" the data sent to influxdb. Normally everything sent to handlers is akin to the `graphite`/`stats` style: | ||
|
||
something.host.metrictype.foo.bar | ||
|
||
or | ||
host.stats.something.foo.bar | ||
|
||
Really the pattern is irrelevant. People have different tastes. Adding much of that data to the column name in InfluxDB is rather silly so `strip_metric` provides you with a chance to add a value that strips off everything up to (and including that value). This allows you to continue sending to graphite or statsd or whatever and still use this handler. | ||
|
||
Using the examples above, if you set the `strip_metric` to `host`, then the column in InfluxDB would be called `metrictype.foo.bar` or `stats.something.foo.bar`. If you set the value to `foo` then the column would simply be called `foo` | ||
|
||
Note that `strip_metric` isn't required. | ||
# Quickstart (for Chef sensu cookbook users) | ||
|
||
```ruby | ||
sensu_gem "influxdb" | ||
|
||
cookbook_file "/etc/sensu/handlers/influx.rb" do | ||
source "handlers/influx.rb" | ||
mode 0755 | ||
end | ||
|
||
sensu_snippet "influx" do | ||
content( | ||
:host => node['sensu']['rabbitmq']['host'], | ||
:port => '8086', | ||
:user => 'stats', | ||
:password => 'stats', | ||
:database => 'stats', | ||
:strip_metric => node.name | ||
) | ||
end | ||
|
||
sensu_handler "influx" do | ||
type "pipe" | ||
command "influx.rb" | ||
end | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env ruby | ||
require 'rubygems' if RUBY_VERSION < '1.9.0' | ||
require 'sensu-handler' | ||
require 'influxdb' | ||
|
||
class Influx < Sensu::Handler | ||
def filter; end | ||
|
||
def handle | ||
@influxdb = InfluxDB::Client.new settings['influx']['database'], :host => settings['influx']['host'], :port => settings['influx']['port'], :username => settings['influx']['user'], :password => settings['influx']['password'] | ||
@event['check']['output'].split("\n").each do |line| | ||
n, v, _ = line.split(/\s+/) | ||
if settings['influx']['strip_metric'] | ||
n.gsub!(/^.*#{settings['influx']['strip_metric']}\.(.*$)/, '\1') | ||
end | ||
@influxdb.write_point(@event['check']['name'], {:host => @event['client']['name'], :metric => n, :value => v, :duration => @event['check']['duration']}) | ||
end | ||
end | ||
end |